Mudbill
Muderator
Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation:
179
|
RE: Hi, i need help!
That is very unnecessary because you now have many duplicate functions that do the exact same.
Since your script uses asEntity and asItem, you can use the same function for all keys and doors. Just add more AddUseItemCallback lines, but point to the same UseKeyOnDoor script.
Like this:
void OnStart() { AddUseItemCallback("", "key1", "door1", "UseKeyOnDoor", true); AddUseItemCallback("", "key2", "door2", "UseKeyOnDoor", true); AddUseItemCallback("", "key3", "door3", "UseKeyOnDoor", true); }
void UseKeyOnDoor(string &in asEntity, string &in asItem) { SetSwingDoorLocked(asEntity, false, true); PlaySoundAtEntity("", "unlock_door.snt", asEntity, 0, false); RemoveItem(asItem); }
The way this works is that asEntity is replaced with the entity used in the callback that executes this function. If the entity the key is used on is "door1", asEntity will be the same as "door1". If the entity is "door2" instead, asEntity is now "door2" and not "door1" anymore. Same thing with asItem and the key names.
You could shorten this script even more using a for-loop, but seeing as you're a beginner, I don't recommend doing so.
(This post was last modified: 03-27-2014, 02:46 PM by Mudbill.)
|
|
03-27-2014, 02:43 PM |
|
Slanderous
Posting Freak
Posts: 1,606
Threads: 78
Joined: Dec 2012
Reputation:
63
|
RE: Hi, i need help!
(03-27-2014, 02:43 PM)Mudbill Wrote: That is very unnecessary because you now have many duplicate functions that do the exact same.
Since your script uses asEntity and asItem, you can use the same function for all keys and doors. Just add more AddUseItemCallback lines, but point to the same UseKeyOnDoor script.
Like this:
void OnStart() { AddUseItemCallback("", "key1", "door1", "UseKeyOnDoor", true); AddUseItemCallback("", "key2", "door2", "UseKeyOnDoor", true); AddUseItemCallback("", "key3", "door3", "UseKeyOnDoor", true); }
void UseKeyOnDoor(string &in asEntity, string &in asItem) { SetSwingDoorLocked(asEntity, false, true); PlaySoundAtEntity("", "unlock_door.snt", asEntity, 0, false); RemoveItem(asItem); }
The way this works is that asEntity is replaced with the entity used in the callback that executes this function. If the entity the key is used on is "door1", asEntity will be the same as "door1". If the entity is "door2" instead, asEntity is now "door2" and not "door1" anymore. Same thing with asItem and the key names.
You could shorten this script even more using a for-loop, but seeing as you're a beginner, I don't recommend doing so.
I know, but since he is a beginner I wanted to give him the scipt in easiest form
|
|
03-27-2014, 03:55 PM |
|
Mudbill
Muderator
Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation:
179
|
RE: Hi, i need help!
(03-27-2014, 03:55 PM)Lazzer Wrote: I know, but since he is a beginner I wanted to give him the scipt in easiest form
I see. Well, the easiest form would not use asEntity or asItem, but rather the name of the objects. But alright. It's good practise to use them though xP
|
|
03-27-2014, 04:05 PM |
|
|