animations and RPG-style scripting

Topics regarding Scripting with Reality Factory
Post Reply
kiebor
Posts: 7
Joined: Fri Aug 07, 2009 4:28 pm
Location: South Afrika

animations and RPG-style scripting

Post by kiebor »

Hey, My :oops: :oops: name is Damien and I'm new to this thing and to here.

I am in dire need of assistence!!

I have created a new playable character to fit into my 3d action-rpg, having removed all shooting anims and kept the stock Punch.mot and Slash.mot (1 and 2) anims. However, I'm having great difficulty altering the Playersetup.ini to incorperate these as attacks. Cn anyone, please, please, give me an example of how to script that in? Punch for unarmed and slash for a sword weapon?

Also, I'm shaking my head constantly, trying ways to configure the player.ini in order to work with XP based levelling systems. Example scripts? anyone. This is truely driving me nuts.

I have modded regularly before using cripples versions of the gamebryo engine, but this is so much different in lnguage and style that I find myself struggling.

Thank you to all in advance, and I'll see just how good I can get at this. Perhaps in future I can return the favor.

Cheers!

Damien. :oops: :shock: :shock:
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: animations and RPG-style scripting

Post by Jay »

http://www.realityfactory.info/forum/vi ... f=8&t=2658

That's a tutorial that covers scripted players (that's a Pawn entity that acts as your player, you should be able to add a Pawn to a level before reading this), and RPG scripting.
In the long run, you wouldn't be able to use the built-in player as it's really limited in what you can do.

Btw, there is a reason why topics like the one i pointed you to are stickied.
Everyone can see the difficult, but only the wise can see the simple.
-----
kiebor
Posts: 7
Joined: Fri Aug 07, 2009 4:28 pm
Location: South Afrika

Re: animations and RPG-style scripting

Post by kiebor »

The link in that thread is broken...
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: animations and RPG-style scripting

Post by Jay »

kk wil fix it as soon as possible. It seems that the file is on my other comp.
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
darksmaster923
Posts: 1857
Joined: Wed Jan 03, 2007 10:32 pm
Location: Huntington Beach, California, USA

Re: animations and RPG-style scripting

Post by darksmaster923 »

Pretty sure you don't need a scripted player, unless you are planning to do a turn based battle system.

It is definitely preferable though, its much more flexible
Herp derp.
kiebor
Posts: 7
Joined: Fri Aug 07, 2009 4:28 pm
Location: South Afrika

Re: animations and RPG-style scripting

Post by kiebor »

I've scripted my pawn, set it up as directed in the tutorial mentioned earlier in this thread. As described in the Pawn Tutorial, I have also written the scripted player into the pawn.ini. I set up the properties of the in-game entity as follows:

Pawn Type 'Necmael'
Script 'Necmael.s'
spawn order 'Spawn'

and left the othe fields blank. Also the Pawn.ini section, headered as [Necmael] features the same as the other pawns I've used as NPCs and who funtion properly. However, when I play-test the level...the scripted player is visible as an NPC (no interaction)...so, the script doesn't work. Any clues? Perhaps I need to change how I reference and/or the pawn.ini needs updating. Really frustrating, was up until 5 am pulling my hair out.

thank you in advance,

Damien
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: animations and RPG-style scripting

Post by Jay »

As a reference script, you can use the genericplayer.s in the sample directory. (as script name you would type "sample\genericplayer.s") The starting order is Spawn, i think.

You can use it as a base for your scripted player and move from there. You can also study it so that you work out how a scripted player works. The cool thing about it is that you have total control over it - and you can do lots of thinghs you couldn't do with the built-in player.
Everyone can see the difficult, but only the wise can see the simple.
-----
kiebor
Posts: 7
Joined: Fri Aug 07, 2009 4:28 pm
Location: South Afrika

Re: animations and RPG-style scripting

Post by kiebor »

This is what I did.

I uninstalled RF, saving my modified and custom files to a seperate folder. Re-installed RF as to reset it to its default. i then built a basic one cube level and inserted the playersetup and player entities. I then modified the pawn.ini to encorporate an extra pawn ( [genericplayer] ) I set this pawn up in exactly the same way as shown in the pawn tutorial, which is as good as the same as every other already existing pawn (as far as I can see). I added a pawn entity to the game-world, named the pawn as in the .ini 'genericplayer', rferenced script 'sample/genericplayer.s/, and set the spawnorder to 'spawn'. I then play-tested. Guess what? The scripted player is now a static pawn that I can see with the stock player. So, basically the stock 'generisplayer' script doesn't seem to work either, even with all my modification removed from RF. I know I can learn from this script and do with it what I can once i see how it works, but how in seventh hell can I do that if I can't get the basic version of the damn thing to initiate? Please, somebody help me. Again, last night 5am was calling and there might even have been a few tears...

