admin command trouble info saving to mysql
#1

Hi. My command won't change the value in mysql. I have a textdraw and it shows my money


Код HTML:
	format(strupdate,sizeof(strupdate),"Blood: %i~n~Temp: %0.2f F~n~Name: %s ~n~Money: %i USD",
							    pInfo[i][pBlood],pInfo[i][pTemp],PlayerName(i),pInfo[i][pMoney]);
This is the admin command
Код HTML:
CMD:setmoney(playerid,params[])
{
	if(pInfo[playerid][pAdminLevel] >= 5)
	{
	    new targetid,money,string[128];
	    if(sscanf(params, "ui", targetid,money)) return SendClientMessage(playerid,-1,""chat" /setmoney [id] [value]");
   		if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,-1,""chat" Player is not online");

		format(string,sizeof(string),"*"COL_RED" %s %ssets %s money to  %i USD", GetAdminName(playerid),PlayerName(playerid),PlayerName(targetid),money);
		SendMessageToAllAdmins(string,-1);

		format(string,sizeof(string),"*"COL_RED" %s %s has set ur money to %i USD",GetAdminName(playerid), PlayerName(playerid), money);
		SendClientMessage(targetid,-1,string);

		pInfo[targetid][pMoney] = money;
	}
	else {
		SendClientMessage(playerid,-1,"*"COL_RED" U no admin!");
	}
	return 1;
}
bUt it won't save to the mysql the new data. why? I type /setmoney x 1000 but in mysql it still remains 0.



mysql cmd

Код HTML:
	strcat(querystr,"CREATE TABLE IF NOT EXISTS `users` (`Username` varchar(24) NOT NULL,`Password` varchar(128) NOT NULL,`Headshots` int(11) NOT NULL,`Murders` int(11) NOT NULL,`BanditsKilled` int(11) NOT NULL,`ZombiesKilled` int(11) NOT NULL, `Backpack` int(11) NOT NULL,`BackpackSlots` int(11) NOT NULL,");
	strcat(querystr,"`BackpackSlotsUsed` int(11) NOT NULL,`pAdminLevel` int(11) NOT NULL,`pVIP` int(11) NOT NULL,`pX` float NOT NULL,`pY` float NOT NULL,`pZ` float NOT NULL,`pWeap1` int(11) NOT NULL,`pAmmo1` int(11) NOT NULL,`pWeap2` int(11) NOT NULL,");
	strcat(querystr,"`pAmmo2` int(11) NOT NULL,`pWeap3` int(11) NOT NULL,`pAmmo3` int(11) NOT NULL,`pWeap4` int(11) NOT NULL,`pAmmo4` int(11) NOT NULL,`pWeap5` int(11) NOT NULL,`pAmmo5` int(11) NOT NULL,`pWeap6` int(11) NOT NULL,`pAmmo6` int(11) NOT NULL,`pWeap7` int(11) NOT NULL,");
	strcat(querystr,"`pAmmo7` int(11) NOT NULL,`pWeap8` int(11) NOT NULL,`pAmmo8` int(11) NOT NULL,`pWeap9` int(11) NOT NULL,`pAmmo9` int(11) NOT NULL,`pHour` int(11) NOT NULL,`pMin` int(11) NOT NULL,`pSec` int(11) NOT NULL,`pBlood` nt(11) NOT NULL,`pMoney` int(11) NOT NULL,`pThrist` int(11) NOT NULL,");
	strcat(querystr,"`pHunger` int(11) NOT NULL,`Humanity` int(11) NOT NULL,`pFirstSpawn`  int(11) NOT NULL,`pJailed` int(11) NOT NULL,`pAliveTime` int(11) NOT NULL,`pIsMapOpened` int(11) NOT NULL,`pSkin` int(11) NOT NULL,`Helper` int(11) NOT NULL, `Leader` int(11) NOT NULL,`IsPlayerBleeding` int(11) NOT NULL,");
  	strcat(querystr,"`IsPlayerLegBroken` int(11) NOT NULL,`pAmbientEnable` int(11) NOT NULL,`DefaultGender` int(11) NOT NULL, `IP` varchar(16) NOT NULL,`ID` int(11) NOT NULL)");
and

Код HTML:
enum playerinfo
{
pMoney
...
ex: In game i write 500 but in mysql it remains 0.
Reply
#2

You have to save his money everytime you change it.

i would also recommend using serversided money because it can not be hacked.

PHP код:
GivePlayerCash(playeridmoney)
{
    
pInfo[targetid][pMoney] += money;
    if(
pInfo[playerid][IsLoggedIn] == true)
     {
        new 
str[128];
        
mysql_format(SQLstr,128,"UPDATE `users` SET `Cash`='%d' WHERE `id` = '%d' LIMIT 1",pInfo[playerid][Cash],pInfo[playerid][ID]);
        
mysql_tquery(SQLstr"""");
    }
    
UpdateMoneyBar(playerid,pInfo[playerid][Cash]);
    if(
pInfo[playerid][pMoney] != GetPlayerMoney(playerid))
    {
        
GivePlayerMoney(playeridpInfo[playerid][Cash] - GetPlayerMoney(playerid));
    }
    return 
pInfo[playerid][Cash];

add this to your gamemode and replace
Код:
GivePlayerMoney
with
Код:
GivePlayerCash
also,change that according to your variables. good luck

Код:
UpdateMoneyBar
simply gives him money with GivePlayerMoney according to his serversided money ( so the green money bar updates )
Reply
#3

pInfo[playerid][ID]


ID = ? what with what should i replace it?


and shouldn't i replace [cash] with [pMoney] ?

GivePlayerMoney(playerid, pInfo[playerid][Cash]
in
GivePlayerMoney(playerid, pInfo[playerid][pMoney]
Reply
#4

yes,replace cash with your variable,i must have forgotten a few variables,you gotta arrange them

and ID is the the ID in the database .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)