02.08.2013, 20:08
I'm trying to save player ranks to a file, and load them when a player connects but it's not doing it properly.
Code for when player first registers, it automatically sets "Rank" to "Player":
Code to load the rank when player connects
Save the rank (if player changes it) to the file:
This creates a 3d text label with the player's name, id, and whatever rank he/she has in his/her ini file:
This is the command to change the player's rank:
Note: You will see why I have "RemoveEntry" in the command.
Little forward to load user info (yeah i had to resort to a tutorial, I aint pro yet)
Now to explain the whole thing....so hold on (I gotta jumble all of this in one post cause I'm traveling and I will not know when I will stop at another stop with internet)
This is the player's ini file when they first register:
The Rank is clearly specified but look what it shows when I connect:
So I go ahead and change my label with the set label cmd:
Recheck the ini
I go in game and it still displays no rank (couldnt post the image cause I'm starting to run low on time)
If I changed the second "Rank =" to "Rank = Insert rank here" it actually works. So I have no idea how to make y_ini replace an existing entry or "overwrite" ...cause it just makes a new "Rank" that's not included under the Player Data tag (which I think might be the problem)
To everyone who reads all of this unorganized crap, thanks again for taking the time. I will rep+ you for helping, and all help is greatly appreciated
Код:
enum PlayerInfo { Pass[129], AdmLevel, Money, Score, Kills, Deaths, Rank[128], };
Код:
INI_WriteString(file,"Rank","Player");
Код:
format(string2,sizeof(string2),"%s %s (%d) connected:",pInfo[playerid][Rank],Name(playerid),playerid);
Код:
INI_WriteString(file,"Rank",pInfo[playerid][Rank]);
Код:
format(ranklabel,sizeof(ranklabel),"%s (%d)\n%s",Name(playerid),playerid,pInfo[playerid][Rank]); rank[playerid] = Create3DTextLabel(ranklabel,COLOR_YELLOW,0.0,0.0,0.0,100.0,GetPlayerVirtualWorld(playerid),1); Attach3DTextLabelToPlayer(rank[playerid],playerid,0.0,0.0,0.0);
Код:
CMD:setlabel(playerid,params[]) { new ranklabel2[128], plrrank[128],name[MAX_PLAYER_NAME],string[128]; GetPlayerName(playerid,name,sizeof(name)); { if(sscanf(params,"s[128]",string)) return SendClientMessage(playerid, 0xFF0000FF,"USAGE: /setlabel <text>"); if(strlen(ranklabel2) > 32) return SendClientMessage(playerid,0xFF0000FF,"ERROR: Rank must be less than 32 characters."); { new INI:file = INI_Open(Path(playerid)); format(ranklabel2,sizeof(ranklabel2),"%s (%d)\n%s",name,playerid,string); Update3DTextLabelText(rank[playerid],0xFFFF00FF,ranklabel2); format(plrrank,sizeof(plrrank),"You have set your rank to: %s",string); SendClientMessage(playerid,0x008000FF,plrrank); INI_RemoveEntry(file,"Rank"); INI_WriteString(file,"Rank",string); INI_Close(file); } } return 1; }
Little forward to load user info (yeah i had to resort to a tutorial, I aint pro yet)
Код:
forward loadaccount_user(playerid,name[],value[]); public loadaccount_user(playerid,name[],value[]) { INI_String("Pass",pInfo[playerid][Pass],129); INI_Int("AdmLevel",pInfo[playerid][AdmLevel]); INI_Int("Money",pInfo[playerid][Money]); INI_Int("Score",pInfo[playerid][Score]); INI_Int("Kills",pInfo[playerid][Kills]); INI_Int("Deaths",pInfo[playerid][Deaths]); INI_String("Rank",pInfo[playerid][Rank],128); return 1; }
This is the player's ini file when they first register:
Код:
[Player's Data] Pass = 4038C6D0353755AE40BA7D3EF4B1636380CC6310D7EA4B05636DD0355BF83569BF09C5C18F4738B75902F495F9E78C13DB77E6543DD7BFB3C3DE35AD2277DCED AdmLevel = 0 Money = 0 Score = 0 Kills = 0 Deaths = 0 Rank = Player
So I go ahead and change my label with the set label cmd:
Recheck the ini
Код:
Rank = Testing [Player's Data] Pass = 4038C6D0353755AE40BA7D3EF4B1636380CC6310D7EA4B05636DD0355BF83569BF09C5C18F4738B75902F495F9E78C13DB77E6543DD7BFB3C3DE35AD2277DCED AdmLevel = 0 Money = 0 Score = 0 Kills = 0 Deaths = 0 Rank = Player [Player Data] AdmLevel = 0 Money = 0 Score = 0 Kills = 0 Deaths = 0 Rank =
If I changed the second "Rank =" to "Rank = Insert rank here" it actually works. So I have no idea how to make y_ini replace an existing entry or "overwrite" ...cause it just makes a new "Rank" that's not included under the Player Data tag (which I think might be the problem)
To everyone who reads all of this unorganized crap, thanks again for taking the time. I will rep+ you for helping, and all help is greatly appreciated