Fire rate (high level)

Topics regarding Scripting with Reality Factory
Post Reply
Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Fire rate (high level)

Post by Veleran » Wed Sep 21, 2011 3:49 pm

I have this pawn on a wall that fires with a small delay between shots,yet it keeps firing all the time.

I do not know how to make it repeat that fire order for a certain amount of time,then go to an other order to play a delay for some seconds (so you can pass over the trap) and then go back to the fire order.
And,f i could randomize it to use a min and max pause time,even better.

{
Spawn[ ()
{
Console(true);
BoxWidth(16); // set bounding box width/depth
NewOrder("Fire");
} ]

Fire[ ()
{
FireProjectile("Firebolt", "BONE02", 0, 0, 0, "health", "");
Delay("Idle", 0.4, "");
AttributeOrder("health", 20, "Destoyed");
RestartOrder();
} ]

Destoyed[ ()
{
AddExplosion("Firebolt1Explosion", "BONE02", 0,0,0);
SetEventState("Trap1Trigger", true);
Remove(true);
} ]

}

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Fire rate (high level)

Post by Allanon » Wed Sep 21, 2011 5:20 pm

Try using the AddTimerOrder() command:

In this example it should fire for 10 seconds then idle for 10 seconds then repeat.

Code: Select all

{ 
    Spawn[ ()
    {
        Console(true);
        BoxWidth(16);	 // set bounding box width/depth
        AddTimerOrder(1,10,"Idle");
        NewOrder("Fire");
    } ] 

    Fire[ () 
    {
        FireProjectile("Firebolt", "BONE02", 0, 0, 0, "health", "");
        Delay("Idle", 0.4, "");
        AttributeOrder("health", 20, "Destoyed");
        RestartOrder();
    } ] 

    Idle[ () 
    {
        AddTimerOrder(1,10,"Fire");
        AddTimerOrder(2,20,"Idle");
    } ] 

    Destoyed[ () 
    { 
        AddExplosion("Firebolt1Explosion", "BONE02", 0,0,0);
        SetEventState("Trap1Trigger", true);
        Remove(true);
    } ] 

}
Idle could also look like this:

Code: Select all

    Idle[ () 
    {
        Delay("Idle", 10, "");
        AddTimerOrder(1,10,"Idle");
        NewOrder("Fire");
             
    } ] 
I'm not sure if the DelTimerOrder() command should be used before setting another timer with the same Timer#.

Or you can do something like this:

Code: Select all

{ 

    timer  [0]

    Spawn[ ()
    {
        Console(true);
        BoxWidth(16);	 // set bounding box width/depth
        timer = time;
        NewOrder("Fire");
       
    } ] 

    Fire[ () 
    {
        if (time > timer + 10)
        {
            Delay("Idle", 10, "");
            timer = time;
        }
        FireProjectile("Firebolt", "BONE02", 0, 0, 0, "health", "");
        Delay("Idle", 0.4, "");
        AttributeOrder("health", 20, "Destoyed");
        RestartOrder();
    } ] 

    Destoyed[ () 
    { 
        AddExplosion("Firebolt1Explosion", "BONE02", 0,0,0);
        SetEventState("Trap1Trigger", true);
        Remove(true);
    } ] 

}
Note: I didn't test this code so it could have problems but you should get the idea of what the code is doing.
Last edited by Allanon on Wed Sep 21, 2011 7:10 pm, edited 1 time in total.

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Fire rate (high level)

Post by Allanon » Wed Sep 21, 2011 7:04 pm

And,f i could randomize it to use a min and max pause time,even better.

Code: Select all

{ 

    min_pause   [5]
    max_pause   [20]

    Spawn[ ()
    {
        Console(true);
        BoxWidth(16);    // set bounding box width/depth
        AddTimerOrder(1,random(min_pause,max_pause),"Idle");
        NewOrder("Fire");
    } ] 

    Fire[ () 
    {
        FireProjectile("Firebolt", "BONE02", 0, 0, 0, "health", "");
        Delay("Idle", 0.4, "");
        AttributeOrder("health", 20, "Destoyed");
        RestartOrder();
    } ] 

    Idle[ () 
    {
        Delay("Idle", random(min_pause,max_pause), "");
        AddTimerOrder(1,random(min_pause,max_pause),"Idle");
        NewOrder("Fire");
     } ] 

    Destoyed[ () 
    { 
        AddExplosion("Firebolt1Explosion", "BONE02", 0,0,0);
        SetEventState("Trap1Trigger", true);
        Remove(true);
    } ] 

}
or

Code: Select all

{ 

    timer       [0]
    min_pause   [5]
    max_pause   [20]

    Spawn[ ()
    {
        Console(true);
        BoxWidth(16);    // set bounding box width/depth
        timer = time;
        NewOrder("Fire");
       
    } ] 

    Fire[ () 
    {
        if (time > timer + random(min_pause,max_pause))
        {
            Delay("Idle", random(min_pause,max_pause), "");
            timer = time;
        }
        FireProjectile("Firebolt", "BONE02", 0, 0, 0, "health", "");
        Delay("Idle", 0.4, "");
        AttributeOrder("health", 20, "Destoyed");
        RestartOrder();
    } ] 

    Destoyed[ () 
    { 
        AddExplosion("Firebolt1Explosion", "BONE02", 0,0,0);
        SetEventState("Trap1Trigger", true);
        Remove(true);
    } ] 

}

Post Reply