Frictional Games Forum (read-only)

Full Version: Scripting problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to make a script to make an enemy randomly appear and disappear, then loop the script. The problem is, after he has been activated once, he never comes back. Here is my script at the moment -

void OnEnter()
{
AddEntityCollideCallback("Player", "ScriptArea_1", "activatemonster1", true, 1);
}

void activatemonster1(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("manhunter_1", true);
AddTimer("", RandFloat(5.0f, 20.0), "deactivatemonster1");
}

void deactivatemonster1(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("manhunter_1", false);
AddTimer("", RandFloat(60.0f, 120.0), "activatemonster1");
}

Would someone be able to tell me why its not repeating itself?
void OnEnter()
{
AddEntityCollideCallback("Player", "ScriptArea_1", "activatemonster1", true, 1);
}

void activatemonster1(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("manhunter_1", true);
AddTimer("", RandFloat(5.0f, 20.0), "deactivatemonster1");
}

void deactivatemonster1(string &in asTimer)
{
SetEntityActive("manhunter_1", false);
AddTimer("", RandFloat(60.0f, 120.0), "activatemonster1");
}

You had the wrong callback syntax in the first AddTimer call.
Ah I see, thanks for your help!
PHP Code:
void OnEnter() // should probably be OnStart
{
    
AddEntityCollideCallback("Player""ScriptArea_1""ActivateMonster"true1);
}

void ActivateMonster(string &in asParentstring &in asChildint alState)
{
    if (
asChild == "ScriptArea_1")
        
ActivateMonster("manhunter_1");
}

void ActivateMonster(string &in monster)
{
    
ResetProp(monster);
    
SetEntityActive(monstertrue);
    
AddTimer(monsterRandFloat(5.0f20.0), "DeactivateMonster");
}

void DeactivateMonster(string &in monster)
{
    
SetEntityActive(monsterfalse);
    
AddTimer(monsterRandFloat(60.0f120.0), "ActivateMonster");

Thanks, I'm still trying to learn the basics of scripting, so many stupid mistakes are made. I'm still at the stage where I punch the air if my map loads without a fatal error.
As a scripter you'll have to walk the fine balance of figuring things out yourself so you get better, and asking the fine folk here. My general rule of thumb: don't ask until the error is causing you to re-evaluate your goals in life.