03.07.2013, 13:33
Hello. Didn't know how to subject this better...
I'm working on a script which will only show a players nametag for another player once he's aimed simultaneously on the player for 2,5 seconds. This is what I got so far:
EDIT: Right now, this works for playerid 0 but no one else.
I'm working on a script which will only show a players nametag for another player once he's aimed simultaneously on the player for 2,5 seconds. This is what I got so far:
pawn Код:
#include <a_samp>
#include <YSI\y_hooks>
new aimid[MAX_PLAYERS];
new aimtime[MAX_PLAYERS];
new aimtimer;
hook OnPlayerSpawn(playerid)
{
for(new i=0; i<MAX_PLAYERS; i++)
{
ShowPlayerNameTagForPlayer(playerid,i,false); //DISABLES EVERYONES NAMETAGS FOR THE PLAYER
ShowPlayerNameTagForPlayer(i,playerid,false); //DISABLES THE PLAYERS NAMETAG FOR EVERYONE ELSE.
}
return 1;
}
hook OnPlayerUpdate(playerid)
{
new aimID = GetPlayerTargetPlayer(playerid); //GET THE PLAYER'S TARGET
if(aimID == aimid[playerid]) return 1; //PREVENT THE TIMER FROM STARTING IF ALREADY STARTED, CREATING 1247375735 DIFFERENT TIMERS
if(aimID != INVALID_PLAYER_ID && aimtime[playerid] == 0) //CHECK IF PLAYER IS AIMING ON SOMEONE AND IF PLAYER ISNT AIMING AT SOMEONE ELSE
{
aimtimer = SetTimerEx("Aimtime",500,1,"uu",playerid,aimID); // START THE TIMER TO CHECK IF THE PLAYER SIMULTANEOUSLY AIMS AT THE TARGET FOR 2,5 SECONDS
aimid[playerid] = aimID; //DEFINES THAT PLAYER IS AIMING, USED FOR PREVENTING TIMER REPEAT
}
return 1;
}
forward Aimtime(playerid,aimID);
public Aimtime(playerid,aimID)
{
if(GetPlayerTargetPlayer(playerid) != aimid[playerid]) return KillTimer(aimtimer); //CHECK IF PLAYER HAS STOPPED AIMING ON THE TARGET, IF SO, CANCEL TIMER.
if(aimtime[playerid] == 5) //IF THE PLAYER HAS AIMED ON THE TARGET SIMULTANEOUSLY FOR 2,5 SECONDS, SHOW THE TARGETS NAMETAG FOR 5 SECONDS.
{
ShowPlayerNameTagForPlayer(playerid,aimid[playerid],true); //SHOWS THE TARGETS NAMETAG
SetTimerEx("Hidenametag",5000,0,"uu",playerid,aimid[playerid]); //SETS A TIMER TO DISABLE THE NAMETAG AFTER 5 SECONDS.
}
aimtime[playerid] ++; //IF THE PLAYER HASNT AIMED FOR 2,5 SECONDS YET, COUNT +1.
return 1;
}
forward Hidenametag(playerid,aimID);
public Hidenametag(playerid,aimID)
{
ShowPlayerNameTagForPlayer(playerid,aimid[playerid],false); //HIDES THE NAMETAG FOR THE PLAYER
aimtime[playerid] = 0; //SETS AIMTIME TO 0, MAKING IT POSSIBLE FOR THE PLAYER TO IDENTIFY SOMEONE ELSE.
aimid[playerid] = -1; //SETS THE AIMID TO -1, = NO PLAYER.
return 1;
}