AddPainOrder Question

Topics regarding Scripting with Reality Factory
Post Reply
WebsterX37
Posts: 16
Joined: Sat Jul 07, 2007 4:44 pm
Location: Berlin, Germany

AddPainOrder Question

Post by WebsterX37 »

Hello

I am new to scripting Pawns but finally managed one simple script.

Pawn spawns
calles Order Idle

Order Idle restarts

Now I wanted to show some explosions if my pawn is hit. So I've read the manual and found the
AddPainOrder.

Within my Idle Order I placed this:

AddPainOrder("Hit",100);

the PainOrder looks as follows:

Hit[()
{
AddExplosion("FlameThrower","BONE_TRIGGER",0, 0, 0);
Return();
}]

I am wondering, where this hit-order returns to. I wanted it to switch back to my idle order but my
debug info says: we are still in the hit-order. How can I go back to idle-order? The HL command NewOrder worked
once, but after this my pain order wasn't called again. I've read some samples but can't figure it out.

Thx
Webster
User avatar
QuestOfDreams
Site Admin
Posts: 1520
Joined: Sun Jul 03, 2005 11:12 pm
Location: Austria
Contact:

Post by QuestOfDreams »

I am wondering, where this hit-order returns to.
When the order is done (by reaching the end of the order or executing a Return() command) control is returned to the (script) point where the Pawn was before the order was run.
Once the order was executed, pain checks are no longer done, you need to re-add the pain order.
Your script should look similar to this (not tested):

Code: Select all

{

    Spawn[()
    {
        // your setup code goes here
        NewOrder("Idle");
    }]

    Idle[()
    {
        // do idle stuff here
        RestartOrder();
    }]

    Hit[() 
    { 
        AddExplosion("FlameThrower","BONE_TRIGGER",0, 0, 0);
        AddPainOrder("Hit",100);
        NewOrder("Idle"); 
    }] 
}
WebsterX37
Posts: 16
Joined: Sat Jul 07, 2007 4:44 pm
Location: Berlin, Germany

Post by WebsterX37 »

Thanx for your answer!

So I tested it the wrong way, putting the AddPainOrder into the Idle-Order. If I understand this right:

The Ordername in AddPainOrder runs only ones and is only called again by an event if the pawn is hit, as long as the attribute
given to the pawn is bigger than zero?

I've added the AddPainOrder("Hit",100); to the spawn order, call the idle order and put the
AddPainOrder("Hit",100); to the Hit order like you wrote.

It did not work, the flames come up only ones at the first hit.

:-(
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis »

Seeing the whole script would help a lot here. :wink:
Pain is only psychological.
WebsterX37
Posts: 16
Joined: Sat Jul 07, 2007 4:44 pm
Location: Berlin, Germany

Post by WebsterX37 »

Here is my script, used for a TV to switch it on and off. The switching works fine. If it comes to "Hit"-order there
are two options:

First: I place a Return(); at the end of the "Hit"-order. Effect: Hitting works fine. But due to the Return() the order doesn't go back to the Order "IdleState". So switching does not work after pawn is hit.

Second: I place a NewOrder("IdleState"); at the end of the "Hit"-order. Effect: Hitting works only once, switching does not
work anymore after one hit.

I'll post the second version here:

Code: Select all

{
ACTIVATERANGE [70]	
TRIGGER [TVTRIGGER]
ALIVE [1000]

Spawn[()
{
	Console(true);
	AttributeOrder("enemy_health",ALIVE,"Die");
	SetFOV(360);
	HostilePlayer(false);
	HostileSame(false);
	HostileDifferent(false);
	IsPushable(true);
	SetGroup("TV");
	AudibleRadius(100);
	SetCollision();
	SetFlag(1,true);
	NewOrder("IdleState");
}]

SwitchOn[()
{
		AnimateStop("on", 1, "tvswitch.wav");
        SetEventState(TRIGGER, true);
        ChangeMaterial("glow_tv");
        NewOrder("IdleState");
}]

SwitchOff[()
{
		AddPainOrder("Hit", 100); 
		AnimateStop("ff", 1, "tvswitch.wav");
        SetEventState(TRIGGER, false);
        ChangeMaterial("tv_noglow");
        NewOrder("IdleState");
}]


IdleState[()
{
	AddPainOrder("Hit", 100); 
	if(self.player_range<ACTIVATERANGE)
	{
		if(self.key_pressed=16)
		{
			if(GetFlag(1)=true)
	    	{ 
		    	SetFlag(1,false);
		    	AddFlagOrder(1,false,"SwitchOn");
	    	}	  	
	    	else
	    	{
		    	SetFlag(1,true);
		    	AddFlagOrder(1,true,"SwitchOff");
	    	}	
   		} 	
   }
   RestartOrder();
}]


Hit[()
{
	AddPainOrder("Hit", 100); 
	AddExplosion("RocketExplosion","BONE_MAIN",0, 0, 0);
	NewOrder("IdleState");
	//Return();
}]


Die[()
{
	//AddExplosion("GeneralExplosion","",0, 0, 0); does not work, Pawn dead already!! no bone!
	Remove(true);
}]

}


At the long run we are all dead.
WebsterX37
Posts: 16
Joined: Sat Jul 07, 2007 4:44 pm
Location: Berlin, Germany

Post by WebsterX37 »

SOLVED IT! :D

I thought the only way could be, going LowLevel and not use AddPainOrder (HL-Command). Here it comes:

Code: Select all

{
ACTIVATERANGE [70]	
TRIGGER [TVTRIGGER]
ALIVE [1000]

Spawn[()
{
	Console(true);
	AttributeOrder("enemy_health",ALIVE,"Die");
	SetFOV(360);
	HostilePlayer(false);
	HostileSame(false);
	HostileDifferent(false);
	IsPushable(true);
	SetGroup("TV");
	AudibleRadius(100);
	SetCollision();
	SetFlag(1,true);
	NewOrder("IdleState");
}]

SwitchOn[()
{
		AnimateStop("on", 1, "tvswitch.wav");
        SetEventState(TRIGGER, true);
        ChangeMaterial("glow_tv");
        NewOrder("IdleState");
}]

SwitchOff[()
{
		AnimateStop("off", 1, "tvswitch.wav");
        SetEventState(TRIGGER, false);
        ChangeMaterial("tv_noglow");
        NewOrder("IdleState");
}]


IdleState[()
{
	debug(self.health);
	if(self.player_range<ACTIVATERANGE)
	{
		if(self.key_pressed=16)
		{
			if(GetFlag(1)=true)
	    	{ 
		    	SetFlag(1,false);
		    	AddFlagOrder(1,false,"SwitchOn");
	    	}	  	
	    	else
	    	{
		    	SetFlag(1,true);
		    	AddFlagOrder(1,true,"SwitchOff");
	    	}	
   		} 	
   }
   if(self.in_pain)							//pawn has been hurt meanwhile
   {
	   LowLevel("Hurted");	   				//go to LL
   }	   
   RestartOrder();
}]


Hurted[()
{
	if(self.health>0)
	{
		AddExplosion("FlameThrower","BONE_MAIN", 0, 0, 0); 
	}	
	HighLevel("IdleState");
	//Return();
}]



Die[()
{
	//AddExplosion("GeneralExplosion","",0, 0, 0); does not work, Pawn dead already!! no bone!
	Remove(true);
}]

}
At the long run we are all dead.
Post Reply