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?
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.
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?
Yes, it does.
So what do you need help with? >.<
Checked now, the money is going, I had 4000$ after a rejoin it became 3900$, which was before.
Fixed :P