Page 1 of 2

Lovely Pawns!

Posted: Sat Jan 05, 2008 8:21 am
by Juryiel
So I just figured out (meaning read in tutorials) that I can use pawns in order to make my own control system through scripting. I've set up a pawn to move about, however, I'm having an issue.

Depending on the actorrotation parameter set for the pawn and for the default player, either the pawn moves opposite the default player and moves correctly (while the default player moves in a mirror image way), or moves in the same direction as the default player but both move back when I hit forward and forward when I hit back. I'm using the genericplayer.s script for the movement so I'm not sure what's up :(

Posted: Sat Jan 05, 2008 11:33 am
by Jay
I think there is something wrong with the genericplayer.s movement. I haven't noticed it before until yesterday, because I normally add this line to the genericplayer.s in RunPlayer():

PlayerToPosition(0, 0, 0, false);

This places the the player to the position of the pawn. Since this is done every frame, the player's position will always be the same as the pawn's.

Posted: Sat Jan 05, 2008 11:35 am
by Juryiel
Well I used a different approach to fix the problem above, but thanks :) On to more issues!

Edit: Yeap, that's the workaround I used too :)

Edit #2: Ah you can just add it once instead of adding it everywhere like I did? You sir are much more clever than I! Thanks!

Another interesting problem, the following code...:

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 [200] // 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 [Idle] // Idle AnimationSpeed
    SHOOTANIM [Shoot3] // Shoot anim
    WALKANIM [Walk] // Walk anim
    BACKANIM [Walk] // walk back anim
	RUNANIM [Run] //Run anim
    STRAFELEFT [recon_strafe_left] // Strafe left anim
    STRAFERIGHT [recon_strafe_right] // Strafe right anim
    INTERANIM [Hit] // Pawn interact anim
    DEATHANIM [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
	K_JUMP [46] // JUMP - SPACE
    
    ANIM [string] // Do Not Edit
    ANC [0] // Do Not Edit, Currently Set So: 0 = Idle, 1 = Run, 2 = WalkForward, 3 = WalkBackward, 4 = Strafe Left, 5 = Strafe Right, 6 = Shoot
    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=1000;
    AnimateHold(IDLEANIM);
    ANIM=StringCopy(IDLEANIM);
    ANC=0;
    LASTANC=0;
    TM=self.time;
    self.think="RunPlayer";
}]
    
RunPlayer[()
{
	AttachCamera();
    //debug(self.key_pressed);
   
    //self.ideal_yaw=-self.player_yaw;
    //ChangeYaw();
	MatchPlayerAngles();
    PlayerRender(false);
    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))
    {
		if(IsKeyDown(K_RUN))
		{
        //left shift key - toggle run
		PlayerToPosition(0,0,0,true,false);
        ANIM=StringCopy(RUNANIM);
		ANC=1;
        SPEED=Integer(PLAYERSPEED)*2;
		}
		else
		{
        //walk
		PlayerToPosition(0,0,0,true,false);
        ANIM=StringCopy(WALKANIM);
        ANC=2;
        SPEED=Integer(PLAYERSPEED);
		}
    }

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

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

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

    if(ANC < 1)
    {
        //no button
        ANIM=StringCopy(IDLEANIM);
        AT=0.5;
    }
    
      
    //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,"");  
}]


}
I don't know how, but it seems somewhere along my coding my pawn picked up some abilities of the player, even though the player is not rendered. For example, it can jump when I press space bar, without me having coded that action. Also, the running works as a toggle, like the player does, however, in this script it is coded to work by holding it down. Strange. I know it's probably some typo or something but any help would be appreciated :)

Edit: So apparently the reason it's doing this is because somewhere I'm breaking the script and making it not load at all, hence I'm actually controlling the player and not the pawn. Hmmm...

Posted: Sat Jan 05, 2008 11:58 am
by Jay
Yes that could be true that you're at some point breaking the script. You can be sure if you change the line Console(false); to Console(true);

When you get a bluish text appear on the left-up corner of the screen, then you know the script has been loaded. If there is no such text in the game, then something is wrong with the script in a way that it is not loaded. (That is called a ReaderScript error) When there is a text, it might give you some clues to the origin of the error. If you're unsure what it means, then you may post the text that is shown.

