Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hi, i need help!
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#11
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:
PHP Code: (Select All)
void OnStart()
{
    
AddUseItemCallback("""key1""door1""UseKeyOnDoor"true);
    
AddUseItemCallback("""key2""door2""UseKeyOnDoor"true);
    
AddUseItemCallback("""key3""door3""UseKeyOnDoor"true);
}

void UseKeyOnDoor(string &in asEntitystring &in asItem)
{
    
SetSwingDoorLocked(asEntityfalsetrue);
    
PlaySoundAtEntity("""unlock_door.snt"asEntity0false);
    
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
Find
Slanderous Offline
Posting Freak

Posts: 1,606
Threads: 78
Joined: Dec 2012
Reputation: 63
#12
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:
PHP Code: (Select All)
void OnStart()
{
    
AddUseItemCallback("""key1""door1""UseKeyOnDoor"true);
    
AddUseItemCallback("""key2""door2""UseKeyOnDoor"true);
    
AddUseItemCallback("""key3""door3""UseKeyOnDoor"true);
}

void UseKeyOnDoor(string &in asEntitystring &in asItem)
{
    
SetSwingDoorLocked(asEntityfalsetrue);
    
PlaySoundAtEntity("""unlock_door.snt"asEntity0false);
    
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 Tongue
03-27-2014, 03:55 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#13
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 Tongue

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
Find




Users browsing this thread: 1 Guest(s)