Hey Guys What's going on?
I was trying to Implement my Cash System But Faced a bit problem
I have created Two Functions SetCash & GetCash Also Create Table in Database
Codes:
Function SetCash, GetCash, Cash
function GetCash( player )
{
local v = GetSQLColumnData( QuerySQL( DB, "SELECT Cash FROM Cash WHERE Name='" + player.Name+"'" ), 0 );
if ( v ) return v.tointeger();
else return 0;
}
function Cash( player )
{
local q = QuerySQL( DB, "SELECT * FROM Cash WHERE Name='" + player.Name+ "'" );
status[ player.ID ].Cash = GetSQLColumnData( q, 1 );
status[ player.ID ].Bank = GetSQLColumnData( q, 2 );
}
function SetCash( player, amount )
{
status[ player.ID ].Cash = amount.tointeger();
QuerySQL(DB, "UPDATE Cash SET Cash='" + amount.tointeger() + "' WHERE Name='" + player.Name + "'");
}
Database Loaded
function CreateTables()
{
QuerySQL( DB, "CREATE TABLE IF NOT EXISTS Cash( Name VARCHAR(32),Cash INT(15), Bank INT(15) )" );
}
I have added this on PlayerDeath
SetCash( player, GetCash( player ) -1000);
But When I type /kill it Doesn't Decrease my Cash but do in Database
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi68.tinypic.com%2Fvgts9i.png&hash=ee7d0b65796aeaf17be1063987ed296b19de24a4)
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi66.tinypic.com%2F15not50.png&hash=94e16af8240fea279d4a871ecb1d08206da704ab)
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi65.tinypic.com%2Fjsgbw2.png&hash=0308e25023622bca8787cea316f732ddbbcfa25d)
What I wanted to fix?
I wanted Cash to be increase & decrease with real cash provided in Gta Vice City!
SetCash( player, GetCash( player) - 1000 );
Quote from: Xmair on Jul 15, 2017, 10:14 AMSetCash( player, GetCash( player) - 1000 );
What Bro?
Quote from: Terror_Styles on Jul 15, 2017, 10:24 AMQuote from: Xmair on Jul 15, 2017, 10:14 AMSetCash( player, GetCash( player) - 1000 );
What Bro?
This
SetCash( player, GetCash( player ) -1000);
and this
SetCash( player, GetCash( player) - 1000 );
are different.
Just replace that line with the one I gave and try.
In hand: -1000
It's correct.
Quote from: KAKAN on Jul 15, 2017, 11:37 AMIn hand: -1000
It's correct.
Then replace your SetCash function to this
function SetCash( player, amount )
{
status[ player.ID ].Cash = amount.tointeger();
QuerySQL(DB, "UPDATE Cash SET Cash='" + amount.tointeger() + "' WHERE Name='" + player.Name + "'");
player.Cash = amount.tointeger( );
}
Thanks
@Xmair :)
@KAKAN Too! For Reminding Him!
Why are you using a string to store cash?
Quote from: EK.IceFlake on Jul 15, 2017, 12:46 PMWhy are you using a string to store cash?
Because then it looks similar to INI storage :P