Frictional Games Forum (read-only)

Full Version: HasItem problem [SOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What's wrong with this code? I have the key but it doesn't trigger the event.

Code:
void CollideAreaLiving(string &in asParent, string &in asChild, int alState)
{
    if(HasItem("key_storage") == true){
//Slime Fades
        SetPropActiveAndFade("slime_6way_1", true, 1.5f);
        SetPropActiveAndFade("slime_anim_wall_1", true, 1.5f);
        SetPropActiveAndFade("slime_pile_1", true, 1.5f);
        SetPropActiveAndFade("slime_pile_2", true, 1.5f);
//Effects
        StartScreenShake(0.115, 2.0f, 0.1f,0.3f);
        FadeSepiaColorTo(100.0f, 4.0f);
        FadeRadialBlurTo(0.15f, 6.0f);
        PlaySoundAtEntity("", "guardian_activated.snt", "Player", 0, false);
//Timer to remove effects
        AddTimer("FadeGone", 3.0f, "GuardianTimer");
    }
}

The code still won't get triggered if I have that key. What's wrong with it?
Mind posting the error message?
Oh sorry, I forgot to remove that part. Edited post above. The problem is now only that the script won't get activated even if I have the item.
Remove the " == true" from if(HasItem("key_storage") == true), like this
Code:
void CollideAreaLiving(string &in asParent, string &in asChild, int alState)
{
    if(HasItem("key_storage")){
//Slime Fades
        SetPropActiveAndFade("slime_6way_1", true, 1.5f);
        SetPropActiveAndFade("slime_anim_wall_1", true, 1.5f);
        SetPropActiveAndFade("slime_pile_1", true, 1.5f);
        SetPropActiveAndFade("slime_pile_2", true, 1.5f);
//Effects
        StartScreenShake(0.115, 2.0f, 0.1f,0.3f);
        FadeSepiaColorTo(100.0f, 4.0f);
        FadeRadialBlurTo(0.15f, 6.0f);
        PlaySoundAtEntity("", "guardian_activated.snt", "Player", 0, false);
//Timer to remove effects
        AddTimer("FadeGone", 3.0f, "GuardianTimer");
    }
}
The collidebox STILL won't get triggered o0.
Could you post the EntityCollideCallback that calls CollideAreaLiving?
Sure, here you go:
AddEntityCollideCallback("Player", "AreaLiving", "CollideAreaLiving", true, 1);
Spotted the problem (I think). You are destroying the Callback when it's triggered the first time.
Set abDeleteOnCollide to false and it should work.. You will have to find another way to remove the Callback only when you have the item. Example would be to use a variable and add a condition to your if conditional to only execute when the player has the key AND when the variable has the right value.
YES! It works! I never realized it would be such an easy answer. Thanks a thousand times. I've been trying to figure out why it didn't work for so long! Big Grin
Glad I could help! Smile