Author Topic: pPlayer.Cash (Main.nut) - problem  (Read 1590 times)

annoxoli

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
pPlayer.Cash (Main.nut) - problem
« on: March 23, 2014, 12:54:15 pm »
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

annoxoli

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: pPlayer.Cash (Main.nut) - problem
« Reply #1 on: March 23, 2014, 01: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 );
}
}
}

Mido_Pop

  • Full Member
  • ***
  • Posts: 168
  • Karma: +6/-20
  • The_Pops ( War )
    • View Profile
Re: pPlayer.Cash (Main.nut) - problem
« Reply #2 on: March 23, 2014, 04: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 );
                                   }
}
}
}
 
« Last Edit: March 24, 2014, 02:42:33 pm by Mido_Pop »



Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: pPlayer.Cash (Main.nut) - problem
« Reply #3 on: March 24, 2014, 03: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.

Merkel

  • Jr. Member
  • **
  • Posts: 89
  • Karma: +4/-10
    • View Profile
Re: pPlayer.Cash (Main.nut) - problem
« Reply #4 on: March 24, 2014, 05: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;
}
}
}
« Last Edit: March 24, 2014, 05:55:54 pm by Dopery »
Westwood Studios

The best studios company in strategy videogames.

SugarD

  • Argonath RPG Dev/Manager
  • Tester
  • Sr. Member
  • ****
  • Posts: 820
  • Karma: +37/-75
  • STOP IN THE NAME OF THE COLESLAW!
    • View Profile
    • Clan Xperience
Re: pPlayer.Cash (Main.nut) - problem
« Reply #5 on: April 25, 2014, 03: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.

 

© Liberty Unleashed Team.