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


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with script
amusei Offline
Junior Member

Posts: 23
Threads: 8
Joined: Aug 2012
Reputation: 2
#1
Information  Help with script

Hi, guys.

I am trying to call a certain func when the player interacts with a door and the door is not locked. However, the function just keeps repeating when the player interacts and I want it to stop after it is called once. Here is my script.

void OnStart()
{
SetEntityPlayerInteractCallback("mansion_6", "Fade", false);
}

void Fade(string &in asEntity)
{
    if(GetSwingDoorLocked("mansion_6") == false)
    {
        SetSwingDoorClosed("mansion_3", true, true);
        SetSwingDoorLocked("mansion_3", true, true);
        PlaySoundAtEntity("", "guardian_activated.snt", "Player", 0, false);
        GiveSanityDamage(10, true);
        StartScreenShake(0.05f, 3.5f, 1.25f, 3.5f);
        FadePlayerRollTo(-50, 33, 33);
        MovePlayerHeadPos(0, -1, 0, 1, 0);
        PlaySoundAtEntity("", "player_bodyfall.snt", "Player", 0, false);
        SetPlayerCrouching(true);
        SetPlayerActive(false);
        FadeOut(7);
        AddTimer("", 13, "Fog");
    }
}

If I change the
SetEntityPlayerInteractCallback("mansion_6", "Fade", false);
to
SetEntityPlayerInteractCallback("mansion_6", "Fade", true);

The "Fade" won't be called if the player has already interacted with the door when it's locked. If it remains "false" it will just continue to repeat (the player will just fade every time he touches the door if it isn't locked and I want him to fade only the first time). Quite a head rush, eh ? Smile . I hope it has a solution Big Grin
(This post was last modified: 08-28-2012, 07:23 AM by amusei.)
08-27-2012, 10:16 AM
Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#2
RE: Help with script

If you don't mind me asking, what must the player do to activate this event (aside from interacting with the unlocked door)? What must he do prior to that, such as using a key on a door or pulling a lever? Or is the door unlocked from the very start? It feels like you've only posted a small portion of your entire script.

I rate it 3 memes.
08-27-2012, 10:36 AM
Find
amusei Offline
Junior Member

Posts: 23
Threads: 8
Joined: Aug 2012
Reputation: 2
#3
RE: Help with script

(08-27-2012, 10:36 AM)andyrockin123 Wrote: If you don't mind me asking, what must the player do to activate this event (aside from interacting with the unlocked door)? What must he do prior to that, such as using a key on a door or pulling a lever? Or is the door unlocked from the very start? It feels like you've only posted a small portion of your entire script.
Well, he must use a key to unlock the door. My entire scripts is too large to post and I don't think anyone would want to read through that Big Grin Here is the Key Unlock part of the script if you think it will help.

    void OnStart()
{
AddUseItemCallback("", "key_hall", "mansion_6", "UnlockDoorWithKey", true);
}

void  UnlockDoorWithKey(string &in asItemA, string &in asItemB)
{
    CompleteQuest("keyquest", "KeyQuest");
    SetSwingDoorLocked("mansion_6", false, true);
    PlaySoundAtEntity("", "unlock_door", "mansion_6", 0, false);
    RemoveItem("key_hall");
}
08-28-2012, 07:02 AM
Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#4
RE: Help with script

The power of variables! Here ya go:


void OnStart()
{
AddUseItemCallback("", "key_hall", "mansion_6", "UnlockDoorWithKey", true);
SetEntityPlayerInteractCallback("mansion_6", "Fade", false);
SetLocalVarInt("door_var", 0);
}

void UnlockDoorWithKey(string &in asItem, string &in asEntity)
{
CompleteQuest("keyquest", "KeyQuest");
SetSwingDoorLocked("mansion_6", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_6", 0, false);
RemoveItem("key_hall");
AddLocalVarInt("door_var", 1);
}

void Fade(string &in asEntity)
{
if(GetSwingDoorLocked("mansion_6") == false && GetLocalVarInt("door_var") == 1)
{
SetSwingDoorClosed("mansion_3", true, true);
SetSwingDoorLocked("mansion_3", true, true);
PlaySoundAtEntity("", "guardian_activated.snt", "Player", 0, false);
GiveSanityDamage(10, true);
StartScreenShake(0.05f, 3.5f, 1.25f, 3.5f);
FadePlayerRollTo(-50, 33, 33);
MovePlayerHeadPos(0, -1, 0, 1, 0);
PlaySoundAtEntity("", "player_bodyfall.snt", "Player", 0, false);
SetPlayerCrouching(true);
SetPlayerActive(false);
FadeOut(7);
AddTimer("", 13, "Fog");
SetLocalVarInt("door_var", 0);
}
}


I added a local variable that is added when the key is used to unlock the door; if the player interacts with the door while it is unlocked it will trigger the event (by adding the variable), then disable it from occuring again by setting the variable back to 0.

Hope that helped!

I rate it 3 memes.
08-28-2012, 07:12 AM
Find
amusei Offline
Junior Member

Posts: 23
Threads: 8
Joined: Aug 2012
Reputation: 2
#5
RE: Help with script

(08-28-2012, 07:12 AM)andyrockin123 Wrote: The power of variables! Here ya go:


void OnStart()
{
AddUseItemCallback("", "key_hall", "mansion_6", "UnlockDoorWithKey", true);
SetEntityPlayerInteractCallback("mansion_6", "Fade", false);
SetLocalVarInt("door_var", 0);
}

void UnlockDoorWithKey(string &in asItem, string &in asEntity)
{
CompleteQuest("keyquest", "KeyQuest");
SetSwingDoorLocked("mansion_6", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_6", 0, false);
RemoveItem("key_hall");
AddLocalVarInt("door_var", 1);
}

void Fade(string &in asEntity)
{
if(GetSwingDoorLocked("mansion_6") == false && GetLocalVarInt("door_var") == 1)
{
SetSwingDoorClosed("mansion_3", true, true);
SetSwingDoorLocked("mansion_3", true, true);
PlaySoundAtEntity("", "guardian_activated.snt", "Player", 0, false);
GiveSanityDamage(10, true);
StartScreenShake(0.05f, 3.5f, 1.25f, 3.5f);
FadePlayerRollTo(-50, 33, 33);
MovePlayerHeadPos(0, -1, 0, 1, 0);
PlaySoundAtEntity("", "player_bodyfall.snt", "Player", 0, false);
SetPlayerCrouching(true);
SetPlayerActive(false);
FadeOut(7);
AddTimer("", 13, "Fog");
SetLocalVarInt("door_var", 0);
}
}


I added a local variable that is added when the key is used to unlock the door; if the player interacts with the door while it is unlocked it will trigger the event (by adding the variable), then disable it from occuring again by setting the variable back to 0.

Hope that helped!
Thanks. That solved the problem. I will never underestimate the power of variables again!
08-28-2012, 07:22 AM
Find




Users browsing this thread: 1 Guest(s)