Frictional Games Forum (read-only)

Full Version: 2 keys script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'm having 2 keys in my map.

The first key you can pick up unlocks a door into another room.
On the way to the locked door, you pass another locked door. But when you unlock the door with the valid key, the other door becomes unlocked automatic... However the next key still works on the newly unlocked door...
Here is my script:

////////////////////////////
// Run first time starting map
void OnStart()
{

}

////////////////////////////
// Run when entering map
void OnEnter()
{
AddUseItemCallback("", "key1", "door1", "KeyOnDoor", true);
AddUseItemCallback("", "key2", "door2", "KeyOnDoor", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door1", false, true);
PlaySoundAtEntity("", "unlock_door", "door1", 0, false);
RemoveItem("key1");

SetSwingDoorLocked("door2", false, true);
PlaySoundAtEntity("", "unlock_door", "door2", 0, false);
RemoveItem("key2");
}

////////////////////////////
// Run when leaving map
void OnLeave()
{

}

What is wrong?
////////////////////////////
// Run first time starting map
void OnStart()
{

}

////////////////////////////
// Run when entering map
void OnEnter()
{
AddUseItemCallback("", "key1", "door1", "KeyOnDoor", true);
AddUseItemCallback("", "key2", "door2", "KeyOnDoor", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity , false, true);
PlaySoundAtEntity("", "unlock_door", "asEntity", 0, false);
RemoveItem(asItem);
}

////////////////////////////
// Run when leaving map
void OnLeave()
{

}
Use this one: They don't figure themselves out. If you put those veents in there, the game will do both of them, not in the order you put them in.

Quote:////////////////////////////
// Run first time starting map
void OnStart()
{

}

////////////////////////////
// Run when entering map
void OnEnter()
{
AddUseItemCallback("", "key1", "door1", "KeyOnDoor", true);
AddUseItemCallback("", "key2", "door2", "KeyOnDoor2", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door1", false, true);
PlaySoundAtEntity("", "unlock_door", "door1", 0, false);
RemoveItem("key1");
}

void KeyOnDoor2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door2", false, true);
PlaySoundAtEntity("", "unlock_door", "door2", 0, false);
RemoveItem("key2");
}

////////////////////////////
// Run when leaving map
void OnLeave()
{

}
No it's this one.
Yay it works!!! Big Grin

I occured another question not related to the keys...

I have a room with 2 locked doors.
In the middle is a table with a note.
Behind one of the doors is a monster.

I already set up the pathnotes (there is only 1)
and made the monster inactive.

Now i want it to go break the door (by just following the pathnote) when i pick up the note.
But i cant make it work.
Script:

////////////////////////////
// Run first time starting map
void OnStart()

{
AddEntityCollideCallback("Player", "PlayerCollide", "MonsterFunction", true, 1);
}

void SetEntityCallbackFunc("note3", "OnPickup");
{
void OnPickup(string &in asItem, string &in asEntity)
{
SetEntityActive("PlayerCollide", true);
void MonsterFunction(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("monster1", true);
AddEnemyPatrolNode("monster1", "PathNodeArea_1", 0, "");
}
}
}
You are doing much wrong, you can't do a void in the callbacks, and there must be an } after any callbacks.
not after you did it all, i can't fix this sorry, its too messed for me Sad
(03-10-2012, 12:14 PM)Stepper321 Wrote: [ -> ]
Quote:////////////////////////////
// Run first time starting map
void OnStart()
{

}

////////////////////////////
// Run when entering map
void OnEnter()
{
AddUseItemCallback("", "key1", "door1", "KeyOnDoor", true);
AddUseItemCallback("", "key2", "door2", "KeyOnDoor2", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door1", false, true);
PlaySoundAtEntity("", "unlock_door", "door1", 0, false);
RemoveItem("key1");
}

void KeyOnDoor2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door2", false, true);
PlaySoundAtEntity("", "unlock_door", "door2", 0, false);
RemoveItem("key2");
}

////////////////////////////
// Run when leaving map
void OnLeave()
{

}
No it's this one.
Correction: Both work.


(03-10-2012, 12:43 PM)Stepper321 Wrote: [ -> ]You are doing much wrong, you can't do a void in the callbacks, and there must be an } after any callbacks.
not after you did it all, i can't fix this sorry, its too messed for me Sad
Those are not callbacks.
Instead of editing it, could you then try doing it the right way?

On pickup - Monster spawn..

void OnStart()
{
SetEntityPlayerInteractCallback("notename", "MonsterSpawm", true);
}

void MonsterSpawn(string &in asEntity)
{
SetEntityActive("monstername", true);
}
It doesn't work... yes my FATAL ERROR messages disappear, but the monster spawn, or begin its pathnode... i tried editing after what you did, with no luck.
I tried making the area get active when i pick up the node and then the area will make the monster spawn... but i guess it is impossible to use notes to trigger anything...
No, you can trigger things with notes. Using the exact way I said. Post the scri[t of the edited version.
Pages: 1 2