Money update
#1

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.
Reply
#2

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.
Reply
#3

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
Reply
#4

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;
}
Reply
#5

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

What are you using then?
Reply
#7

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

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

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.
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)