SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 26/10/2018, 09:29 PM   #1
Calinut200
Big Clucker
 
Join Date: Jun 2016
Posts: 74
Reputation: 0
Default Money update

I make a rly eazy /dice sistem , all work good but when i use /stats my money don't update if i win or lose at dice.
If i enter on server and i have 100kk , and i lose all at dice , in /stats will be 100kk. DOn't update the money.
Code:
CMD:dice1(playerid)
{
	new dice = 1 + random(2);
    if(dice == 1)
	{
	SendClientMessage(playerid,-1,"A picat un numar impar.");
	SendClientMessage(playerid,-1,"Ai pierdut 1.000.000");
	GivePlayerMoney(playerid , -1000000);
    return 1;
	}
	else if(dice == 2)
	{
	SendClientMessage(playerid,-1,"A picat un numar par.");
	SendClientMessage(playerid,-1,"Ai castigat 1.000.000");
	GivePlayerMoney(playerid , 1000000);
    return 2;
	}
	return 1;
}
Code:
CMD:stats(playerid, params[])
{
  new string[500],name[MAX_PLAYER_NAME];
  GetPlayerName(playerid, name, sizeof(name));
  format(string, sizeof(string), "{4286f4}Name{FFFFFF}: %s\n{4286f4}Admin Level{FFFFFF}: %i\n{4286f4}Money{FFFFFF}: %i",name, PlayerInfo[playerid][pAdmin],  PlayerInfo[playerid][pCash]);
  SendClientMessage(playerid,-1,string);
  return 1;
}
what to do? Sry my bad english.
Calinut200 is offline   Reply With Quote
Old 26/10/2018, 09:36 PM   #2
KinderClans
Banned
 
Join Date: May 2018
Location: Italy
Posts: 716
Reputation: 43
Default Re: Money update

pawn Code:
CMD:dice1(playerid)
{
    new dice = 1 + random(2);
   
    switch (dice)
    {
        case 1:
    {
        SendClientMessage(playerid,-1,"A picat un numar impar.");
        SendClientMessage(playerid,-1,"Ai pierdut 1.000.000");
        GivePlayerMoney(playerid, -1000000);
    }
        case 2:
    {
        SendClientMessage(playerid,-1,"A picat un numar par.");
        SendClientMessage(playerid,-1,"Ai castigat 1.000.000");
        GivePlayerMoney(playerid, 1000000);
    }
    return 1;
}

Use switch, it's much faster. And that return 2; was useless.

In /stats command, creating a string with 500 cells is useless if you're showing only 3 variables.
KinderClans is offline   Reply With Quote
Old 26/10/2018, 09:43 PM   #3
Calinut200
Big Clucker
 
Join Date: Jun 2016
Posts: 74
Reputation: 0
Default Re: Money update

But how i update PlayerInfo(playerid)(pCash) if i win 50kk at dice. If i have 20kk and i win 50kk. That 50kk dont show in /stats ,money :20kk not money:70kk. That money from dice dont sav in stats
Calinut200 is offline   Reply With Quote
Old 26/10/2018, 09:49 PM   #4
KinderClans
Banned
 
Join Date: May 2018
Location: Italy
Posts: 716
Reputation: 43
Default Re: Money update

Because you're using pCash wrong. Lemme do an example.

This should happen when player login: (Assuming you're using MySQL)

pawn Code:
cache_get_value_int(0, "Cash", PlayerInfo[playerid][pCash]);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);

When giving money to a player, just use GivePlayerMoney.

If player quits and you wanna save their money, then:

pawn Code:
new query[70], p = playerid;
   
    mysql_format(g_SQL, query,sizeof(query), "UPDATE `your_players_table` SET `Cash` = %i WHERE `ID`= %d",
    GetPlayerMoney(p) PlayerInfo[p][AccountID]);
   
    mysql_query(g_SQL, query);

Notice how i used GetPlayerMoney to get current player's money and saving them in "Cash" row.

To show them in /stats, you don't need to call pCash, just use GetPlayerMoney.

pawn Code:
CMD:mymoney(playerid, params[])
{
  new string[80];
  format(string, sizeof(string), "I currently have $%i in my pocket.", GetPlayerMoney(playerid));
  SendClientMessage(playerid,-1,string);
  return 1;
}
KinderClans is offline   Reply With Quote
Old 26/10/2018, 09:55 PM   #5
Calinut200
Big Clucker
 
Join Date: Jun 2016
Posts: 74
Reputation: 0
Default Re: Money update

Thanks man , i will try tomorrow . I don t use mysql, i dont know how to use it.
Calinut200 is offline   Reply With Quote
Old 26/10/2018, 09:56 PM   #6
KinderClans
Banned
 
Join Date: May 2018
Location: Italy
Posts: 716
Reputation: 43
Default Re: Money update

What are you using then?
KinderClans is offline   Reply With Quote
Old 26/10/2018, 10:32 PM   #7
Calinut200
Big Clucker
 
Join Date: Jun 2016
Posts: 74
Reputation: 0
Default Re: Money update

A folder where is a folder for player , 1000players register= 1000 folders
Calinut200 is offline   Reply With Quote
Old 26/10/2018, 10:34 PM   #8
KinderClans
Banned
 
Join Date: May 2018
Location: Italy
Posts: 716
Reputation: 43
Default Re: Money update

What the...
KinderClans is offline   Reply With Quote
Old 27/10/2018, 12:49 AM   #9
kristo
Banned
 
Join Date: Jun 2012
Location: Estonia
Posts: 352
Reputation: 179
Default Re: Money update

Quote:
Originally Posted by KinderClans View Post
Use switch, it's much faster.
What's your reasoning behind this statement?
kristo is offline   Reply With Quote
Old 27/10/2018, 01:00 AM   #10
KinderClans
Banned
 
Join Date: May 2018
Location: Italy
Posts: 716
Reputation: 43
Default Re: Money update

Quote:
Originally Posted by kvann View Post
What's your reasoning behind this statement?
Yeah you're right. It's much better to do if and else if everytime. You're right. There are many reasons why switch is more faster than if. Apart from easiness in the use, ofc.
KinderClans is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best Anti-Money Hack Method (Server Sided Money) Discussion Dorito Scripting Help 15 18/12/2016 02:46 PM
Money bar does not update OllyBrock Scripting Help 3 08/03/2014 10:35 PM
Money doesn't update unless you relog conor565 Scripting Help 3 03/11/2012 12:28 AM
[Include] money.inc - Advanced, plug-n-play, server-sided money system fiki574 Includes 7 25/02/2012 09:47 PM
Update players money when they get it..? _Vortex Help Archive 6 07/09/2009 02:04 AM


All times are GMT. The time now is 02:04 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.