Trying to make player nametags hide when they're crouched. -
rangerxxll - 23.10.2015
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);
}
}
}
}
Re: Trying to make player nametags hide when they're crouched. -
Abagail - 23.10.2015
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.
Re: Trying to make player nametags hide when they're crouched. -
ATGOggy - 23.10.2015
Try this:
PHP 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(playerid, i, 0);
}
}
if(PlayerCurrentlyCrouched[playerid] == true) // If the player's crouching.
{
PlayerCurrentlyCrouched[playerid] = true;
for(new i=0; i < MAX_PLAYERS; i++)
{
ShowPlayerNameTagForPlayer(playerid, i, 1);
}
}
}
}
public OnPlayerStreamIn(playerid, forplayerid)
{
if(IsPlayerCurrentlyCrouched[playerid])
{
ShowNameTagFprPlayer(playerid, forplayerid, 0);
}
return 1;
}
Re: Trying to make player nametags hide when they're crouched. -
rangerxxll - 23.10.2015
Quote:
Originally Posted by ATGOggy
Try this:
PHP 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(playerid, i, 0);
}
}
if(PlayerCurrentlyCrouched[playerid] == true) // If the player's crouching.
{
PlayerCurrentlyCrouched[playerid] = true;
for(new i=0; i < MAX_PLAYERS; i++)
{
ShowPlayerNameTagForPlayer(playerid, i, 1);
}
}
}
}
public OnPlayerStreamIn(playerid, forplayerid)
{
if(IsPlayerCurrentlyCrouched[playerid])
{
ShowNameTagFprPlayer(playerid, forplayerid, 0);
}
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
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.
Re: Trying to make player nametags hide when they're crouched. -
Pottus - 23.10.2015
You are going to have a real hard time trying to detect this using keys why not use OnPlayerUpdate() and GetPlayerSpecialAction() best way.
Re: Trying to make player nametags hide when they're crouched. -
rangerxxll - 23.10.2015
Quote:
Originally Posted by Pottus
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.
Re: Trying to make player nametags hide when they're crouched. -
Pottus - 23.10.2015
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;
}
Re: Trying to make player nametags hide when they're crouched. -
PrO.GameR - 23.10.2015
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.