Damien
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: animations and RPG-style scripting

Post by Jay »

What does the Realityfactory.log say? Also, did you write 'Spawn' or 'spawn'? The scripting language is case-sensitive. (I think 'Spawn' is the right name). I hope this works for you, don't give up!
Everyone can see the difficult, but only the wise can see the simple.
-----
kiebor
Posts: 7
Joined: Fri Aug 07, 2009 4:28 pm
Location: South Afrika

Re: animations and RPG-style scripting

Post by kiebor »

My God, Jay!

Your signature line has never been more true, I do think.
All that stress and worry because of a capital letter(!).

Thank you so much.

But there are still things I need help with. After, finally, getting the 'genericplayer.s' scrpt to work I noticed that my character wasn't animated whilst moving. Nor could he jump. I reviewed the script and changed the noted animations to the correct ones. Then I had when play-testing, a moveable, animated character that still could no jump and run. Also, the weapon I make for him was floating in an odd place. I think its because the original playe is invisible as he should be but is still holding the weapon that should be with the scripted player. Nevermind, I thought I can sort it good later. So I made some changes to the script regarding derived stats from the player attributes. I did as the ones in the tutorial, but ith my own stamp on them. Odd things came from that, a static scripted player and no original player, I make more change to get it right.... I have had ll kind of things on my screen, from seeing the original player but with camera view fixed to the pawn....

anyway, below is a script, my one I am using. Could anyone be so kind as to tell me what is wrong with it? If I revert the lines asocietated with health and endurance to original. I have the situation I describe with moving origina player - fixed viewpoint pawn. chopping and changing confues me now. Please find it here:
{

WEAPONMODEL [TC_Longsword] // Weapon held by pawn
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 [Idle] // Idle AnimationSpeed
MAGIC_ANIM [Shoot2]
MELEE_ANIM_A [Slash2] // Shoot anim
MELEE_ANIM_B [Punch]
WALKANIM [Walk] // Walk anim
BACKANIM [WalkBack] // Walk back anim
STRAFELEFT [StrafeLeft] // Strafe left anim
STRAFERIGHT [StrafeRight] // Strafe right anim
INTERANIM [Punch] // Pawn interact anim
DEATHANIM [Die] // Death Anim
ROOTBONE [Bip01] // Pawn root bone
WEAPONHAND [Bip01 R Hand] // Pawn weapon bone

K_MELEE_A [73] // INTERACT KEY - RIGHT MOUSE
K_MELEE_B [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

TARGET [FALSE] //the current target
MELEE_DAMAGE [10] //base damage you do with melee weapon
MELEE_DIST [128] //maximum distance needed for melee attack
MELEE_RATE [2.0] //time between melee attacks
MELEE_DAMAGEATTRIB [health] //attribute that is damaged by melee attack


Spawn[()
{
Console(false);
BoxWidth(BOX);
SetGroup(GROUP);
AddAttribute(HEALTHATTRIB, 0, GetAttribute(“endurance”,”Player”)*5);
SetAttribute(HEALTHATTRIB, GetAttribute(“endurance”,”Player”)*5);
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(GetAttribute(HEALTHATTRIB) < 1)
{
HighLevel("Die");
return 0;
}

// handle controls
if(IsKeyDown(K_MELEE_A)
{
//fire/attack
if(ANC < 1)
{
//only go to shoot anim if at idle
ANIM=StringCopy(MELEE_ANIM));
ANC=1;
}
// Check fire rate
if(self.time > TM+MELEE_RATE)
{
TM=self.time;
TARGET= TraceToActor("BIP01FOOTSTEPS",0,1,MELEE_DIST);
If(TARGET=”FALSE”)
{
//do nothing
;
}
else
{
DamageEntity(MELEE_DAMAGE, MELEE_DAMAGEATTRIB*GetAttribute(“Strenght”,”Player”)/20, TARGET);
}
TM=self.time;
}
}

if(IsKeyDown(K_MELEE_B)
{
//fire/attack
if(ANC < 1)
{
//only go to shoot anim if at idle
ANIM=StringCopy(MELEE_ANIM));
ANC=1;
}
// Check fire rate
if(self.time > TM+MELEE_RATE)
{
TM=self.time;
TARGET= TraceToActor("BIP01FOOTSTEPS",0,1,MELEE_DIST);
If(TARGET=”FALSE”)
{
//do nothing
;
}
else
{
DamageEntity(MELEE_DAMAGE, MELEE_DAMAGEATTRIB*GetAttribute(“Strenght”,”Player”)/20, TARGET);
}
TM=self.time;
}
}

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(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*GetAttribute(“Speed”,”Player”)/20);
}]

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, "");
}]
}
Also I eventually want 3 melee anims and 1 magic casting anims assigned to 4 attack buttons on the keyboard, where can I find out which buttons correspond with which number codes?

