Trying to make player nametags hide when they're crouched.
#1

However, it doesn't work. At all. Can anyone spot an issue? I've tried multiple methods.

pawn Code:
if ((newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH))
    {
        if(GameStatus == 2 && IsReady[playerid] == true)
        {
            if(PlayerCurrentlyCrouched[playerid] == false) // Not currently crouching.
            {
                PlayerCurrentlyCrouched[playerid] = true;
                for(new i=0; i < MAX_PLAYERS; i++)
                {
                    ShowPlayerNameTagForPlayer(i, playerid, 0);
                }
            }
            if(PlayerCurrentlyCrouched[playerid] == true) // If the player's crouching.
            {
                PlayerCurrentlyCrouched[playerid] = true;
                for(new i=0; i < MAX_PLAYERS; i++)
                {
                    ShowPlayerNameTagForPlayer(i, playerid, 1);
                }
            }
           
        }
    }
Reply
#2

You also need to hide nametags for streaming in players if you aren't already as a side note. Otherwise, print debug statements to see if the code actually gets executed.
Reply
#3

Try this:
PHP Code:
if ((newkeys KEY_CROUCH) && !(oldkeys KEY_CROUCH))
    {
        if(
GameStatus == && IsReady[playerid] == true)
        {
            if(
PlayerCurrentlyCrouched[playerid] == false// Not currently crouching.
            
{
                
PlayerCurrentlyCrouched[playerid] = true;
                for(new 
i=0MAX_PLAYERSi++)
                {
                    
ShowPlayerNameTagForPlayer(playeridi0); 
                }
            }
            if(
PlayerCurrentlyCrouched[playerid] == true// If the player's crouching.
            
{
                
PlayerCurrentlyCrouched[playerid] = true;
                for(new 
i=0MAX_PLAYERSi++)
                {
                    
ShowPlayerNameTagForPlayer(playeridi1);
                }
            }
            
        }
    }
public 
OnPlayerStreamIn(playeridforplayerid)
{
    if(
IsPlayerCurrentlyCrouched[playerid])
    {
        
ShowNameTagFprPlayer(playeridforplayerid0);
    }
    return 
1;

Reply
#4

Quote:
Originally Posted by ATGOggy
View Post
Try this:
PHP Code:
if ((newkeys KEY_CROUCH) && !(oldkeys KEY_CROUCH))
    {
        if(
GameStatus == && IsReady[playerid] == true)
        {
            if(
PlayerCurrentlyCrouched[playerid] == false// Not currently crouching.
            
{
                
PlayerCurrentlyCrouched[playerid] = true;
                for(new 
i=0MAX_PLAYERSi++)
                {
                    
ShowPlayerNameTagForPlayer(playeridi0); 
                }
            }
            if(
PlayerCurrentlyCrouched[playerid] == true// If the player's crouching.
            
{
                
PlayerCurrentlyCrouched[playerid] = true;
                for(new 
i=0MAX_PLAYERSi++)
                {
                    
ShowPlayerNameTagForPlayer(playeridi1);
                }
            }
            
        }
    }
public 
OnPlayerStreamIn(playeridforplayerid)
{
    if(
IsPlayerCurrentlyCrouched[playerid])
    {
        
ShowNameTagFprPlayer(playeridforplayerid0);
    }
    return 
1;

Thank you. My friend and I tried testing it before onplayerstreamin, and it didn't work. We'll try testing it with it in about an hour or so.

Quote:
Originally Posted by Abagail
View Post
You also need to hide nametags for streaming in players if you aren't already as a side note. Otherwise, print debug statements to see if the code actually gets executed.
Will try. Thank you.
Reply
#5

You are going to have a real hard time trying to detect this using keys why not use OnPlayerUpdate() and GetPlayerSpecialAction() best way.
Reply
#6

Quote:
Originally Posted by Pottus
View Post
You are going to have a real hard time trying to detect this using keys why not use OnPlayerUpdate() and GetPlayerSpecialAction() best way.
To my understanding, onplayerupdate uses a lot of resources. I was always told to avoid it.
Reply
#7

Complete non-sense this is where you SHOULD use it because you need this feature to be responsive when done correctly it won't use much of anything in terms of resources simply a drop of water in the pond. Why is that? Let me show you. You could even run this in a timer but then you are going to lose some response time OPU won't be a problem at all this is very light.

Code:
static bool:PlayerCrouching[MAX_PLAYERS];

public OnPlayerUpdate(playerid)
{
	if(PlayerCrouching[playerid])
	{
		// Player stopped crouching
	    if(GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK))
	    {
	        PlayerCrouching[playerid] = false;
	        // Unhide player label
	    }
	}
	else
	{
	    if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK))
	    {
	        PlayerCrouching[playerid] = true;
	        // Hide player labels
	    }
	
	}
	return 1;
}
Reply
#8

We really are in need of a proper tutorial for OPU, everyone thinks it uses "alot" of resources, everyone says avoid it, but it's one of great ( if not the best) callbacks of sa-mp that lets us do magic with it.

OPU gets called lets say 30 times a sec, thats 30 simple if(value) checks, way WAY less than a very simple loop all of us have in our scripts, thats the purpose of OPU, use it and enjoy it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)