Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: KAKAN on Sep 22, 2015, 01:38 PM

Title: player.Cash
Post by: KAKAN on Sep 22, 2015, 01:38 PM
Hello All!
I save the cash in a array, when a player leaves his cash( player.Cash ) gets converted into the array (stats[ player.ID ].Cash), when he reconnects, everything is OK. but when he lost his connection and tries again, his cash is set back to 0, why?
Title: Re: player.Cash
Post by: KAKAN on Sep 22, 2015, 01:47 PM
Okay. So to solve this problem, I have made some functions like this:-
function IncCash( player, amount )
{
  stats[ player.ID ].Cash += amount.tointeger();
  player.Cash += amount.tointeger();
}

function DecCash( player, amount )
{
  stats[ player.ID ].Cash -= amount.tointeger();
  player.Cash += amount.tointeger();
}

And a cmd regarding to it:-
else if ( cmd == "givecash" )
            {
            local Cash = player.Cash
            if ( !text ) PrivMessage( player, "Error - Invalid Format, /Givecash <Nick/ID> <Amount>" );
            else if ( NumTok( text, " " ) < 2 ) PrivMessage( player,"Error - Invalid Format, !Givecash <Nick/ID> <Amount>" );
            local plr = GetPlayer( GetTok( text, " ", 1 ) ), amount = GetTok( text, " ", 2 )
            if ( !plr ) PrivMessage( player,"Error - Invalid Nick/ID." );
else if ( !IsNum(amount) ) PrivMessage( player,"Error: Amount must be in numbers." );
            else if ( Cash < amount.tointeger() ) PrivMessage( player,"Not Enough Money!!" );
            else if ( amount.tointeger() < 0 ) PrivMessage( player,"Sending Failed, Please use the correct way to send." );
            else if ( !stats[ plr.ID ].Logged ) PrivMessage( player, plr.Name + " haven't registered himself/herself.");
                       else
               {
                          PrivMessage( player,"You Gave " + ammount + " To " + plr.Name );
                          DecCash( player, amount );
                          PrivMessage( plr,"You Recevied " + amount + " From " + player.Name );
                          IncCash( plr, amount );
               }
        }

So is the code given above is correct? I actually doubt on the .tointeger() points.
Title: Re: player.Cash
Post by: KAKAN on Sep 22, 2015, 01:51 PM
And yes, added one more function
function GetCash(player) {
return stats[ player.ID ].Cash
}

And I'm using this one on onpLayerkill
if( stats[ killer.ID ].Logged )
{
stats[ killer.ID ].Kills++
IncCash( killer, 150 );
  stats[ killer.ID ].Update( player, sqliteDB );
  }
if( stats[ player.ID ].Logged )
{
stats[ player.ID ].Deaths++
if ( GetCash(player) < 100 )
{
DecCash( player, player.Cash );
}
else DecCash( player, 100 );
stats[ player.ID ].Update( player, sqliteDB );
}

So any bugs?
Title: Re: player.Cash
Post by: Thijn on Sep 22, 2015, 03:54 PM
Quote from: KAKAN on Sep 22, 2015, 01:51 PMSo any bugs?
You tell us. Does it work?
Title: Re: player.Cash
Post by: KAKAN on Sep 22, 2015, 04:10 PM
Yes, it does.
Title: Re: player.Cash
Post by: Thijn on Sep 22, 2015, 04:19 PM
So what do you need help with? >.<
Title: Re: player.Cash
Post by: KAKAN on Sep 22, 2015, 04:23 PM
Checked now, the money is going, I had 4000$ after a rejoin it became 3900$, which was before.
Title: Re: player.Cash
Post by: KAKAN on Sep 22, 2015, 04:31 PM
Fixed :P