Liberty Unleashed

Scripting => Script Help => Topic started by: annoxoli on March 23, 2014, 11:54:15 am

Title: pPlayer.Cash (Main.nut) - problem
Post by: annoxoli on March 23, 2014, 11:54:15 am
Hi,

I want to remove Cash when a vehicle is spawned. I use the follow script :
Code: [Select]
else if ( szCmd == "spawncar" )
{
if ( szParams )
{
local pTemp = split( szParams, " " ), ID = 90;
if ( IsNum( pTemp[ 0 ] ) ) ID = pTemp[ 0 ].tointeger();
if ( pPlayer.Cash >= 250 )
{
if ( ( ID >= 90 ) && ( ID <= 150 ) )
{
local v = pPlayer.Pos;
pPlayer.Cash -= 250;
MessagePlayer( "Der Mechaniker hat dir das Auto " + ID + " geliefert", pPlayer );
CreateVehicle( ID, Vector( v.x + 5, v.y, v.z ), pPlayer.Angle );
}
}
else
{
MessagePlayer ( "Du brauchst mindestens $250 um ein Auto zu Spawnen", pPlayer );
}
}
}

But my server still crash, with no reason!
If I remove these command "pPlayer.Cash -= 250 ;" it's still working!
But why this won't work ? "pPlayer.Cash >= 250" will work also.

Thanks, greetings Annoxoli
Title: Re: pPlayer.Cash (Main.nut) - problem
Post by: annoxoli on March 23, 2014, 12:50:42 pm
still working :
Code: [Select]
else if ( szCmd == "spawncar" )
{
if ( szParams )
{
local pTemp = split( szParams, " " ), ID = 90;
if ( IsNum( pTemp[ 0 ] ) ) ID = pTemp[ 0 ].tointeger();
if ( pPlayer.Cash >= 250 )
{
if ( ( ID >= 90 ) && ( ID <= 150 ) )
{
local v = pPlayer.Pos;
MessagePlayer( "Der Mechaniker hat dir das Auto " + ID + " geliefert", pPlayer );
CreateVehicle( ID, Vector( v.x + 5, v.y, v.z ), pPlayer.Angle );
pPlayer.Cash -= 250;
}
}
else
{
MessagePlayer ( "Du brauchst mindestens $250 um ein Auto zu Spawnen", pPlayer );
}
}
}
Title: Re: pPlayer.Cash (Main.nut) - problem
Post by: Mido_Pop on March 23, 2014, 03:21:05 pm
Try This >>>>
Code: [Select]
else if ( szCmd == "spawncar" )
{
if ( szParams )
{
local pTemp = split( szParams, " " ), ID = 90;
if ( IsNum( pTemp[ 0 ] ) ) ID = pTemp[ 0 ].tointeger();
if ( ( ID >= 90 ) && ( ID <= 150 ) )
{
                                  if ( pPlayer.Cash >= 250 )
                                   {
local v = pPlayer.Pos;
pPlayer.Cash -= 250;
MessagePlayer( "Der Mechaniker hat dir das Auto " + ID + " geliefert", pPlayer );
CreateVehicle( ID, Vector( v.x + 5, v.y, v.z ), pPlayer.Angle );
                                   }
                                  else
                                   {
                                      MessagePlayer( "Sorry You Need 250$.", pPlayer );
                                   }
}
}
}
 
Title: Re: pPlayer.Cash (Main.nut) - problem
Post by: Vortrex on March 24, 2014, 02:25:53 am
Mido_Pop, I noticed two flaws with your code:

First of all, why do you need to check for the player cash twice?
You check the cash once, then check the vehicle model ID, then the cash again.

Second, I have mentioned this before to you at some point. I don't remember when exactly it was, but there is an awesome key on most keyboards called the "TAB" key ... When used properly, this key is really good at its job in making code readable through the use of clean indentation. On a standard QWERTY keyboard, this key is right above the Caps Lock keyboard, but it could differ for whatever keyboard layout you use.

Thanks in advance for understanding.
Title: Re: pPlayer.Cash (Main.nut) - problem
Post by: Merkel on March 24, 2014, 04:49:21 pm
use...
It's optimized

Code: [Select]
function onPlayerCommand ( pPlayer, szCommand, szParams ) {

switch ( szCommand ) {

case "v": case "veh": case "car": case "spawncar":
{

if ( pPlayer.Cash >= 250 ) {

if ( szParams ) {

local ID = 0;

if ( IsNum ( szParams ) ) ID = GetTok ( szParams, " ", 1 );

if ( ID >= 90 && ID <= 150 ) {

local Vehicle = CreateVehicle ( ID, pPlayer.Pos, pPlayer.Angle );
if ( Vehicle ) pPlayer.Vehicle = Vehicle;

Vehicle.OneTime = true;

pPlayer.Cash -= 250;

return;
}

MessagePlayer ( "Usage : /" + szCommand + " < 90 - 150 >", pPlayer );

return;
}

MessagePlayer ( "Usage : /" + szCommand + " < 90 - 150 >", pPlayer );

return;
}

MessagePlayer ( "You need $ 250 for spawn a vehicle.", pPlayer );

return;
}
}
}
Title: Re: pPlayer.Cash (Main.nut) - problem
Post by: SugarD on April 25, 2014, 02:10:57 pm
Second, I have mentioned this before to you at some point. I don't remember when exactly it was, but there is an awesome key on most keyboards called the "TAB" key ... When used properly, this key is really good at its job in making code readable through the use of clean indentation. On a standard QWERTY keyboard, this key is right above the Caps Lock keyboard, but it could differ for whatever keyboard layout you use.
He may have typed it out in the reply box here on the forums, which would have blocked the use of the tab key.