Author Topic: varable help  (Read 3064 times)

I'm trying to make a gun that after you fire it a few times it ejects a clip

Code: [Select]
function RegunImage::onMount()
{
$shot = 0;
}

function RegunImage::onFire(%this,%obj,%slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
Parent::onFire(%this,%obj,%slot);
}

function RegunImage::onPreFire(%this)
{
if($shot( = 5.0)
%this.goto(Clipout);
$shot = 0;
)
else
$shot = $shot + 1;
}

and i'm trying to figure out the correct way of doing this:
Code: [Select]
function RegunImage::onPreFire(%this)
{
if($shot( = 5.0)
%this.goto(Clipout);
$shot = 0;
)
else
$shot = $shot + 1;
}
but i keep goofing up at the if(%shot stuff

random fact: i pulled all the function sh1tz outta my head, no copy pastea

Code: [Select]
function RegunImage::onPreFire(%this){
if($shot == 5.0){
%this.goto(Clipout); //Is Clipout a handle of anything?
$shot = 0;
} else
$shot = $shot + 1;
}

i have a clipout state and i want it to go to that state when the values equals what ever
Code: [Select]
stateName[6] = "Clipout";
stateTransitionOnTimeout[6]     = "Ready";
stateTimeoutValue[6] = 1;
stateEjectShell[6]       = true;

edit: well i found some onammo stuff and i need a bit of help with that, it justs go's to the clipout state:
Code: [Select]
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.15;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = weaponSwitchSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "PreFire";
stateAllowImageChange[1]         = true;
stateSequence[1] = "Ready";

stateName[2]                    = "PreFire";
stateTransitionOnTimeout[2]     = "Fire";
stateTimeoutValue[2]            = 0.03;
stateTransitionOnAmmo[2]        = "Clipout";


stateName[3]                    = "Fire";
stateTransitionOnTimeout[3]     = "Smoke";
stateTimeoutValue[3]            = 0.14;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "Fire";
stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;
stateEmitter[3] = RegunFlashEmitter;
stateEmitterTime[3]       = 0.05;
stateEmitterNode[3] = "muzzleNode";
stateSound[3] = gunShot1Sound;


stateName[4] = "Smoke";
stateEmitter[4] = gunSmokeEmitter;
stateEmitterTime[4] = 0.05;
stateEmitterNode[4] = "muzzleNode";
stateTimeoutValue[4]            = 0.01;
stateTransitionOnTimeout[4]     = "Reload";

stateName[5] = "Reload";
stateSequence[5]                = "Reload";
stateTransitionOnTriggerUp[5]     = "Ready";
stateSequence[5] = "Ready";

stateName[6] = "Clipout";
stateTransitionOnTimeout[6]     = "Ready";
stateTimeoutValue[6] = 1;
stateEjectShell[6]       = true;



};

//function RegunImage::onMount()
//{
//$shot = 0;
//}

function RegunImage::onFire(%this,%obj,%slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
Parent::onFire(%this,%obj,%slot);
}

function RegunImage::onPreFire(%obj)
{
if($shot== 5){
//%this.goto(Clipout);
setimageammo(0,true)
$shot = 0;
} else
$shot = $shot + 1;
}

function RegunImage::onClipout(%obj)
{
setimageammo(0,false)
}
« Last Edit: January 28, 2008, 06:09:50 PM by zackin5 »

Why are you using a global variable? That will make it clipout after 5 shots, but each shot by anyone will add onto it.

Player1 fires 3 times
Player2 fires once
Player1 fires once
Clip out for Player1

whoops! i forgot to change the values, um? type? but now that thats fixed i'm still having issues, like i say'd before when i fire it go's right to the clipout state:
Code: [Select]

   // Initial start up state
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.15;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = weaponSwitchSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "PreFire";
stateAllowImageChange[1]         = true;
stateSequence[1] = "Ready";

stateName[2]                    = "PreFire";
stateTransitionOnTimeout[2]     = "Fire";
stateTimeoutValue[2]            = 0.03;
stateTransitionOnNoAmmo[2]        = "Clipout";


