PDA

View Full Version : Mask System


nerovani
20/02/2016, 11:27 AM
Hi. This is my code:
CMD:buymask(playerid)
{
if(PlayerInfo[playerid][pMask] == 1) return InfoMessage(playerid, "You already have a mask.");
else
{
InfoMessage(playerid, "You have received a mask.");
PlayerInfo[playerid][pMaskID] = randomEx(111111,999999);
PlayerInfo[playerid][pMask] = 1;
}
return 1;
}

CMD:mask(playerid)
{
if(PlayerInfo[playerid][pMask] == 0) return SendClientMessage(playerid, -1, "You don't have a mask");
if(maskon[playerid] == 0)
{
new string[240];
maskon[playerid] = 1;
GetPlayerName(playerid, string, sizeof(string));
strmid(PlayerInfo[playerid][pRealName], string, 0, strlen(string), 64);
format(string,sizeof(string), "Stranger_%d", PlayerInfo[playerid][pMaskID]);
SetPlayerName(playerid, string);
MeMessage(playerid,"puts on their mask.");
for(new i = 0; i < MAX_PLAYERS; i++)
{
ShowPlayerNameTagForPlayer(i, playerid, 0);
}
}
else if(maskon[playerid] == 1)
{
SetPlayerName(playerid, PlayerInfo[playerid][pRealName]);
maskon[playerid] = 0;
MeMessage(playerid,"takes off their mask.");
for(new i = 0; i < MAX_PLAYERS; i++)
{
ShowPlayerNameTagForPlayer(i, playerid, 1);
}
}
return 1;
}

CMD:behindmask(playerid, params[])
{
new playerb, string[128];
if(sscanf(params, "i", playerb)) return UsageMessage(playerid, "/behindmask (playerid)");
format(string, sizeof(string), "Stranger %d = %s", PlayerInfo[playerb][pMaskID], PlayerInfo[playerb][pRealName]);
SendClientMessage(playerid, -1, string);
return 1;
}

It shows no error while compiling and it is a mask system.
The purpose is that each user has his own Mask ID that is a random 6-digit number.
I run the script and everything seems fine, I can take off my mask and put it back on.

But when I join with two accounts, the names get messed up real bad.
Example:
[ID0] Justin has a mask on
[ID1] Anna has a mask on
I type: /behindmask 1 and it shows this:
Stranger 105 = AnJustin

Then as the two accounts have the mask on at the same time, one account copies the REAL NAME of the other account and when that account takes off their mask (Let's say Anna took off her mask), her real name becomes "stin" which is a part of Justin's name.

Someone help, cheers.

Chump
20/02/2016, 06:59 PM
GetPlayerName(playerid, string, sizeof(string));
strmid(PlayerInfo[playerid][pRealName], string, 0, strlen(string), 64);


strmid? What?

It isn't exactly the ideal function to use for string copying. It seems this is a habit commonly derived from Godfather edits. The problem is that strmid only copies characters up to strlen(string), so if anything was stored in pRealName previously, then any characters after strlen(string) would remain.

You could just use GetPlayerName to store the name directly:


GetPlayerName(playerid, PlayerInfo[playerid][pRealName], MAX_PLAYER_NAME);

nerovani
21/02/2016, 09:34 AM
After I connected with another account, and typed /behindmask 0, it showed me:
Stranger 117 = Just3_Lockwood

Then I took off the mask on the account of Justin and got this:
http://imgur.com/tNYTBXI

(That was after I changed the script with your suggestion)

nerovani
21/02/2016, 02:26 PM
Okay so I just realized all the values are scattered, it is making 0 sense to me.
This is a scriptfile for Justin:
Name = 74
MaskID = 117
Mask = 118

Any suggestions? :/

Chump
21/02/2016, 07:22 PM
How is "pRealName" defined in the enumerator? It should be:


pRealName[MAX_PLAYER_NAME]

nerovani
21/02/2016, 07:40 PM
How is "pRealName" defined in the enumerator? It should be:


pRealName[MAX_PLAYER_NAME]


enum pInfo
{
pRealName,
pMaskID,
pMask
}

new PlayerInfo[MAX_PLAYERS][pInfo];
new maskon[2];

nerovani
21/02/2016, 07:52 PM
It is fixed now, thank you.

But I just noticed another problem. When the server restarts and let's say Justin connects. He types /mask, but it tells him he doesn't have one (Justin disconnected before the server restart) although he got one before and it is saved in the scriptfile. It's like it isn't reading that value. Any suggestions on this issue?

Chump
21/02/2016, 07:54 PM
How is the data being read?

nerovani
21/02/2016, 07:58 PM
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Name",PlayerInfo[playerid][pRealName]);
INI_Int("MaskID",PlayerInfo[playerid][pMaskID]);
INI_Int("Mask",PlayerInfo[playerid][pMask]);
return 1;
}

Chump
21/02/2016, 08:01 PM
INI_String("Name", PlayerInfo[playerid][pRealName], MAX_PLAYER_NAME);
INI_Int("MaskID", PlayerInfo[playerid][pMaskID]);
INI_Int("Mask", PlayerInfo[playerid][pMask]);

nerovani
21/02/2016, 08:03 PM
Okay, but the "Mask" value is somehow being ignored, forcing players to /buymask everytime after server restart.

nerovani
21/02/2016, 08:34 PM
Nevermind, forgot to put the
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);

lmao, all works now perfectly.