genericplayer

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

genericplayer

Post by Veleran » Wed Aug 11, 2010 3:22 am

Is this sample script ok to use as template for a scripted player,i want it mostly for melee and occasionally projectiles?
If someone has an updated version (bugfree) can post it here.
1.It dont see anywhere in it saveattributes and loadatributes commands to save the state of the player between levels.
How nobody needed that?

2.And,i remember an old one that had some problems with inverted movement of the invisible standard player.

3.Also,can someone remind me how you use the script?Add a pawn with name "player" and add a player pawn to the pawn.ini?

4.If that s it,how do you define more than one players in the pawn.ini?

5.Is there a way to script character selection for players that use script like the genericplayer.s?

6.If there is a way,then for each level do you have to add one playersetup and playerstart,and all-14-for example pawns that will be the players?

Code: Select all

{
	FIREAMMO 		[pistolbullet]	// Projectile fired by pawn
	FIREEFFECT 		[Electric]		// muzzleflash effect
	WEAPONMODEL 	[Laser]			// Weapon held by pawn
	FIRERATE 		[0.1]			// Weapon firing rate
	GROUP 			[Friendly]		// Pawn Group - must be targetted by enemies
	PLAYERSPEED 	[96]			// Walk Speed
	HEALTHATTRIB 	[health]		// health attribute given to pawn
	HEALTHAMOUNT 	[500]			// amount of health given to pawn
	DAMAGEATTRIB 	[health]		// Atribute damaged by pawn
	BOX 			[24]			// Box width
	
	IDLEANIM 		[recon_idle]			// Idle AnimationSpeed
	SHOOTANIM 		[recon_shoot]			// Shoot anim
	WALKANIM 		[recon_walk]			// Walk anim
	BACKANIM 		[recon_walk_back]		// Walk back anim
	STRAFELEFT 		[recon_strafe_left]		// Strafe left anim
	STRAFERIGHT 	[recon_strafe_right]	// Strafe right anim
	INTERANIM 		[recon_strike]			// Pawn interact anim
	DEATHANIM 		[recon_die]				// Death Anim
	ROOTBONE 		[Bip01]					// Pawn root bone
	WEAPONHAND 		[Bip01 L Hand]			// Pawn weapon bone
	
	K_INTER 		[73] // INTERACT KEY - RIGHT MOUSE
	K_FIRE 			[72] // FIRE KEY - LEFT MOUSE
	K_FOR 			[15] // FORWARD - W
	K_BAK 			[27] // BACK - S
	K_LEFT	 		[26] // STRAFE LEFT - A
	K_RIGHT 		[28] // STRAFE RIGHT - D
	K_RUN 			[36] // RUN - LEFT SHIFT KEY
	
	ANIM 			[string]	// Do Not Edit
	ANC 			[0]			// Do Not Edit
	LASTANC 		[0]			// Do Not Edit
	DIR 			[0]			// Do Not Edit
	AT 				[0.5]		// Do Not Edit
	INTER	 		[string]	// Do Not Edit
	TM 				[0]			// Do Not Edit
	SPEED 			[0]			// Do Not Edit
	
	Spawn[()
	{
		Console(false);
		BoxWidth(BOX);
		SetGroup(GROUP);
		AttributeOrder(HEALTHATTRIB, HEALTHAMOUNT, "Die");
		SetWeapon(WEAPONMODEL);
		LowLevel("Setup");
	}]
    
	Setup[()
	{
		AttachCamera();
		self.yaw_speed=256;
		AnimateHold(IDLEANIM);
		ANIM=StringCopy(IDLEANIM);
		ANC=0;
		LASTANC=0;
		TM=self.time;
		self.think="RunPlayer";
	}]
	
	RunPlayer[()
	{
		//debug(self.key_pressed);
		PlayerRender(false);
		self.ideal_yaw=self.player_yaw;
		ChangeYaw();
	
		DIR=0; 				// Default straight
		SPEED=0; 			// Default - no motion
		AT=0.1; 			// Default
		ANC=0; 				// Default
		AnimationSpeed(1); 	// Default
	
		// handle health status
		if(self.health < 1)
		{
			HighLevel("Die");
			return 0;
		}
	
		// handle controls
		if(IsKeyDown(K_INTER))
		{
			//strike/interact
			AnimateBlend(INTERANIM, 0.25);
			self.think="Interact";
			return 0;
		}

		if(IsKeyDown(K_FOR))
		{
			// forward
			ANIM=StringCopy(WALKANIM);
			ANC=2;
			SPEED=Integer(PLAYERSPEED);
		}

		if(IsKeyDown(K_BAK))
		{
			// back
			ANIM=StringCopy(BACKANIM);
			ANC=3;
			DIR=ConvertDegrees(180);
			SPEED=Integer(PLAYERSPEED);
		}

		if(IsKeyDown(K_LEFT))
		{
			// strafe left
			ANIM=StringCopy(STRAFELEFT);
			// make strafe transition smoother
			AT=0.5;
			ANC=4;
			DIR=ConvertDegrees(90);
			SPEED=Integer(PLAYERSPEED);
		}

		if(IsKeyDown(K_RIGHT))
		{
			// strafe right
			ANIM=StringCopy(STRAFERIGHT);
			// make strafe transition smoother
			AT=0.5;
			ANC=5;
			DIR=ConvertDegrees(270);
			SPEED=Integer(PLAYERSPEED);
		}

		if(IsKeyDown(K_FIRE))
		{
			// fire
			if(ANC < 1)
			{
				//only go to shoot anim if at idle
				ANIM=StringCopy(SHOOTANIM);
				ANC=1;
			}
			// Check fire rate
			if(self.time > TM+FIRERATE)
			{
				TM=self.time;
				FireProjectileBlind(FIREAMMO, WEAPONHAND, 0, 0, 0, DAMAGEATTRIB);
				AddExplosion(FIREEFFECT, WEAPONHAND, 0, 0, 0);
				TM=self.time;
			}
		}

		if(ANC < 1)
		{
			//no button
			ANIM=StringCopy(IDLEANIM);
			AT=0.5;
		}

		if(IsKeyDown(K_RUN))
		{
			//left shift key - toggle run
			AnimationSpeed(1.5);
			SPEED=SPEED+(SPEED/2);
		}

		//handle animations
		if(Integer(LASTANC) != Integer(ANC))
		{
			AnimateBlend(ANIM,AT);
		}
		LASTANC=Integer(ANC);
		if(self.animate_at_end)
		{
			AnimateHold(ANIM);
		}

		//handle motions
		walkmove(self.current_yaw+DIR,SPEED);
	}]

	Interact[()
	{
		if(self.animate_at_end)
		{
			INTER=TraceToActor(ROOTBONE, 0, 0, 32);
			if(INTER != "FALSE")
			{
				SetEventState(INTER # "Trigger", true);
			}
			self.think="RunPlayer";
			return 0;
		}
	}]

	Die[()
	{
		AnimateStop(DEATHANIM, 0, "");  
	}]
}
Last edited by paradoxnj on Thu Aug 12, 2010 4:00 pm, edited 1 time in total.
Reason: Added code tags to make it easier to read

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

Re: genericplayer

Post by Veleran » Wed Aug 11, 2010 11:56 pm

I wonder how the player is hidden,do you change the alpha in playersettup.ini?
that way wont the player still receive stencil shadows?Is the pawn attached to the player via the entity name to the root bone?i m not sure, guessing.
Its been five years since i used the scripted player and i dont remember the entities settup.I dont want to try a whole pickles demo,i just to know what entities i need and szentity names to use.

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

Re: genericplayer

Post by QuestOfDreams » Mon Aug 16, 2010 10:21 am

Is this sample script ok to use as template for a scripted player,i want it mostly for melee and occasionally projectiles?
The script is ok, the player can fire projectiles, no melee attack implemented there (although it's not for a player you can take a look at the genericmelee.s script for ideas on how to add that).
1.It dont see anywhere in it saveattributes and loadatributes commands to save the state of the player between levels.
You have to use the Attribute commands with the last parameter (string EntityName) set to "Player". (Only player attributes get saved while changing the level (of course only if you specify it in the ChangeLevel entity))
2.And,i remember an old one that had some problems with inverted movement of the invisible standard player.
Don't remember that one...
3.Also,can someone remind me how you use the script?Add a pawn with name "player" and add a player pawn to the pawn.ini?
Add a player pawn to pawn.ini, add a pawn entity to the level, don't name it "Player" (could confuse the engine as "Player" is used in some methods to identify the built in player).
4.If that s it,how do you define more than one players in the pawn.ini?
Just add another pawn definition, the name doesn't matter (but don't use "Player" as mentioned above)
5.Is there a way to script character selection for players that use script like the genericplayer.s?
I don't think so, at least it would be rather difficult (create a level that acts as selection menu, save selection as attribute, use attribute in next level as a trigger to spawn only the desired player pawn, haven't tried though)
6.If there is a way,then for each level do you have to add one playersetup and playerstart,and all-14-for example pawns that will be the players?
Yes.

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

Re: genericplayer

Post by QuestOfDreams » Mon Aug 16, 2010 10:30 am

Veleran wrote:I wonder how the player is hidden, do you change the alpha in playersettup.ini?
RunPlayer[()
{
//debug(self.key_pressed);
PlayerRender(false);
that way wont the player still receive stencil shadows?
PlayerRender(false); prevents the built-in player's actor to get rendered, as would an alpha value of 0. What does not get rendered does not receive stencil shadows.
Is the pawn attached to the player via the entity name to the root bone? i m not sure, guessing.
The pawn is not attached to the player, it just uses its rotation (yaw). Usually you lock away the player, so he can't move around.
Its been five years since i used the scripted player and i dont remember the entities settup.I dont want to try a whole pickles demo,i just to know what entities i need and szentity names to use.
See previous post.

Post Reply