Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Terror_Styles on Jul 15, 2017, 08:50 AM

Title: Player.Cash or Cash Function
Post by: Terror_Styles on Jul 15, 2017, 08:50 AM
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!
Title: Re: Player.Cash or Cash Function
Post by: Xmair on Jul 15, 2017, 10:14 AM
SetCash( player, GetCash( player) - 1000 );
Title: Re: Player.Cash or Cash Function
Post by: Terror_Styles on Jul 15, 2017, 10:24 AM
Quote from: Xmair on Jul 15, 2017, 10:14 AMSetCash( player, GetCash( player) - 1000 );
What Bro?
Title: Re: Player.Cash or Cash Function
Post by: Xmair on Jul 15, 2017, 10:58 AM
Quote from: Terror_Styles on Jul 15, 2017, 10:24 AM
Quote 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.
Title: Re: Player.Cash or Cash Function
Post by: KAKAN on Jul 15, 2017, 11:37 AM
In hand: -1000
It's correct.
Title: Re: Player.Cash or Cash Function
Post by: Xmair on Jul 15, 2017, 11:52 AM
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( );
}
Title: Re: Player.Cash or Cash Function
Post by: Terror_Styles on Jul 15, 2017, 12:32 PM
Thanks @Xmair :)
@KAKAN Too! For Reminding Him!
Title: Re: Player.Cash or Cash Function
Post by: EK.IceFlake on Jul 15, 2017, 12:46 PM
Why are you using a string to store cash?
Title: Re: Player.Cash or Cash Function
Post by: . on Jul 15, 2017, 12:55 PM
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