SA-MP Forums Archive
Money update - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Money update (/showthread.php?tid=660175)



Money update - Calinut200 - 26.10.2018

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.
Код:
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;
}
Код:
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.


Re: Money update - KinderClans - 26.10.2018

pawn Код:
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.


Re: Money update - Calinut200 - 26.10.2018

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


Re: Money update - KinderClans - 26.10.2018

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

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

pawn Код:
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 Код:
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 Код:
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;
}



Re: Money update - Calinut200 - 26.10.2018

Thanks man , i will try tomorrow . I don t use mysql, i dont know how to use it.


Re: Money update - KinderClans - 26.10.2018

What are you using then?


Re: Money update - Calinut200 - 26.10.2018

A folder where is a folder for player , 1000players register= 1000 folders


Re: Money update - kristo - 27.10.2018

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
Use switch, it's much faster.
What's your reasoning behind this statement?


Re: Money update - KinderClans - 27.10.2018

Quote:
Originally Posted by kvann
Посмотреть сообщение
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.


Re: Money update - kristo - 27.10.2018

Quote:
Originally Posted by kvann
Посмотреть сообщение
What's your reasoning behind this statement?
Quote:
Originally Posted by KinderClans
Посмотреть сообщение
There are many reasons why switch is more faster than if.
And that's why I asked for them.