stateName[3]                    = "Fire";
stateTransitionOnTimeout[3]     = "Smoke";
stateTimeoutValue[3]            = 0.14;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "Fire";
stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;
stateEmitter[3] = RegunFlashEmitter;
stateEmitterTime[3]       = 0.05;
stateEmitterNode[3] = "muzzleNode";
stateSound[3] = gunShot1Sound;


stateName[4] = "Smoke";
stateEmitter[4] = gunSmokeEmitter;
stateEmitterTime[4] = 0.05;
stateEmitterNode[4] = "muzzleNode";
stateTimeoutValue[4]            = 0.01;
stateTransitionOnTimeout[4]     = "Reload";

stateName[5] = "Reload";
stateSequence[5]                = "Reload";
stateTransitionOnTriggerUp[5]     = "Ready";
stateSequence[5] = "Ready";

stateName[6] = "Clipout";
stateTransitionOnTimeout[6]     = "Ready";
stateTimeoutValue[6] = 1;
stateEjectShell[6]       = true;



};

function RegunImage::onMount()
{
%shot== 0;
}

function RegunImage::onFire(%this,%obj,%slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
Parent::onFire(%this,%obj,%slot);
}

function RegunImage::onPreFire(%obj)
{
if(%shot== 5){
//%this.goto(Clipout);
setimageammo(0,true)
%shot== 0;
} else
%shot== $shot + 1;
}

function RegunImage::onClipout(%obj)
{
setimageammo(0,false)
}

Code: [Select]
function RegunImage::onPreFire(%obj)
{
if(%shot== 5){
//%this.goto(Clipout);
setimageammo(0,true)
%shot= 0;
} else
%shot= %shot + 1;
}
only use == in if()s, while()s, ect.
also you forgot one of the $ to %.

%shot would do nothing, it's a local variable.

setImageAmmo is not a function, it's a method I believe.

meh.. now its sorta acting funny every time i re-exec it a second time it gives me a buffer overload crash message thing, also now it never does goto clipout. also randy, what exactly do you mean by all that? I'm still kinda new to this scripting stuff..
Code: [Select]
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.15;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = weaponSwitchSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "PreFire";
stateAllowImageChange[1]         = true;
stateSequence[1] = "Ready";

stateName[2]                    = "PreFire";
stateTransitionOnTimeout[2]     = "Fire";
stateTimeoutValue[2]            = 0.03;
stateTransitionOnNoAmmo[2]        = "Clipout";


stateName[3]                    = "Fire";
stateTransitionOnTimeout[3]     = "Smoke";
stateTimeoutValue[3]            = 0.14;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "Fire";
stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;
stateEmitter[3] = RegunFlashEmitter;
stateEmitterTime[3]       = 0.05;
stateEmitterNode[3] = "muzzleNode";
stateSound[3] = gunShot1Sound;


stateName[4] = "Smoke";
stateEmitter[4] = gunSmokeEmitter;
stateEmitterTime[4] = 0.05;
stateEmitterNode[4] = "muzzleNode";
stateTimeoutValue[4]            = 0.01;
stateTransitionOnTimeout[4]     = "Reload";

stateName[5] = "Reload";
stateSequence[5]                = "Reload";
stateTransitionOnTriggerUp[5]     = "Ready";
stateSequence[5] = "Ready";

stateName[6] = "Clipout";
stateTransitionOnTimeout[6]     = "Ready";
stateTimeoutValue[6] = 1;
stateEjectShell[6]       = true;



};

function RegunImage::onMount()
{
//%shot== 0;
}

//function RegunImage::onFire(%this,%obj,%slot)
//{
// if(%obj.getDamagePercent() < 1.0)
// %obj.playThread(2, shiftAway);
// Parent::onFire(%this,%obj,%slot);
//}

function RegunImage::onFire(%obj)
{
if(%shot== 5){
//%this.goto(Clipout);
setimageammo(0,true)
%shot=0;
} else
%shot=$shot + 1;
}

function RegunImage::onClipout(%obj)
{
setimageammo(0,false)
}

meh.. now its sorta acting funny every time i re-exec it a second time it gives me a buffer overload crash message thing, also now it never does goto clipout. also randy, what exactly do you mean by all that? I'm still kinda new to this scripting stuff..
Code: [Select]
function RegunImage::onMount()
{
//%shot== 0;
}

