Pawn scripts

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

Pawn scripts

Post by Veleran » Mon Jul 11, 2016 12:14 pm

I need some advice for various scripts.
I temporary used static entity proxy trap actors and want to switch them with Pawns.
Right now i was thinking what to write in the script for a Spear trap in a pit 64 x 64 x 64.

The plan is the Player to have two more attributes :Spot and Disarm (min 1 max 10?).
The higher the spot is,the more visible the trap becomes and at a greater distance.

The trap pawn first checks if it can see the Player at a certain distance - lets say 256 units-texels.
If his spot attribute is high or max,the pawn gets a transparency 255-solid.
The lower the spot is the lower the visibility,example if spot is 5,the trap pawn will be alpha 127 and render at 128 texels away.
With spot around 1 i imagine transparency to be set to 64,at distance 96.
And then,at 64 texels i think the player should receive some damage anyway and the trap can get full alpha (255).

For other traps i imagine i would try 64 texels as min render distance,but the spears are 64 units down in the pit and at distance 64 the would become visible only when you fall down.

Also i am not sure if i can use these commands:
ModifyAttribute(string AttributeName, int Amount, string EntityName);
or damagearea?

I trying to add what i have so far so i can uploald the small level tet demo for Allanon to take a look at it and see what we can do.
I still have to place breakables,8 total traps,model the ham pickup,maybe model few barrels now that i got the breakable script,and all this takes days.
Until then i might make a simple script for the speartrap with playerdist order and then modifyattribute just to replace the static entity trap.
Or just do nothing script,put the 4 vase breakables and upload sooner,i will see..

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Pawn scripts

Post by Veleran » Thu Jul 21, 2016 2:27 pm

An example:This one spears trap in the circular pit 128 units radius,as the player gets near it,is shut down everything with the message "incorrect parameters in method FadeIn".
I thought the fade in did not have enough time to be executed but i do not think the NextOrder command after it to be messing it.

I would prefer something in Low level with damageAttribute directly when player is near,but i leave it for later becasue i do not kow yet enough about it.
Right now i wanted to just place all kinds of traps i prepared and assign a simple working script to each,so i can test some most basics of a level and rid of any big bugs ,before i would ever upload for further script testing.

Code: Select all

{ 
	Spawn[ ()
	{
		       Console(false);
		       Gravity(false);
               BoxHeight(1);
		       FadeOut(0.1,0);
		       NewOrder("WaitHidden");
      } ] 
	  
	WaitHidden[ () 
	{   	
		PlayerDistOrder(128,"FadeIn");
		RestartOrder();
	} ]  
	
	FadeIn[ ()
    {   	
		FadeIn(1,255);	
		NextOrder("Wait");
	} ]
	
	Wait[ ()
    {   	
		PlayAnimation("Idle",false,"");
		PlayerDistOrder(64,"DoDamage");
		RestartOrder();
	} ]
	
	DoDamage[ ()
    {   	
		ModifyAttribute("heath",-3);
		Delay("Idle",3,"");
		RestartOrder();
	} ]
} 

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Pawn scripts

Post by Veleran » Thu Jul 21, 2016 2:48 pm

Hmm...it just got fixed.
I did not think it would not like to use the name of the command FadeIn also as an order name.

The thing now is that the Player does not take any damage even when he is standing close ,and on it,or ever inside the specified damage radius.

Code: Select all

{ 
	Spawn[ ()
	{
		       Console(false);
		       Gravity(false);
               BoxHeight(1);
		       FadeOut(0.1,0);
		       NewOrder("WaitHidden");
      } ] 
	  
	WaitHidden[ () 
	{   	
		PlayerDistOrder(128,"Appear");
		RestartOrder();
	} ]  
	
	Appear[ ()
    {   	
		FadeIn(1,255);	
		NextOrder("Wait");
	} ]
	
	Wait[ ()
    {   	
		PlayAnimation("Idle",false,"");
		PlayerDistOrder(64,"DoDamage");
		PlayerDistOrder(64,"Wait");
		RestartOrder();
	} ]
	
	DoDamage[ ()
    {   	
		ModifyAttribute("heath",1,"Player");
		Delay("Idle",3,"");
		RestartOrder();
	} ]
} 

