format(string, sizeof(string), "INSERT INTO `players` ( `Name` , `Password`, `Money` , `Bank` , `Level` ,`RPoints` ,`Warns` ,`Job` ,`Banned` ,`Kills` , `Deaths`, `Faction`, `LastIP`, `rankname` `groupID`) VALUES ('%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d','%s','%s', '%s' '%d')",
PlayerName(playerid), PlayerTemp[playerid][password], PlayerTemp[playerid][sm], PlayerInfo[playerid][bank], PlayerInfo[playerid][playerlvl], PlayerInfo[playerid][rpoints], PlayerInfo[playerid][warns], PlayerInfo[playerid][job], PlayerInfo[playerid][banned], PlayerInfo[playerid][kills], PlayerInfo[playerid][deaths] ,PlayerInfo[playerid][PTeamName], PlayerTemp[playerid][IP], PlayerInfo[playerid][rankname], PlayerTemp[playerid][groupID]);
mysql_query(string);
So heres my code for registering a player, i have more things to save, so how to make these into 2-3 lines with using other strings?
pawn Код:
|
//Re-use:
format(string, sizeof(string), "INSERT INTO `players` ( `Name`) VALUES ('%s')", PlayerName(playerid));
mysql_query(string);
format(string, sizeof(string), "INSERT INTO `players` ( `Password`) VALUES ('%s')", PlayerTemp[playerid][password]);
mysql_query(string);
//and so on
//New variables:
format(string, sizeof(string), "INSERT INTO `players` ( `Name`) VALUES ('%s')", PlayerName(playerid));
mysql_query(string);
new string_2[50];
format(string_2, sizeof(string_2), "INSERT INTO `players` ( `Password`) VALUES ('%s')", PlayerTemp[playerid][password]);
mysql_query(string_2);
//and so on
format(string, sizeof(string), "INSERT INTO `players` ( `Name` , `Password`, `Money` , `Bank` , `Level` ,`RPoints` ,`Warns` ,`Job` ,`Banned` ,`Kills` , `Deaths`, `Faction`, `LastIP`, `rankname`) VALUES ('%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d','%s','%s', '%s')",
PlayerName(playerid), PlayerTemp[playerid][password], PlayerTemp[playerid][sm], PlayerInfo[playerid][bank], PlayerInfo[playerid][playerlvl], PlayerInfo[playerid][rpoints], PlayerInfo[playerid][warns], PlayerInfo[playerid][job], PlayerInfo[playerid][banned], PlayerInfo[playerid][kills], PlayerInfo[playerid][deaths] ,PlayerInfo[playerid][PTeamName], PlayerTemp[playerid][IP], PlayerInfo[playerid][rankname]);
format(string, sizeof(string),"INSERT INTO `players` ( `groupID`, `groupName`, `groupLeader` ) VALUES ( '%d', '%s', '%s' )", PlayerTemp[playerid][groupID], PlayerTemp[playerid][groupName], PlayerTemp[playerid][groupLeader]);
mysql_query(string);
//Registering//
new
string [ 128 ]
;
format(string, sizeof(string), "INSERT INTO `players` ( Name , Password ) VALUES ( '%s', '%s' )",
PlayerName( playerid ), PlayerTemp[ playerid ][ password ]);
mysql_query(string);
//Saving//
new
string [ 528 ] // change the string value if this is not enough.
;
format( string, sizeof ( string ), "UPDATE `players` SET `Money` = %i , `Bank` = %i , `Level` = %i ,`RPoints` = %i ,`Warns` = %i ,`Job` = %i ,`Banned` = %i , \
`Kills` = %i, `Deaths` = %i, `Faction` = %i, `LastIP` = '%s' , `rankname` = '%s' WHERE `Username` = '%s'",
PlayerTemp[playerid][sm], PlayerInfo[playerid][bank], PlayerInfo[playerid][playerlvl], PlayerInfo[playerid][rpoints], PlayerInfo[playerid][warns], PlayerInfo[playerid][job],
PlayerInfo[playerid][banned], PlayerInfo[playerid][kills], PlayerInfo[playerid][deaths] ,PlayerInfo[playerid][PTeamName], PlayerTemp[playerid][IP], PlayerInfo[playerid][rankname], PlayerName(playerid));
format( string, sizeof ( string ), "UPDATE `players` SET `groupID` = %i , `groupName` = '%s' , `groupLeader` = '%s'",
PlayerTemp[playerid][groupID], PlayerTemp[playerid][groupName], PlayerTemp[playerid][groupLeader]);