//function RegunImage::onFire(%this,%obj,%slot)
//{
// if(%obj.getDamagePercent() < 1.0)
// %obj.playThread(2, shiftAway);
// Parent::onFire(%this,%obj,%slot);
//}

function RegunImage::onFire(%obj)
{
if(%shot== 5){
//%this.goto(Clipout);
setimageammo(0,true)
%shot=0;
} else[u][b]{[/b][/u]
%shot=$shot + 1;
[u][b]}[/b][/u]
}

function RegunImage::onClipout(%obj)
{
setimageammo(0,false)
}
I'd suggest those two brackets to be inserted

They don't need to be inserted, there's only one line of code after the else.

Try this

Code: [Select]
Try this

function RegunImage::onFire(%this,%obj,%slot)
{
if(%obj.getImageAmmo(0))
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
if(%obj.shot >= 5)
{
%this.goto(Clipout);
%obj.setimageammo(0,false)
%obj.shot = 0;
schedule(1000,0,reload,%obj);
}
else
%obj.shot++;
Parent::onFire(%this,%obj,%slot);
}

function reload(%obj)
{
%obj.shot = 0;
}


Untested.

Dont use prefire for this

*sigh* bump4help,
the dang console hates me and keeps giving me this stuff:
Code: [Select]
Add-Ons/Weapon_RealGun.cs Line: 233 - Syntax error.
>>> Advanced script error report.  Line 465.
>>> Some error context, with ## on sides of error halt:
if(%obj.shot >= 5)

{

%this.goto(Clipout);

%obj.setimageammo(0,false)

%obj.##s##hot = 0;

schedule(1000,0,reload,%obj);

}

else

%obj.shot++;

Parent::onFire(%this,%obj,%slot);
>>> Error report complete.

Executing Add-Ons/Weapon_RealGun.cs.
Add-Ons/Weapon_RealGun.cs Line: 233 - Syntax error.
>>> Advanced script error report.  Line 465.
>>> Some error context, with ## on sides of error halt:
if(%obj.shot >= 5)

{

%this.goto(Clipout);

%obj.setimageammo(0,false)

%obj.##s##hot = 0;

schedule(1000,0,reload,%obj);

}

else

%obj.shot++;

Parent::onFire(%this,%obj,%slot);
>>> Error report complete.

i patch up the %obj.%shot and it gives me this:


Code: [Select]
Add-Ons/Weapon_RealGun.cs Line: 229 - Syntax error.
>>> Advanced script error report.  Line 457.
>>> Some error context, with ## on sides of error halt:
if(%obj.getDamagePercent() < 1.0)

%obj.playThread(2, shiftAway);

if(%obj.%shot ##>##= 5)

{

%this.goto(Clipout);

%obj.setimageammo(0,false)

%obj.%shot = 0;
>>> Error report complete.

Executing Add-Ons/Weapon_RealGun.cs.
Add-Ons/Weapon_RealGun.cs Line: 229 - Syntax error.
>>> Advanced script error report.  Line 457.
>>> Some error context, with ## on sides of error halt:
if(%obj.getDamagePercent() < 1.0)

%obj.playThread(2, shiftAway);

if(%obj.%shot ##>##= 5)

{

%this.goto(Clipout);

%obj.setimageammo(0,false)

%obj.%shot = 0;
>>> Error report complete.

ARG! why wont it work >_<

You're missing a ";" here: %obj.setimageammo(0,false)

if(%obj.%shot >= 5)

Take out the second %.

it still hates me:
Code: [Select]
Executing Add-Ons/Weapon_RealGun.cs.
Add-Ons/Weapon_RealGun.cs Line: 198 - Syntax error.
>>> Advanced script error report.  Line 395.
>>> Some error context, with ## on sides of error halt:
^stateEjectShell[6]       = true;

^

^



};



function RegunImage::onMount()

{

^%shot== 0;##
##
}



//function RegunImage::onFire(%this,%obj,%slot)

//{

//^if(%obj.getDamagePercent() < 1.0)
>>> Error report complete.