04-26-2016, 10:30 PM
I know this is possible but im not sure exactly how. I want to have a key be used on 3 different doors then once this is true the key should disappear from the inventory. Could anyone give me a hand with this please?
// Conrol variables for this code snippet
string yourFirstDoor = "myDoor01";
string yourSecondDoor = "myDoor02";
string yourThirdDoor = "myDoor03";
string yourSpecialKey = "myKeyItem";
void OnStart()
{
// Preloading Resources
PreloadSound("unlock_door.snt");
// Callbacks setup
AddUseItemCallback("", yourSpecialKey, yourFirstDoor, "UnlockDoor", true);
AddUseItemCallback("", yourSpecialKey, yourSecondDoor, "UnlockDoor", true);
AddUseItemCallback("", yourSpecialKey, yourThirdDoor, "UnlockDoor", true);
}
// GENERAL DOOR UNLOCK FUNCTION
void UnlockDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
PlaySoundAtEntity("", "unlock_door.snt", asEntity, 1.0f, false);
// If it's your special key and all doors are unlocked, remove it from the Inventory
if(asItem == yourSpecialKey && AllDoorsUnlocked())
{
RemoveItem(asItem);
}
// If it's some other normal key, just remove it without any condition
else if(asItem != yourSpecialKey)
{
RemoveItem(asItem);
return;
}
}
// CHECKING IF ALL DOORS ARE UNLOCKED
bool AllDoorsUnlocked()
{
if(GetSwingDoorLocked(yourFirstDoor) == false &&
GetSwingDoorLocked(yourSecondDoor) == false &&
GetSwingDoorLocked(yourThirdDoor) == false)
{
return true;
}
return false;
}
void OnStart()
{
string mySubVar = "Whoa";
}
SetGlobalVarInt("name", 0);
// Might also interest you:
// AddGlobalVarInt("name", 1); adds the integer to the value
// GetGlobalVarInt(string& asName); returns the integer value
string mySubVar = "Whoa";
void OnStart()
{
}
AddLocalVarInt("MyInt"+i, 1);
int myInt+i = myInt+i + 1; //Errors, obviously