confusing scripts

Topics regarding Scripting with Reality Factory
Post Reply
evertalis
Posts: 4
Joined: Mon Mar 29, 2010 2:37 am

confusing scripts

Post by evertalis »

{
FIREAMMO[pistolbullet]//Projectilefiredbypawn
FIREEFFECT[Electric]//muzzleflasheffect
WEAPONMODEL[Laser]//Weaponheldbypawn
FIRERATE[0.1]//Weaponfiringrate
GROUP[player]//PawnGroup-mustbetargettedbyenemies
PLAYERSPEED[96]//WalkSpeed
HEALTHATTRIB[Health]//healthattributegiventopawn
HEALTHAMOUNT[500]//amountofhealthgiventopawn
DAMAGEATTRIB[Health]//Atributedamagedbypawn
BOX[24]//Boxwidth

IDLEANIM[Idle]//IdleAnimationSpeed
WALKANIM[Walk]//Walkanim
BACKANIM[WalkBack]//Walkbackanim
STRAFELEFT[StrafeLeft]//Strafeleftanim
STRAFERIGHT[StrafeRight]//Straferightanim
INTERANIM//Pawninteractanim
DEATHANIM[Die]//DeathAnim
ROOTBONE[Bip01]//Pawnrootbone
WEAPONHAND[Bip01LHand]//Pawnweaponbone

K_INTER[73]//INTERACTKEY-RIGHTMOUSE
K_FIRE[72]//FIREKEY-LEFTMOUSE
K_FOR[15]//FORWARD-W
K_BAK[27]//BACK-S
K_LEFT[26]//STRAFELEFT-A
K_RIGHT[28]//STRAFERIGHT-D
K_RUN[36]//RUN-LEFTSHIFTKEY

ANIM[string]//DoNotEdit
ANC[0]//DoNotEdit
LASTANC[0]//DoNotEdit
DIR[0]//DoNotEdit
AT[0.5]//DoNotEdit
INTER[string]//DoNotEdit
TM[0]//DoNotEdit
SPEED[0]//DoNotEdit

TARGET[FALSE]//thecurrenttarget
MELEE_DAMAGE[10]//basedamageyoudowithmeleeweapon
MELEE_DIST[128]//maximumdistanceneededformeleeattack
MELEE_ANIM[Slash1]//meleeattackanimation
MELEE_RATE[2.0]//timebetweenmeleeattacks
MELEE_DAMAGEATTRIB[Health]//attributethatisdamagedbymeleeattack

LEVELUP_BACKGROUND_X[128]//thehalfof(screensizeX-imagesizeX)
LEVELUP_BACKGROUND_Y[128]//thehalfof(screensizeY-imagesizeY)
LEVELUP_PLUSSES_X[192]//LEVELUP_BACKGROUND+64
LEVELUP_PLUSSES_Y[256]//LEVELUP_BACKGROUND+128
LEVELUP_HEADLINE[Level-Up]
LEVELUP_HEADLINE_X[48]
LEVELUP_HEADLINE_Y[48]
LEVELUP_TEXTS_X[160]
LEVELUP_TEXTS_Y[160]

MOUSEX[0]
MOSUEY[0]
MOUSE_TRANSX[0]
MOUSE_TRANSY[0]
MOUSE_LOCATION[Nowhere]

STATS_RAISEPERLEVEL[5]//numberofstatpointsthatcanberaisedeachlevel
STATS_RAISED[0]//numberofstatpointsraisedalreadyatthislevel.//Setbackto0wheneveralevelwasreached


Spawn[()
{
Console(true);
BoxWidth(BOX);
SetGroup(GROUP);
AddAttribute(HEALTHATTRIB,0,GetAttribute("Stamina","Player")*5);
SetAttribute(HEALTHATTRIB,GetAttribute("Stamina","Player")*5);
//SetWeapon(WEAPONMODEL);
LowLevel("SetupL");
}]

SetupL[()
{
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;//Defaultstraight
SPEED=0;//Default-nomotion
AT=0.1;//Default
ANC=0;//Default
AnimationSpeed(1);//Default

//handlehealthstatus
if(GetAttribute(HEALTHATTRIB)<1)
{
HighLevel("Die");
return0;
}


//handlecontrols
if(IsKeyDown(K_INTER))
{
//strike/interact
AnimateBlend(INTERANIM,0.25);
self.think="Interact";
return0;
}

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))
{
//strafeleft
ANIM=StringCopy(STRAFELEFT);
//makestrafetransitionsmoother
AT=0.5;
ANC=4;
DIR=ConvertDegrees(90);
SPEED=Integer(PLAYERSPEED);
}

if(IsKeyDown(K_RIGHT))
{
//straferight
ANIM=StringCopy(STRAFERIGHT);
//makestrafetransitionsmoother
AT=0.5;
ANC=5;
DIR=ConvertDegrees(270);
SPEED=Integer(PLAYERSPEED);
}

if(IsKeyDown(K_FIRE))
{
//fire/attack
if(ANC<1)
{
//onlygotoshootanimifatidle
ANIM=StringCopy(MELEE_ANIM));
ANC=1;
}
//Checkfirerate
if(self.time>TM+MELEE_RATE)
{
TM=self.time;
TARGET=TraceToActor("BIP01FOOTSTEPS",0,1,MELEE_DIST);
If(TARGET="FALSE")
{
//donothing
;
}
else
{
DamageEntity(MELEE_DAMAGE,MELEE_DAMAGEATTRIB*GetAttribute("Strength","Player")/20,TARGET);
}
TM=self.time;
}
}


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