Thank you again,

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

Re: animations and RPG-style scripting

Post by Juutis »

There's quite a lot of syntax errors in the script. Misplaced brackets, spelling errors ('If' instead of 'if') and stuff like that. Use Console(true); in the Spawn order to turn on the debug info for the pawn. It lets you know if there are any errors in the script. However, the biggest problem is the strange quotation marks you're using:
AddAttribute(HEALTHATTRIB, 0, GetAttribute(endurance,Player)*5);
You should only use the " " ones.

Also, you're missing the declaration for the MELEE_ANIM variable.
Also I eventually want 3 melee anims and 1 magic casting anims assigned to 4 attack buttons on the keyboard, where can I find out which buttons correspond with which number codes?
viewtopic.php?f=8&t=282



Here's the script with the syntax errors corrected. At least most of them:

Code: Select all

{

WEAPONMODEL [TC_Longsword] // Weapon held by pawn
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 [Idle] // Idle AnimationSpeed
MAGIC_ANIM [Shoot2]
MELEE_ANIM_A [Slash2] // Shoot anim
MELEE_ANIM_B [Punch]
WALKANIM [Walk] // Walk anim
BACKANIM [WalkBack] // Walk back anim
STRAFELEFT [StrafeLeft] // Strafe left anim
STRAFERIGHT [StrafeRight] // Strafe right anim
INTERANIM [Punch] // Pawn interact anim
DEATHANIM [Die] // Death Anim
ROOTBONE [Bip01] // Pawn root bone
WEAPONHAND [Bip01 R Hand] // Pawn weapon bone

K_MELEE_A [73] // INTERACT KEY - RIGHT MOUSE
K_MELEE_B [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

TARGET [FALSE] //the current target
MELEE_DAMAGE [10] //base damage you do with melee weapon
MELEE_DIST [128] //maximum distance needed for melee attack
MELEE_RATE [2.0] //time between melee attacks
MELEE_DAMAGEATTRIB [health] //attribute that is damaged by melee attack


Spawn[()
{
Console(true);
BoxWidth(BOX);
SetGroup(GROUP);
AddAttribute(HEALTHATTRIB, 0, GetAttribute("endurance","Player")*5);
SetAttribute(HEALTHATTRIB, GetAttribute("endurance","Player")*5);
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[()
{
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(GetAttribute(HEALTHATTRIB) < 1)
{
HighLevel("Die");
return 0;
}

// handle controls
if(IsKeyDown(K_MELEE_A))
{
//fire/attack
if(ANC < 1)
{
//only go to shoot anim if at idle
ANIM=StringCopy(MELEE_ANIM);
ANC=1;
}
// Check fire rate
if(self.time > TM+MELEE_RATE)
{
TM=self.time;
TARGET= TraceToActor("BIP01FOOTSTEPS",0,1,MELEE_DIST);
if(TARGET="FALSE")
{
//do nothing
;
}
else
{
DamageEntity(MELEE_DAMAGE, MELEE_DAMAGEATTRIB*GetAttribute("Strenght","Player")/20, TARGET);
}
TM=self.time;
}
}

if(IsKeyDown(K_MELEE_B))
{
//fire/attack
if(ANC < 1)
{
//only go to shoot anim if at idle
ANIM=StringCopy(MELEE_ANIM);
ANC=1;
}
// Check fire rate
if(self.time > TM+MELEE_RATE)
{
TM=self.time;
TARGET= TraceToActor("BIP01FOOTSTEPS",0,1,MELEE_DIST);
if(TARGET="FALSE")
{
//do nothing
;
}
else
{
DamageEntity(MELEE_DAMAGE, MELEE_DAMAGEATTRIB*GetAttribute("Strenght","Player")/20, TARGET);
}
TM=self.time;
}
}

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(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*GetAttribute("Speed","Player")/20);
}]

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, "");
}]

}
Pain is only psychological.
kiebor
Posts: 7
Joined: Fri Aug 07, 2009 4:28 pm
Location: South Afrika

Re: animations and RPG-style scripting

Post by kiebor »

Thank you.

I must say that people here are considerably more helpful than most modding forums I've been on.

Thanks again.

Maybe it's because I've been writing the scripts in word, not being english in origin and so to use spellscheck for errors, and then copy/pasting into the script editor?

Not something I'll be doing again soon.

Thank you once more...

Damien.
Post Reply