SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 23/10/2015, 01:46 AM   #1
rangerxxll
Gangsta
 
rangerxxll's Avatar
 
Join Date: Aug 2011
Posts: 882
Reputation: 59
Default Trying to make player nametags hide when they're crouched.

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);
                }
            }
           
        }
    }
__________________

Server Website: http://www.pgagaming.net/forums/
Server IP:87.98.241.207:7024
rangerxxll is offline   Reply With Quote
Old 23/10/2015, 01:50 AM   #2
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,182
Reputation: 442
Default Re: Trying to make player nametags hide when they're crouched.

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.
Abagail is offline   Reply With Quote
Old 23/10/2015, 02:07 AM   #3
ATGOggy
Gangsta
 
Join Date: Sep 2014
Location: Ls-rcr
Posts: 850
Reputation: 52
Default Re: Trying to make player nametags hide when they're crouched.

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;

__________________
******: "I've said this before. People think that MySQL is some simple plug-and-play magic bullet that you can use to just make your mode instantly better. They don't realise that the "L" in "SQL" means "language". So instead of programming PAWN, and using a bit of this mystery thing, you are now programming in two languages at once. If you spend months learning PAWN, you should spend the same time learning SQL, if not more - it is probably the more complex of the two languages, and not something that just gets bolted on to the side."


I give and want only fair reps. I hate this: "hey bro, I rep you, rep me plz

Click below if you wanna be amazed:
http://Paid2Refer.com/ref.php?refId=291262
ATGOggy is offline   Reply With Quote
Old 23/10/2015, 02:46 AM   #4
rangerxxll
Gangsta
 
rangerxxll's Avatar
 
Join Date: Aug 2011
Posts: 882
Reputation: 59
Default Re: Trying to make player nametags hide when they're crouched.

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.
__________________

Server Website: http://www.pgagaming.net/forums/
Server IP:87.98.241.207:7024
rangerxxll is offline   Reply With Quote
Old 23/10/2015, 03:41 AM   #5
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,857
Reputation: 1292
Default Re: Trying to make player nametags hide when they're crouched.

You are going to have a real hard time trying to detect this using keys why not use OnPlayerUpdate() and GetPlayerSpecialAction() best way.
Pottus is offline   Reply With Quote
Old 23/10/2015, 04:40 AM   #6
rangerxxll
Gangsta
 
rangerxxll's Avatar
 
Join Date: Aug 2011
Posts: 882
Reputation: 59
Default Re: Trying to make player nametags hide when they're crouched.

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.
__________________

Server Website: http://www.pgagaming.net/forums/
Server IP:87.98.241.207:7024
rangerxxll is offline   Reply With Quote
Old 23/10/2015, 06:19 AM   #7
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,857
Reputation: 1292
Default Re: Trying to make player nametags hide when they're crouched.

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;
}
Pottus is offline   Reply With Quote
Old 23/10/2015, 08:37 AM   #8
PrO.GameR
Gangsta
 
PrO.GameR's Avatar
 
Join Date: Oct 2012
Posts: 695
Reputation: 121
Default Re: Trying to make player nametags hide when they're crouched.

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.
__________________
Blueberry Prison Roleplay will be back soon!
Follow the forums for more information about opening day.

Forums
PrO.GameR is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make textdraw hide after 10 seconds? lQs Scripting Help 3 05/05/2013 06:29 PM
Hide Player Name CaTaLinU Scripting Help 4 04/09/2012 10:29 AM
hide player MA_proking Scripting Help 4 18/02/2012 09:51 AM
How I can hide the Player Name? ]B4E[kengston Help Archive 2 20/02/2011 07:01 PM
welcome msg not hide for second player [SOB]Chris Help Archive 1 19/07/2009 08:54 PM


All times are GMT. The time now is 06:15 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.