PDA

View Full Version : Is the player crouching?



legacy-TseTse
08-06-2003, 04:20 AM
ok, first of all... im somewhat new to unreal coding, but i also am starting to get the overall framework of it. im doing a simple weapon project of my own, mostly to learn how to code a little and also potentially for a mod down the road...

here's my situation: i want to check to see if the player is crouching, in determining the weapon spread.



event ModeDoFire()
{

local PlayerController PC;

PC = PlayerController(Instigator.Controller);

// 1. CHECK if GUN IS "COOL"
if ( Level.TimeSeconds - LastFireTime > 0.5 )
Spread = Default.Spread;

// 2. CHECK if PLAYER IS CROUCHED

else if ( PC.bIsCrouched == True )
{
Log("checking crouch: PC");
}

// 3. ELSE, WIDEn SPREAD A LOT

else
{
Spread = FMin(Spread+0.02,0.12);
}

LastFireTime = Level.TimeSeconds;
Super.ModeDoFire();
}

yes, i know that code doesnt work :D

i was trying to tap into the variable/state by checking the bIsCrouched, but it yells at me ("error, Cast from Pawn to PlayerCOntroller will always fail" is the wotgreal/ucc message).

how do i do this?

any/all tips would be greatly appreciated. normally, id look to the base code for a working example of the kind of thing i want, but i just dont see one.

legacy-TheSquirrelKing
08-06-2003, 12:45 PM
It might help to know what line the compiler is pointing out as containing the error...

legacy-FireCrack
08-06-2003, 05:56 PM
bIsCrouched is a property of pawn so instead of 'local PlayerControler PC;' you's wand somthing more like 'local Pawn P' i belive 'P = Pawn(instigator);' will work and then you can have 'if (p.bIsCrouched = True)'

legacy-TseTse
08-08-2003, 11:22 AM
Originally posted by FireCrack
bIsCrouched is a property of pawn so instead of 'local PlayerControler PC;' you's wand somthing more like 'local Pawn P' i belive 'P = Pawn(instigator);' will work and then you can have 'if (p.bIsCrouched = True)'

rgr,. i went ahead and tried that syntax...



event ModeDoFire()
{
local Pawn P;
P = Pawn(instigator);

// 1. CHECK if GUN IS "COOL"

if ( Level.TimeSeconds - LastFireTime > 0.5 )
Spread = Default.Spread;

// 2. CHECK if PLAYER IS CROUCHED

else if (p.bIsCrouched = True)
{
Log("checking crouch: PC");
}

// 3. ELSE, WIDEn SPREAD A LOT

else
{
Spread = FMin(Spread+0.02,0.12);
}

LastFireTime = Level.TimeSeconds;
Super.ModeDoFire();
}


the error was: "Cast from 'pawn' to 'Pawn' is unneccessary."

:bulb:

legacy-luciano.bargman
08-08-2003, 12:06 PM
Have you read the error message? :p

Instigator is already a pawn. As you are using WOTGreal, you can hold CTRL, point in the word 'instigator' and wait until it gets underlined. When this happens, click on it. You will go to the declaration of the variable (this works for fnctions too). THere you will see something like
var Pawn Instigator;

What means that Instigator is of Pawn class. So, you dont need to typecast Instigator to Pawn, as its already one. Generally, you use typecasting to access variables in a child class.

You should read something about Object Oriented Programming, it will help a lot. The Unreal Wiki (www.unrealwiki.com) have pages about this 2 subjects, OOP and typecasting.

Good luck ;)

legacy-TseTse
08-08-2003, 12:41 PM
Originally posted by luciano.bargman
Have you read the error message? :p

Instigator is already a pawn. As you are using WOTGreal, you can hold CTRL, point in the word 'instigator' and wait until it gets underlined. When this happens, click on it. You will go to the declaration of the variable (this works for fnctions too). THere you will see something like
var Pawn Instigator;

What means that Instigator is of Pawn class. So, you dont need to typecast Instigator to Pawn, as its already one. Generally, you use typecasting to access variables in a child class.

You should read something about Object Oriented Programming, it will help a lot. The Unreal Wiki (www.unrealwiki.com) have pages about this 2 subjects, OOP and typecasting.

Good luck ;)

ya, i understand this in concept, just totally new at unreal syntax... and trying anything people suggest.

:D

I do admit not having much clue about Instigator specifically, although the "controller" rolei think i understand. I'll try some variations. this little excercise is helping me a lot. :)

*pokes at code some more*

PS. i just tried this:



else if ( P.bIsCrouched = true )
{
Log("checking crouch: PC");
}


and im getting an error about a missing ")"

P = instigator;

legacy-segall
08-08-2003, 02:18 PM
else if ( P.bIsCrouched = true )

should be

else if ( P.bIsCrouched == true )

legacy-TseTse
08-09-2003, 01:43 PM
ahahaha, thanks so much.

it worked.

*hides back in his newbie coding cave*

legacy-Melaneus
08-11-2003, 02:21 AM
You can also shorten it:
else if ( P.bIsCrouched )

You don't have to ask if a boolean variable == true.

you can use
if (!boolean)
instead of
if (boolean == false)
too.