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
Script Help Remove key after 3x uses
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#4
RE: Remove key after 3x uses

I created a simple code snipped that hopefully resolves your problem.
Feel free to use the general UnlockDoor function for any of your keys and doors, for it will unlock them just fine without any modifications.

Bare in mind the snipped is controlled by the variables on top.
Feel free to replace variables with string entries if you feel like it.

PHP Code: (Select All)
// 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(""yourSpecialKeyyourFirstDoor"UnlockDoor"true);
    
AddUseItemCallback(""yourSpecialKeyyourSecondDoor"UnlockDoor"true);
    
AddUseItemCallback(""yourSpecialKeyyourThirdDoor"UnlockDoor"true);
}

// GENERAL DOOR UNLOCK FUNCTION
void UnlockDoor(string &in asItemstring &in asEntity)
{
    
SetSwingDoorLocked(asEntityfalsetrue);
    
PlaySoundAtEntity("""unlock_door.snt"asEntity1.0ffalse);
    
    
// 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;

04-27-2016, 08:48 AM
Find


Messages In This Thread
Remove key after 3x uses - by serbusfish - 04-26-2016, 10:30 PM
RE: Remove key after 3x uses - by WALP - 04-27-2016, 01:51 AM
RE: Remove key after 3x uses - by Daemian - 04-27-2016, 06:39 AM
RE: Remove key after 3x uses - by Spelos - 04-27-2016, 08:48 AM
RE: Remove key after 3x uses - by serbusfish - 05-05-2016, 12:29 PM
RE: Remove key after 3x uses - by WALP - 05-05-2016, 12:49 PM
RE: Remove key after 3x uses - by Darkfire - 05-06-2016, 02:46 PM
RE: Remove key after 3x uses - by serbusfish - 05-08-2016, 11:28 AM
RE: Remove key after 3x uses - by Spelos - 05-08-2016, 07:55 PM
RE: Remove key after 3x uses - by Mudbill - 05-08-2016, 10:33 PM
RE: Remove key after 3x uses - by Darkfire - 05-09-2016, 04:31 PM



Users browsing this thread: 5 Guest(s)