if(IsKeyDown(K_RUN))
{
//leftshiftkey-togglerun
AnimationSpeed(1.5);
SPEED=SPEED+(SPEED/2);
}

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

//handlemotions
walkmove(self.current_yaw+DIR,SPEED*GetAttribute("Speed","Player")/20);

if(GetAttribute("exp","Player")>(GetAttribute("nextexp","Player")-1))
{
ModifyAttribute("exp",GetAttribute("nextexp","Player")*(-1),"Player");
ModifyAttribute("nextexp",1000,"Player");
ModifyAttribute("level",1,"Player");
self.think="LevelUp";
}

}]

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

Die[()
{
AnimateStop(DEATHANIM,0,"");
}]

DrawLevelUpScreen[()
{
DrawFlipBookImage("Levelup",0,LEVELUP_BACKGROUND_X,
LEVELUP_BACKGROUND_Y,255,255,255,255,1.0);//0=background
DrawFlipBookImage("Levelup",1,LEVELUP_PLUSSES_X,
LEVELUP_PLUSSES_Y,255,255,255,255,1.0);//1=Plus
DrawFlipBookImage("Levelup",1,LEVELUP_PLUSSES_X,
LEVELUP_PLUSSES_Y+64,255,255,255,255,1.0);//1=Plus
DrawFlipBookImage("Levelup",1,LEVELUP_PLUSSES_X,
LEVELUP_PLUSSES_Y+128,255,255,255,255,1.0);//1=Plus
DrawFlipBookImage("Levelup",1,LEVELUP_PLUSSES_X,
LEVELUP_PLUSSES_Y+192,255,255,255,255,1.0);//1=Plus
//drawheadlineandnameofthestats
DrawText(LEVELUP_HEADLINE,LEVELUP_HEADLINE_X,
LEVELUP_HEADLINE_Y,255,10,255,255,255);
DrawText("Strength",LEVELUP_TEXTS_X,LEVELUP_TEXTS_Y,255,10,
255,255,255);
DrawText("Stamina",LEVELUP_TEXTS_X,LEVELUP_TEXTS_Y+64,255,
10,255,255,255);
DrawText("Speed",LEVELUP_TEXTS_X,LEVELUP_TEXTS_Y+128,255,
10,255,255,255);
//drawthestat-values
DrawText(GetAttribute("Strength","Player"),LEVELUP_TEXTS_X+256,
LEVELUP_TEXTS_Y,255,10,255,255,255);
DrawText(GetAttribute("Stamina","Player"),LEVELUP_TEXTS_X+256,
LEVELUP_TEXTS_Y+64,255,10,255,255,255);
DrawText(GetAttribute("Speed","Player"),LEVELUP_TEXTS_X+256,
LEVELUP_TEXTS_Y+128,255,10,255,255,255);
}]