Posted: Sat Jan 05, 2008 12:01 pm
by Juryiel
I'm certain that it's not loading because I found the nifty RealityFactory.log file and it says:

Reader Script Error for Pawn1
scripts\juryactionplayer.s:

Going to try the console thing see if I get any more info.

Edit: No blue text of any kind so it's not loading and also not giving me any hints.

Posted: Sat Jan 05, 2008 12:11 pm
by Jay
ANC [0] // Do Not Edit, Currently Set So: 0 = Idle, 1 = Run, 2 = WalkForward, 3 = WalkBackward, 4 = Strafe Left, 5 = Strafe Right, 6 = Shoot
In your text it looks like it's split into two lines. If it is in your script also, then either make it one line or comment out the second line.

Was it that?

Posted: Sat Jan 05, 2008 12:16 pm
by Juryiel
In fact, it is one line in my script..

However, removing that line DOES fix it.. somehow. Maybe it autowraps? It's not wrapped in RF Script Editor. Or maybe some of the symbols I used mess up the comment? Going to test a few things and find out! But even if I don't I'll just remove it! Thanks!

Posted: Sat Jan 05, 2008 12:32 pm
by Juryiel
It's the commas. Apparently having commas in comments is not good. I wonder what other characters break comments? Oh well, it's good to know, maybe it should be looked into though, I just spent the past 2 hours trying to figure that out :) Or at least noted in some prominent place

Posted: Sat Jan 05, 2008 2:45 pm
by Juryiel
Is it possible to set a character's vertical speed (or at least reset it to zero)? I don't mean turn off gravity, because I still want the character to fall, but I want him to restart accelerating from velocity = 0;

Posted: Sat Jan 05, 2008 4:08 pm
by vrageprogrammer
Disable ALL player animations.

Posted: Sat Jan 05, 2008 7:19 pm
by Jay
Just wondering: How is this going to help?

Posted: Sat Jan 05, 2008 7:33 pm
by vrageprogrammer
Juriel is using a pawn player, so disabling default player anims should make things easier..

Posted: Sat Jan 05, 2008 7:52 pm
by Juryiel
vrage,

can you please ellaborate on what disabling animations would do in my goal to control my pawn's vertical speed (or set it to 0)? :) I'm confused

Posted: Sun Jan 06, 2008 1:20 am
by Juryiel
Still no ideas eh? :) Well I'm working on an action adventure type script that I will release to anyone once I'm done. I think it will help a lot of people who aren't trying to make FPS. But my scripting abilities are simple so it won't be anything too fancy!

