Frictional Games Forum (read-only)
Hi, i need help! - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Hi, i need help! (/thread-24934.html)

Pages: 1 2


RE: Hi, i need help! - Mudbill - 03-27-2014

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:
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.


RE: Hi, i need help! - Slanderous - 03-27-2014

(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:
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


RE: Hi, i need help! - Mudbill - 03-27-2014

(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