Mask System
#1

Hi. This is my code:
PHP код:
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(playeridstringsizeof(string));
        
strmid(PlayerInfo[playerid][pRealName], string0strlen(string), 64);
        
format(string,sizeof(string), "Stranger_%d"PlayerInfo[playerid][pMaskID]);
        
SetPlayerName(playeridstring);
        
MeMessage(playerid,"puts on their mask.");
        for(new 
0MAX_PLAYERSi++)
        {
            
ShowPlayerNameTagForPlayer(iplayerid0);
        }
    }
    else if(
maskon[playerid] == 1)
    {
        
SetPlayerName(playeridPlayerInfo[playerid][pRealName]);
        
maskon[playerid] = 0;
        
MeMessage(playerid,"takes off their mask.");
        for(new 
0MAX_PLAYERSi++)
        {
            
ShowPlayerNameTagForPlayer(iplayerid1);
        }
    }
return 
1;
}
CMD:behindmask(playeridparams[])
{
new 
playerbstring[128];
if(
sscanf(params"i"playerb)) return UsageMessage(playerid"/behindmask (playerid)");
format(stringsizeof(string), "Stranger %d = %s"PlayerInfo[playerb][pMaskID], PlayerInfo[playerb][pRealName]);
SendClientMessage(playerid, -1string);
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.
Reply
#2

pawn Код:
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:

pawn Код:
GetPlayerName(playerid, PlayerInfo[playerid][pRealName], MAX_PLAYER_NAME);
Reply
#3

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)
Reply
#4

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? :/
Reply
#5

How is "pRealName" defined in the enumerator? It should be:

pawn Код:
pRealName[MAX_PLAYER_NAME]
Reply
#6

Quote:
Originally Posted by Chump
Посмотреть сообщение
How is "pRealName" defined in the enumerator? It should be:

pawn Код:
pRealName[MAX_PLAYER_NAME]
Код:
enum pInfo
{
    pRealName,
    pMaskID,
    pMask
}

new PlayerInfo[MAX_PLAYERS][pInfo];
new maskon[2];
Reply
#7

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?
Reply
#8

How is the data being read?
Reply
#9

Код:
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;
}
Reply
#10

pawn Код:
INI_String("Name", PlayerInfo[playerid][pRealName], MAX_PLAYER_NAME);
INI_Int("MaskID", PlayerInfo[playerid][pMaskID]);
INI_Int("Mask", PlayerInfo[playerid][pMask]);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)