Posted: Sun Jan 06, 2008 3:57 am
by Juryiel
Couple of more problems. I'm trying to make a levitating scripted player, but when I use the Gravity(false) command, even though my pawn doesn't fall, the default player does (but very slowly) taking my camera with him! I need to have the camera attached to the default player to get the type of controls I want. I can't seem to figure out why. Also, another problem, when facing the camera and jumping towards it (especially when a wall is close behind the camera) it crashes RF. The code is below, I'll keep working on these problems and others mentioend above, but any help is appreciated :)

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 [200] // 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 [Idle] // Idle AnimationSpeed
    SHOOTANIM [Shoot3] // Shoot anim
    WALKANIM [Walk] // Walk anim
    BACKANIM [Walk] // walk back anim
	RUNANIM [Run] //Run anim
	JUMPANIM [Jump] //Jump anim
    STRAFELEFT [recon_strafe_left] // Strafe left anim
    STRAFERIGHT [recon_strafe_right] // Strafe right anim
    INTERANIM [Hit] // Pawn interact anim
    DEATHANIM [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
	K_JUMP [46] // JUMP - SPACE
	K_LEV [34] //LEVITATE KEY - L
    
    ANIM [string] // Do Not Edit
    ANC [0] // Do Not Edit 
 	// ANC Currently Set So 0 is Idle
	// 1 is Run 2 is WalkForward 
 	// 3 is WalkBackward 4 is Strafe Left
	// 5 is Strafe Right 6 is Shoot
	// 7 is Falling 8 is Levitating
	
    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
	
	WALKRUNANIM [string] //Do Not Edit
	WALKRUNSPEED [0] //Do Not Edit
	WALKRUNANC [0] //Do Not Edit
	JUMPMODE [0] //Do Not Edit
	SPACEPRESS [0] //Do Not Edit
	STORE_Z [0] //Do Not Edit
	gravityOn [1] //Do Not Edit - Keeps track if gravity is on or off
    
Spawn[()
{
    Console(false);
    BoxWidth(BOX);
    SetGroup(GROUP);
    AttributeOrder(HEALTHATTRIB,HEALTHAMOUNT,"Die");
    //SetWeapon(WEAPONMODEL);
    LowLevel("Setup");
}]
    
Setup[()
{
    self.yaw_speed=1000;
    AnimateHold(IDLEANIM);
    ANIM=StringCopy(IDLEANIM);
	AnimationSpeed(2); 
    ANC=0;
    LASTANC=0;
	SPACEPRESS=0; //Used to separate button presses for jumps
	JUMPMODE = 0; //Default - Not currently jumping
	gravityOn = 1;  //Default - Gravity is on to start
    TM=self.time;
    self.think="RunPlayer";
}]
    
RunPlayer[()
{
    //debug(self.key_pressed);
	
	PlayerToPosition(0,0,0,false,false);
    //PlayerRender(false);
	
    DIR=0; // Default straight
    SPEED=0; //Default - no motion
    AT=0.1; //Default
    ANC=0; //Default
 
	
	WALKRUNSPEED = Integer(PLAYERSPEED); //Default for Walking
	WALKRUNANIM = StringCopy(WALKANIM);  //Default for Walking
	WALKRUNANC = 2; //Default for Walking
    
    //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_LEV))
	{
		Gravity(false);
		gravityOn=0;
		flymove(ConvertDegrees(90),0,(75*sin(5*self.time)));
		//ANC = 8;
	}
	else
	{
		Gravity(true);
		gravityOn=1;
	}
	
	//Walk & Run Code
	if(IsKeyDown(K_RUN))
	{
		WALKRUNSPEED = Integer(PLAYERSPEED)*2;
		WALKRUNANIM = StringCopy(RUNANIM);
		WALKRUNANC = 1;
	}
    
	
	if((IsKeyDown(K_FOR)=true) and (IsKeyDown(K_LEFT)=false) and (IsKeyDown(K_RIGHT)=false) and (IsKeyDown(K_BAK)=false))
    {
		DIR = self.player_yaw + ConvertDegrees(180);
		self.ideal_yaw = DIR;
		ChangeYaw();
        ANIM=StringCopy(WALKRUNANIM);
		ANC=Integer(WALKRUNANC);
        SPEED=Integer(WALKRUNSPEED);
    }

    if((IsKeyDown(K_FOR)=false) and (IsKeyDown(K_LEFT)=false) and (IsKeyDown(K_RIGHT)=false) and (IsKeyDown(K_BAK)=true))
    {
		DIR = self.player_yaw;
		self.ideal_yaw = DIR;
		ChangeYaw();
        ANIM=StringCopy(WALKRUNANIM);
		ANC=Integer(WALKRUNANC);
        SPEED=Integer(WALKRUNSPEED);

    }

    if((IsKeyDown(K_FOR)=false) and (IsKeyDown(K_LEFT)=true) and (IsKeyDown(K_RIGHT)=false) and (IsKeyDown(K_BAK)=false))
    {
		DIR = self.player_yaw + ConvertDegrees(-90);
		self.ideal_yaw = DIR;
		ChangeYaw();
        ANIM=StringCopy(WALKRUNANIM);
		ANC=Integer(WALKRUNANC);
        SPEED=Integer(WALKRUNSPEED);
    }

    if((IsKeyDown(K_FOR)=false) and (IsKeyDown(K_LEFT)=false) and (IsKeyDown(K_RIGHT)=true) and (IsKeyDown(K_BAK)=false))
    {
		DIR = self.player_yaw + ConvertDegrees(90);
		self.ideal_yaw = DIR;
		ChangeYaw();
        ANIM=StringCopy(WALKRUNANIM);
		ANC=Integer(WALKRUNANC);
        SPEED=Integer(WALKRUNSPEED);

    }

	 if((IsKeyDown(K_FOR)=true) and (IsKeyDown(K_LEFT)=false) and (IsKeyDown(K_RIGHT)=true) and (IsKeyDown(K_BAK)=false))
    {
		DIR = self.player_yaw + ConvertDegrees(135);
		self.ideal_yaw = DIR;
		ChangeYaw();
        ANIM=StringCopy(WALKRUNANIM);
		ANC=Integer(WALKRUNANC);
        SPEED=Integer(WALKRUNSPEED);

    }
	
	 if((IsKeyDown(K_FOR)=true) and (IsKeyDown(K_LEFT)=true) and (IsKeyDown(K_RIGHT)=false) and (IsKeyDown(K_BAK)=false))
    {
		DIR = self.player_yaw + ConvertDegrees(-135);
		self.ideal_yaw = DIR;
		ChangeYaw();
        ANIM=StringCopy(WALKRUNANIM);
		ANC=Integer(WALKRUNANC);
        SPEED=Integer(WALKRUNSPEED);

    }
	
	 if((IsKeyDown(K_FOR)=false) and (IsKeyDown(K_LEFT)=false) and (IsKeyDown(K_RIGHT)=true) and (IsKeyDown(K_BAK)=true))
    {
		DIR = self.player_yaw + ConvertDegrees(45);
		self.ideal_yaw = DIR;
		ChangeYaw();
        ANIM=StringCopy(WALKRUNANIM);
		ANC=Integer(WALKRUNANC);
        SPEED=Integer(WALKRUNSPEED);

    }
	
	 if((IsKeyDown(K_FOR)=false) and (IsKeyDown(K_LEFT)=true) and (IsKeyDown(K_RIGHT)=false) and (IsKeyDown(K_BAK)=true))
    {
		DIR = self.player_yaw + ConvertDegrees(-45);
		self.ideal_yaw = DIR;
		ChangeYaw();
        ANIM=StringCopy(WALKRUNANIM);
		ANC=Integer(WALKRUNANC);
        SPEED=Integer(WALKRUNSPEED);

    }
	
	
	//handle jump - Double Jump!
	//Are we falling? If not we should be on the ground so we should we are not jumping!
	if((self.IsFalling=true) and (gravityOn=1))
	{
		ANC=7; //Set Jump/Fall animation
	}
	else
	{
		JUMPMODE=0;
	}
	
	if((IsKeyDown(K_JUMP)=false) and (SPACEPRESS=1)){SPACEPRESS=0;} //Makes sure you have to release and re-press the jump button to jump again.
	if((IsKeyDown(K_JUMP)=true) and (SPACEPRESS=0) and (JUMPMODE < 2) and (gravityOn=1)) //Have we performed less than 2 jumps? If so run the jump function.
	{
		SPACEPRESS=1;
		HighLevel("JumpFunc");
		ANC=7; //Set Jump/Fall animation
		return 0;
	}
	
	if(ANC=7)
	{	
		//While jumping, play this anim, even if doing other actions like moving forward.
		ANIM=StringCopy(JUMPANIM);
	}
    if(ANC < 1)
    {
        //no button
        ANIM=StringCopy(IDLEANIM);
        AT=0.5;
    }
    
      
    //handle animations
    if(Integer(LASTANC) != Integer(ANC))
    {
        AnimateBlend(ANIM,AT);
    }
    LASTANC=Integer(ANC);
    if(self.animate_at_end)
    {
        AnimateHold(ANIM);
    }
    
    //handle motions
    walkmove(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,"");  
}]

JumpFunc[()
{
	if((self.IsFalling)) //If we're falling do the code below to perform the second jump and set JUMPMODE to 2 to indicate we've performed 2 jumps
	{
		JUMPMODE = 2;
		Jump(JUMPANIM,200,true,""); 
	}
	else //If we haven't performed one jump yet do the code below to perform the first jump and set JUMPMODE to 1 to indicate we've performed 1 jump
	{
	JUMPMODE=1;
	Jump(JUMPANIM,150,true,""); 
	}
	LowLevel("RunPlayer");
	return 0;
}]

}