I will try something similar with other traps until i find something better.
There is some other trap that is kind of different.
It has a blade that comes out slashing to which i wanted to use damage area method or fire projectiles from three bones across the blade ,but i leave that for another time.

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Pawn scripts

Post by Veleran » Thu Aug 11, 2016 10:43 am

Let me ask something else,can you use the szEntity name of a Pawn entity in the level as a Trigger instead of an actual trigger,Logic gate or the SetEventState command?
It is about a Pawn lever that would act as a trigger.

If i have a lever pawn and a glyph pawn,the lever script sends an event state to the Glyph Pawn script to change its ambient so it will look like the Glyoh symbol is glowing lit,
for each Glyph in the level i would need a unique lever script,commanding like SetEventState "Glyph1_Trigger = true" ,another script telling "Glyph1_Trigger = true" and so on.

I ask if i can avoid having those different scripts by having one lever script used by many levers and each Glyph Symbol Pawn to use the szEntity name of each lever pawn in the level.

As for the previous scripting questions posts:
I have replaced most trap pawns with world model moving platforms that use model state modifier entities for the damage,and static entity proxy for static ones.
That is because the trap Pawn projectiles did not damage player when ever they were launched close the Pawn's polygons.
Example,the swinging ball projectile was fired from the center inside the spiked ball that was supposed to damage player,which was too close to the pawn polys to have any effect.

Or the slash trap that had a long blade coming out of the wall,the projectiles were fired from the three bones along the blade and if their launch would be offset was set away from the blade polygons,it would become very inaccurate,and
you would take damage even when you just pass close by the trap blade

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

Re: Pawn scripts

Post by Allanon » Fri Aug 12, 2016 10:32 am

Veleran wrote:Let me ask something else,can you use the szEntity name of a Pawn entity in the level as a Trigger instead of an actual trigger,Logic gate or the SetEventState command?
It is about a Pawn lever that would act as a trigger.
I don't know how to use a pawn directly as a trigger but you can use the pawn's SpawnPoint to store the name of the other pawn. To access the string in SpawnPoint from within the script just use the pawn variable point_name.

You can put the lever pawn's name in the glyph pawn's SpawnPoint then use the point_name to check an attribute:

Lever script:

Code: Select all

AddAttribute("Lever", 0, 1);  # Add and set attribute to 0
SetAttribute("Lever", 1);     # Set attribute to 1
Glyph script:

Code: Select all

if (GetAttribute("lever", point_name) = 1)
    //do something
Or you can put the glyph pawn's name in the lever pawn's SpawnPoint then use point_name to set an event:

Lever script:

Code: Select all

