Player.Cash or Cash Function

Started by Terror_Styles, Jul 15, 2017, 08:50 AM

Previous topic - Next topic

Terror_Styles

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







What I wanted to fix?
I wanted Cash to be increase & decrease with real cash provided in Gta Vice City!

Xmair

SetCash( player, GetCash( player) - 1000 );

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Terror_Styles


Xmair

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.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

KAKAN

oh no

Xmair

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( );
}

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Terror_Styles


EK.IceFlake

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
.