Annoying /mask problem :/
#1

Guys this is my /mask cmd:

pawn Код:
if (strcmp("/mask", cmdtext, true, 5) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
        if(Masked[playerid] == 0)
        {
            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(i))
                {
                    ShowPlayerNameTagForPlayer(i, playerid, 0);
                }
            }
            ApplyAnimation(playerid, "SHOP", "ROB_Shifty", 4.1,0,0,0,0,0); // Anim to avoid bug when Animations doesn't apply
            Masked[playerid] = 1;
            MaskTimer[playerid] = SetTimerEx("MaskAnim", 100, false, "i", playerid); // Timer for Applying animation and triggering another timer
            msk[0] = SetPlayerAttachedObject(playerid, 1, 19037, 5, 0.067999, 0.030000, 0.026000, 105.800018, 87.500038, 30.699975,1.000000,1.000000,1.000000,0,0); // Mask in left hand, so it's looking cool with Animation..
            SendClientMessage(playerid, COLOR_LIGHTGREEN, "ON");
            return 1;
        }
        else if(Masked[playerid] == 1) // If player will write /mask again his mask will be removed
        {
            if(IsPlayerConnected(playerid))
            {
                for(new i = 0; i < MAX_PLAYERS; i++)
                {
                    if(IsPlayerConnected(playerid))
                    {
                        ShowPlayerNameTagForPlayer(i, playerid, 1); // Showing player's tag for other player
                    }
                }
                Masked[playerid] = 0;
                ClearAnimations(playerid); // To avoid bugging /mask if player spam /mask CMD
                KillTimer(MaskTimer[playerid]); // To avoid bugging /mask if player spam /mask CMD
                KillTimer(MaskTime[playerid]); // Same as above..
                if(IsPlayerAttachedObjectSlotUsed(playerid, 1)) RemovePlayerAttachedObject(playerid, msk[1]); // Removing his mask
                SendClientMessage(playerid, COLOR_LIGHTGREEN, "OFF");
                return 1;
            }
        }
        }
        return 1;
    }
but if player change interior, his name is visible again, and sometimes it doesn't hide player's name, I mean it hide it for some ppl and for some not, how should I fix that ? :/
Reply
#2

Yeah, the NameTag system is not the greatest.

Create a timer on OnPlayerLogin or OnPlayerConnect that checks every 5 seconds (or whatever seems good to you) to see if they own a mask (and one that is on), and if so, have it run:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++) ShowPlayerNameTagForPlayer(playerid, i, false);
You can also have it check (not in a timer) if they own a mask (and one that is on), and if so, have it run:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++) ShowPlayerNameTagForPlayer(playerid, i, false);
when they enter certain interiors or under OnPlayerUpdate.
Reply
#3

You can use OnPlayerUpdate I guess and check if they have a mask, etc. The code for that is below:

Код:
public OnPlayerUpdate(playerid)
{
if(Masked[playerid] == 1)
{
for(new i = 0; i < MAX_PLAYERS; i++)
                {
                    if(IsPlayerConnected(playerid))
                    {
                        ShowPlayerNameTagForPlayer(i, playerid, 0); // Showing player's tag for other player
                    }
                }
}
else return 1;
}
The issue is probably the players logged in after they typed [/mask]. Since they weren't on the server when ShowPlayerNameTagForPlayer was called, it didn't affect them.

EDIT: johnjohnsonusa beat me to it... But yeah, you can use a timer or this way... (My way is better, hehe).
Reply
#4

What's up buddy? I'll write a fix for this tomorrow if you can't get it working properly.

For now, try this(untested);

Код:
//add this stock anywhere in your script, I would do it where the other stocks are.
//If you don't have any stocks yet, just put this at the very bottom so you can find it easily.
stock MaskFix(playerid)
{
            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(i))
                {
                    ShowPlayerNameTagForPlayer(i, playerid, 0);
                }
            }
}

// then look for OnPlayerInteriorChange
//Make it look like this.

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    MaskFix(playerid);
    return 1;
}
This should fix it, however I've never used this callback, therefore it might only work when entering or when exiting an interior, however it should work perfectly as I don't see why it wouldn't...

Also, this will only fix the interior bug, obviously it's not gonna do anything if for example when a player gets in a vehicle.

Anytime the mask disappears, you can use MaskFix(playerid); inside it's callback.

So, if it disappeared when a player entered a vehicle, just put MaskFix(playerid) inside OnPlayerEnterVehicle
and OnPlayerExitVehicle, etc.

If you do it under onplayerupdate as mentioned before, it will work, but it will CONSTANTLY run that function like once every 2 seconds or something. This could cause your server to lag out, basically like DOSing yourself.
Reply
#5

Or for the easiest way... that is 100% to work.. Put it under OnPlayerStreamIn maybe??
pawn Код:
public OnPlayerStreamIn(playerid, forplayerid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(Masked[i] == 1)
            {
                ShowPlayerNameTagForPlayer(playerid, i, 0);
            }
        }
    }
    return 1;
}
Reply
#6

Thank you guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)