SetEventState(point_name # " lever pulled", true);
Glyph script:

Code: Select all

if (GetEventState(EntityName # " lever pulled") = true)
    // do something

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Pawn scripts

Post by Veleran » Fri Aug 12, 2016 3:05 pm

Thank you very much although that syntax looks too complicated to me.
Maybe i will do what i thought from the beginning if i was about to use too many switches.
Add various orders in the lever script named Lever1_On ,Lever2_On and so on,then in the editor choose one of them as the next order after the start in each lever spawn Script point.


Or just use the button world trigger model i already got,or make a small switch trigger model for the trigger,it cant look that bad from afar...

I will try again such scripting later if i am more familiar with it.

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Pawn scripts

Post by Veleran » Tue Aug 16, 2016 9:20 pm

Since the next order of the script point did nothing to change order,(i do not know if it wanted the pawn to first be trigger spawned) i wrote this script and it works okay,and i like hoe the short switch sound loops and fakes a gear mechanism sound.

Code: Select all

{ 
	Switch1[ () 
        {     
			Console(false);
			Gravity(false);
			SetScale(1.25);		
		    AnimateStop("Up",2,"");
		    AddCollisionOrder("Switch1_Pulled");
        } ] 
	
	Switch1_Pulled[ () 
        {   
		    BlendToAnimation("Down",0.3,true,"Dark Crypt/Environment//Switch.wav");
			SetEventState("Switch1_On",true);
		    AnimateStop("Down",1,"");
			EndScript();
	    } ] 
		
	Switch2[ () 
        {     
			Console(false);
			Gravity(false);
			SetScale(1.25);
		    AnimateStop("Up",2,"");
		    AddCollisionOrder("Switch2_Pulled");
        } ] 
	
	Switch2_Pulled[ () 
        {   
		    BlendToAnimation("Down",0.25,true,"Dark Crypt/Environment//Switch.wav");
			SetEventState("Switch2_On",true);
		    AnimateStop("Down",1,"");
			EndScript();
	    } ] 
    } 
So far okay,and now i need to test how to activate the glyph door with more than one lever.
Either put logic gate that waits both switch event state to be On,or have a script for it.
If i use the old way with the logic gate entity ,if i later need to drop more switched than two i will have place another logic gate.

What do you suggest?I could try adding the door as a pawn that uses a script that waits four triggers to be previously set to on.
The only bad thing about that is not the script but the square bounding box that does not match the thin door and i will have to place the door pawn further from its supposed location so you do not bump on an invisible barrier when closing in,and when activated the door should remain open afterwards to avoid the inaccurate collision.

I can surely need the callback like checking of triggers also in various other occasions like a Sub Boss Pawn that checks if many of his mates have fallen so he escapes in time or call for reinforcements,destroying a certain number of monsters for rewards and other puzzle like things.
Can you remind me how you write the checking of the four triggers state in high level- if it is suitable?

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Pawn scripts

Post by Veleran » Wed Aug 17, 2016 5:29 pm

I got a Glyph (hireroglyphic like from Faistos of Crete) actor and writing a script for it to increase the ambient and maybe fill color when the switch is on.
I do not know how to write the ambientlightfromfloor part.How about the brackets and the = true words spelling,i do not remember having an exact example somewhere to copy.

Also,if some day i want to add in a level two same Glyphs that use the same script but have a different szEntityName like Glyph27_1 Glyph27_2 ?

I do not know how to define it so any szEntityName you put in the editor Pawn entity to be automatically read in the SetEntityLighting order.
If i learn how to complete the ambient light = true syntax to run the script i will be satisfied for the moment because i do not plan very soon to put two of the same glyphs yet.

As you can see the script is unfinished

Code: Select all

{ 
	Glyph27[ () 
        {     
			Console(false);	
		    AnimateStop("Idle",1,"");
         if (GetEventState("Switch1_On") = true)
         {
		 LowLevel("Glyph27_Lit");
		 }			 
        } ] 
	
	Glyph27_Lit[ () 
        {   
            SetEntityLighting("Glyph27", 64, 64, 64, 127, 127, 127, bool AmbientLightFromFloor);
		    AnimateStop("Idle",1,"");
			EndScript();
	    } ] 
		
	Glyph02[ () 
        {     
			Console(false);
		    AnimateStop("Idle",1,"");
         if (GetEventState("Switch2_On") = true)
         {
		 LowLevel("Glyph02_Lit");
		 }				 
        } ] 
	
	Glyph02_Lit[ () 
        {   
            SetEntityLighting("Glyph02", 64, 64, 64, 127, 127, 127, bool AmbientLightFromFloor);
		    AnimateStop("Idle",1,"");
			EndScript();
	    } ] 
    } 

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

Re: Pawn scripts

Post by QuestOfDreams » Wed Aug 17, 2016 7:46 pm

You can access a Pawn's szEntityName via the Pawn variable EntityName, e.g.

Code: Select all

SetEntityLighting(self.EntityName, 64, 64, 64, 127, 127, 127, false);

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Pawn scripts

Post by Veleran » Fri Aug 19, 2016 2:33 am

Thank you.This is the script for two pawns signs.One from each placed near the door and the other two placed each above its switch.
I copied pieces from elsewhere and after many preview runs and re editing the script, i made it work,although it may still have minor errors which i do not see.

Code: Select all

{ 
	Glyph27[ () 
        {     
			Console(false);	
			LowLevel("Glyph27Wait");
		} ] 
		
	Glyph27Wait[ () 	
        {	
		    SetEntityLighting("Glyph27", 16, 16, 16, 64, 64, 64, false);
			SetEntityLighting("Glyph27_Door", 16, 16, 16, 16, 16, 16, false); 	
         if(GetEventState("Switch1_On") = true)
         {
			 
            SetEntityLighting("Glyph27", 64, 64, 64, 127, 127, 127, false);
			SetEntityLighting("Glyph27_Door", 64, 64, 64, 127, 127, 127, false); 
		}			 
	    } ] 
		
	Glyph02[ () 
        {     
			Console(false);	
			LowLevel("Glyph02Wait");
		} ] 
		
	Glyph02Wait[ ()
        {		
		    SetEntityLighting("Glyph02", 16, 16, 16, 48, 48, 48, false);
		    SetEntityLighting("Glyph02_Door", 16, 16, 16, 16, 16, 16, false); 		
         if(GetEventState("Switch2_On") = true)
         {
            SetEntityLighting("Glyph02", 64, 64, 64, 127, 127, 127, false);	
			SetEntityLighting("Glyph02_Door", 64, 64, 64, 127, 127, 127, false);	
		}			 
	} ] 

} 

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Pawn scripts

Post by Veleran » Thu Sep 08, 2016 12:00 am

I have this monster generator script,which is a static actor that as long it is alive the monsters keep re spawning,
but it does not seems to take any damage when you hit it.
It just restarts the Idle order over and over.

Code: Select all

{ 
	Start[ ()
	    {
			Console(true);
			Gravity(true);
			BoxWidth(28);
			BoxHeight(28);
            NewOrder("Idle");
        } ] 

	Idle[ () 
        {      
			SetEventState("Skeleton_Generator_1_1_On", true);
		  	AttributeOrder("enemy_health", 10, "Destroyed");
		    RestartOrder();
        } ] 
	
	Destroyed[ () 
        {   
			SetEventState("Skeleton_Generator_1_1_On", false);
		  	AddExplosion("VaseCeramic1_Explosion", "BONE02", 0, 0, 0);
			LoopAnimation("Idle", 0.15, "");
			Remove(true);
	    } ] 
    } 
Another is the monster generator ruby red eyes pawn that glow by changing the ambient in low level.
I do not say it worked,i got a parse error in order Glow near "0".
What i do not know if you can add a pause between each ambient value,as i can not find any delay command like in High level.
I am trying to avoid switching to highlevel every time the ambient lightning changes.

If it is difficult to do this eyes glow,then i will skip it.

Code: Select all

{ 
	Start[ () 
        {     
			Console(true);	
			LowLevel("Glow");
		} ] 
		
	Glow[ () 	
        {	
		    SetEntityLighting("Skeleton_Generator_1_Eyes", 0, 0, 0, 0, 0, 0, false);	
			SetEntityLighting("Skeleton_Generator_1_Eyes", 0 0, 0, 64, 64, 64, false); 	
			SetEntityLighting("Skeleton_Generator_1_Eyes", 0, 0, 0, 127, 127, 127, false); 	
			SetEntityLighting("Skeleton_Generator_1_Eyes", 0, 0, 0, 180, 180, 180, false); 
			SetEntityLighting("Skeleton_Generator_1_Eyes", 0, 0, 0, 127, 127, 127, false); 	
			if(GetEventState("Skeleton_Generator_1_1_On") = false)
			HighLevel("Destroyed");
		}			 
	} ] 
 
 	Destroyed[ () 
        {     
			Remove(true);
		} ] 
} 

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

Re: Pawn scripts

Post by Allanon » Thu Sep 08, 2016 12:45 am

In the first script the RestartOrder(); will cause the Idle order to keep repeating that means you are repeatedly calling AttributeOrder("enemy_health", 10, "Destroyed"); and that function sets "enemy_health" to 10 each time it's called. Try removing RestartOrder();

In the second script you are missing curly brackets:

Code: Select all

 
if(GetEventState("Skeleton_Generator_1_1_On") = false)
{
         HighLevel("Destroyed");
}

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Pawn scripts

Post by Veleran » Thu Sep 08, 2016 10:49 am

The generator works now.The eyes still have the parse error near "0".
And even if it worked,is there a way to insert a pause between each glow value at low level?
That is useful and i wonder how it can be done in low level.
I would like it to stay darker lets say 0.5 or 1 second and then go to the next line and increase or decrease the ambient.

But,it looks like easier to add an actor material entity in the level for each generator eyes to play a bitmap sequence that turns from black to red and backwards.
I just have to set the Pawn ambient to a stead 127 in the pawn ini to make sure the brightest color can not be darkened by the level geometry shadows.

Flipbook actor material might look easier but i wanted to script it to avoid extra bitmaps and level entities.
The scripted Glyph i have that gets lit did not need animated bitmaps because its glowing is static.

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

Re: Pawn scripts

Post by Allanon » Thu Sep 08, 2016 9:49 pm

I just noticed there is an extra bracket at the bottom of the Glow order.

Try this:

Code: Select all

{ 
   colors { [0][64][127][180][127]}
   index [0]

   Start[ () 
   {     
         Console(true);   
         LowLevel("Glow");
   } ] 
      
   Glow[ ()    
   {   
         self.ThinkTime = 1.0;
         c = colors[index];
         SetEntityLighting("Skeleton_Generator_1_Eyes", 0, 0, 0, c, c, c, false);   
         index = index + 1;
         if (index = colors.numChildren)
         {
             index = 0;
         }
 
         if (GetEventState("Skeleton_Generator_1_1_On") = false)
         {
             HighLevel("Destroyed");
         }
                
   } ] 
 
   Destroyed[ () 
   {     
         Remove(true);
   } ] 
}
Note: I didn't try this code so it might have errors

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Pawn scripts

Post by Veleran » Fri Sep 09, 2016 1:26 pm

Thank you.The script works and it looks good from far.Now i got to merge the scripts of the generator and its eyes because for some unknown reason the eyes that are in the same origin with the main pawn do not appear in the level.

I re exported the generator as one actor,using extra normal map material for the bones to prevent the main actor from changing ambient (because a bug prevents the dot3 normal mapped materials from having ambient other than 0), and a common material for the red eyes.


I do not need any red tint this moment by the way,i say we leave the ambient colors neutral.
From closer view you can see that the glow animation can be improved more.

If you say 0 is black and 3 is 127 ,right now it goes like this : 0 - 1- 2 3 -2 - 0 (it skips the 1 when it goes down).
I would prefer if it goes 0 1 2 3 -3 2 1 0 and restart.

Another detail is to add twice interpolation values between the increase/decrease.
I guess change of 32 between each value at the same rate will be smoother,and better.

I need to merge the two scripts by adding in the latest glowing script a health function that allows it to be destroyed and do the explosion instead of checking the trigger to do that.
I did many runs until i find out the explosion was not working and shut down the level if there was not enough time after the explosion line,and that is why i put there the LoopAnimation.

I do not know what can be done for that in low level,but i hope something will be found.


And to add the trigger event state on and off that is for the skeletons that re spawn as long as the generator is alive.

You will be sure what i mean if you take a look at the script.

Code: Select all

{ 
	Start[ ()
	    {
			Console(false);
			Gravity(true);
			BoxWidth(22);
			BoxHeight(28);
            NewOrder("Idle");
        } ] 

	Idle[ () 
        {      
			SetEventState("Skeleton_Generator_1_1_On", true);
		  	AttributeOrder("enemy_health", 10, "Destroyed");
        } ] 
	
	Destroyed[ () 
        {   
			SetEventState("Skeleton_Generator_1_1_On", false);
			SetNoCollision();
			FadeOut(0.01,0);
		  	AddExplosion("SkeletonGeneratorExplosion", "BONE02", 0, 0, 0);
			LoopAnimation("Idle", 1.0, "");
			Remove(true);
			
	    } ] 
    } 

Post Reply