TranslateMouseCoordsLevelUp[()
{
MOUSEX=GetMousePosX();
MOUSEY=GetMousePosY();
MOUSE_TRANSX=StringCopy(MOUSEX)-StringCopy(LEVELUP_BACKGROUND_X);
MOUSE_TRANSY=StringCopy(MOUSEY)-StringCopy(LEVELUP_BACKGROUND_Y);
MOUSE_LOCATION="Nowhere";
if(MOUSE_TRANSX<0)
{
return0;
}
if(MOUSE_TRANSY<0)
{
return0;
}
if(MOUSE_TRANSX>768)
{
return0;
}
if(MOUSE_TRANSY>512)
{
return0;
}
if(MOUSE_TRANSX>63andMOUSE_TRANSX<129)
{
if(MOUSE_TRANSY>127andMOUSE_TRANSY<385)
{
if(MOUSE_TRANSY<193)
{
MOUSE_LOCATION="LevelUp_Strength";
return1;
}
if(MOUSE_TRANSY>191andMOUSE_TRANSY<257)
{
MOUSE_LOCATION="LevelUp_Stamina";
return1;
}
if(MOUSE_TRANSY>255andMOUSE_TRANSY<321)
{
MOUSE_LOCATION="LevelUp_Speed";
return1;
}

}
}
MOUSE_LOCATION="LevelUp_Background";
return1;
}]

LevelUp[()
{
if(STATS_RAISED=StringCopy(STATS_RAISEPERLEVEL))
{
STATS_RAISED=0;
self.think="RunPlayer";
return1;
}
DrawLevelUpScreen();
if(self.lbutton_pressed)
{
if(TranslateMouseCoordsLevelUp())
{
switch(MOUSE_LOCATION)
{
case"LevelUp_Strength"
{
ModifyAttribute("Strength",1,"Player");
STATS_RAISED=StringCopy(STATS_RAISED)+1;
}
case"LevelUp_Stamina"
{
ModifyAttribute("Stamina",1,"Player");
STATS_RAISED=StringCopy(STATS_RAISED)+1;
//updatethehealthattribute
SetAttributeValueLimitsHEALTHATTRIB,0,
GetAttribute("Stamina","Player")*5);
SetAttribute(HEALTHATTRIB,GetAttribute("Stamina","Player")*5);
}
case"LevelUp_Speed"
{
ModifyAttribute("Speed",1,"Player");
STATS_RAISED=StringCopy(STATS_RAISED)+1;
}

}
}
}
}]
}



Hiya good people of the reality factory boards. I'm new here, so please be gentle with me if I ask dumb questions - but no kid gloves. Above is a script (slightly editted, but more or less exactly input as described in the rpg tutorial) which for one or other reason won't run!! I have my pawn setup in the editor - spawn order is 'Spawn' - made sure caps and the like were correct - and matched the pawntype to the [] named actor I wanted to use. When I don't put a command in the spawn order, the pawn appears in the game where it should, but with the script activated...it is invisible and not present as the player character. I'd be very grateful if enyone could be so kind as to look at the script as is and let me know where I'm going wrong - or perhaps another idea of what I effed up. Cheers and thanks in advance...

Ever :oops: :mrgreen:
User avatar
zany_001
Posts: 1047
Joined: Fri Mar 02, 2007 8:36 am
Location: Aotearoa

Re: confusing scripts

Post by zany_001 »

First, welcome to the forums!

Second, next time put scripting-related questions in the Scripting area ;D

Third, sorry if this sounds stupid but have you got an actor for the pawn, that isn't invisible?
Once I was sad, and I stopped being sad and was awesome instead.
True story.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: confusing scripts

Post by Juutis »

First off, there's a bug with comments in scripts. For me, removing some of the comments in the start fixed the biggest problem (the pawn not appearing at all).

Secondly, you have some syntax errors in the script. The console reveals them once you get the script running:

Code: Select all

MOSUEY[0] -> MOUSEY[0]
return0; -> return 0;
ANIM=StringCopy(MELEE_ANIM)); -> ANIM=StringCopy(MELEE_ANIM);
If(TARGET="FALSE") -> if(TARGET="FALSE")
But even after fixing these the script doesn't seem to work like it should. I hope you can manage to fix it on your own, since I don't have time to delve deeper into it right now.

