26.06.2014, 18:23
Hello,
So i am trying to save the score,
Well thats what i did
I also added this stock
And this timer
And for sure
under ongamemodeinit
I also added a cmd so i can test,
But it sets my score, and after i logout My score resets.
So i am trying to save the score,
Well thats what i did
Code:
enum E_PLAYERS { ID, Name[MAX_PLAYER_NAME], Password[129], Money, Score, eHumans, eZombies, bool:IsLoggedIn, bool:IsRegistered, LoginAttempts, LoginTimer };
Code:
public OnPlayerSpawn(playerid) { SetPlayerScore(playerid, PlayerInfo[playerid][Score]); return 1; }
Code:
AssignPlayerData(playerid) { PlayerInfo[playerid][ID] = cache_get_field_content_int(0, "id"); cache_get_field_content(0, "password", PlayerInfo[playerid][Password], g_SQL, 129); PlayerInfo[playerid][Money] = cache_get_field_content_int(0, "money"); PlayerInfo[playerid][Score] = cache_get_field_content_int(0, "score"); return 1; }
Code:
UpdatePlayerData(playerid) { if(PlayerInfo[playerid][IsLoggedIn] == false) return 0; new query[128]; mysql_format(g_SQL, query, sizeof(query), "UPDATE `players` SET `money` = '%d' SET `score` = '%d' WHERE `id` = '%d' LIMIT 1", PlayerInfo[playerid][Money],PlayerInfo[playerid][Score], PlayerInfo[playerid][ID]); mysql_tquery(g_SQL, query); return 1; }
Code:
SetupPlayerTable() { mysql_query(g_SQL, "CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL auto_increment PRIMARY KEY,`username` varchar(30) NOT NULL,`password` varchar(130) NOT NULL,`money` int(10) NOT NULL default '0',`score` int(10) NOT NULL default '0')", false); return 1; }
Code:
stock Player_GiveScore(playerid,amount) { PlayerInfo[playerid][Score] += amount; return 1; }
Code:
function MainTimer() { foreach(Player, playerid) { ResetPlayerMoney(playerid); GivePlayerMoney(playerid, PlayerInfo[playerid][Money]); SetPlayerScore(playerid, PlayerInfo[playerid][Score]); } }
Code:
SetTimer("MainTimer", 500, 1);
I also added a cmd so i can test,
Code:
CMD:ok(playerid,params[]) { Player_GiveScore(playerid,500); return 1; }