Welcome to the forums.
Pain is only psychological.
evertalis
Posts: 4
Joined: Mon Mar 29, 2010 2:37 am

Re: confusing scripts

Post by evertalis »

Thank you both for your rapid responses to my question. I removed the comments, checked, double checked, and checked again for spelling and the like. Guess what? It does do sort of what I wanted...I understand that you can't hold my hand through this and really appreciate your help - I think I can get along with trial and error further, I kind of got lost in a pseudo-blind panic LOL. Sorry about putting this in the wrong place... :oops:

I did have one other query though...the rf world editor has no issues running on windows 7, but the compiled game does (mine does anyway) without setting it to run with admin privilages under xp compatibility. Is it possible to run the end game through a sidebar gadget successfully? Also the gadget thingy-ma-jobbin' is a cool way to revamp RF - an access gadget for the tools eg. I dunno, maybe I'm on the wrong track here, but I'd appreciate a simple interface to access any/all tools individually or simultaneously without the direct need for shortcuts (Microsoft have had 20+ years to give us decent accessability to our files without clogging up taskbars and desktops - maybe this is an amicable solution).

Cheers,
Ever
User avatar
darksmaster923
Posts: 1857
Joined: Wed Jan 03, 2007 10:32 pm
Location: Huntington Beach, California, USA

Re: confusing scripts

Post by darksmaster923 »

evertalis wrote:Thank you both for your rapid responses to my question. I removed the comments, checked, double checked, and checked again for spelling and the like. Guess what? It does do sort of what I wanted...I understand that you can't hold my hand through this and really appreciate your help - I think I can get along with trial and error further, I kind of got lost in a pseudo-blind panic LOL. Sorry about putting this in the wrong place... :oops:

I did have one other query though...the rf world editor has no issues running on windows 7, but the compiled game does (mine does anyway) without setting it to run with admin privilages under xp compatibility. Is it possible to run the end game through a sidebar gadget successfully? Also the gadget thingy-ma-jobbin' is a cool way to revamp RF - an access gadget for the tools eg. I dunno, maybe I'm on the wrong track here, but I'd appreciate a simple interface to access any/all tools individually or simultaneously without the direct need for shortcuts (Microsoft have had 20+ years to give us decent accessability to our files without clogging up taskbars and desktops - maybe this is an amicable solution).

Cheers,
Ever
Possibly RF isn't completely updated for windows 7, it is rather old software, but it's good that it works instead of just crashing.

And welcome to the forums :D
Herp derp.
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: confusing scripts

Post by Jay »

Omg. :lol: It's been 2 and a half years, and now someone tells me they found a bug in the script....

First thinghs first, welcome to the forums. :D

Change PawnRender(false) to PawnRender(true). PawnRender(false) makes it so that the pawn doesn't render. (This can be usefull if you are making a 1st person game)

I hope the script works otherwise, that would be embarassing. :lol:
Everyone can see the difficult, but only the wise can see the simple.
-----
evertalis
Posts: 4
Joined: Mon Mar 29, 2010 2:37 am

Re: confusing scripts

Post by evertalis »

yeah the script does work as it should now. There were a lot of tiny errors in the code when taken directly from the tutorial (mostly inconsistencies in the refrences due to minor spelling mistakes and double brackets where they weren't needed), also, the script has several incomplete lines that I had to guess at to finish off correctly. I fiddled with the pawnrender true/false thing for a while and figured it out. It's funny, when I first got on with this script I was incredibly overwhelmed, but having prior knowledge of python and gs9 makes things a lot easier when you really delve into it. However, I have tried several different command combinations for the use of key combinations, ie. I want 'w' to move my player forward, but if, and only if, 'r' is pressed with 'w' the player runs displaying the run animation -- i can have, no animation, running all the time, or the script failing as my results from what I'm trying...also I can script a jump, but the player hangs in the air. Can I set a tijmer that the jump can last, so that the pawn/player drops after a few secs regardless of whether the jump key is pressed?

Thanks for the warm welcome
Post Reply