Identify Player...
#1

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:

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;
}
EDIT: Right now, this works for playerid 0 but no one else.
Reply
#2

Types of values are wrong. SetTimerEx doesn't have "u" type.

https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#3

Switched to:
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 AMAING ON SOMEONE AND IF PLAYER ISNT AIMING AT SOMEONE ELSE
    {
        aimtimer = SetTimerEx("Aimtime",500,1,"dd",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,"dd",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;
}
Still bugs a bit for some players. Also, some players have their nametags shown from spawn and some are hidden.
Reply
#4

Your script is a chaos. You're storing timer IDs for each player in one variable. That will cause some timers to run infinitely until your server starts lagging and dies. Make each timer ID player specific, and when you kill a timer, you should reset aimid and aimtime.

Also, why are you passing aimID to the function and then not use it?
Reply
#5

pawn Код:
#include <a_samp>
#include <YSI\y_hooks>
#include <OPTP>

new aimid[MAX_PLAYERS];
new aimtime[MAX_PLAYERS];
new aimtimer[MAX_PLAYERS];

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

/*public OnPlayerTargetPlayer(playerid,newtarget,oldtarget)
{
    if(newtarget != INVALID_PLAYER_ID && aimtime[playerid] == 0)
    {
        aimtimer = SetTimerEx("Aimtime",500,1,"dd",playerid,newtarget); // START THE TIMER TO CHECK IF THE PLAYER SIMULTANEOUSLY AIMS AT THE TARGET FOR 2,5 SECONDS
        aimid[playerid] = newtarget; //DEFINES THAT PLAYER IS AIMING, USED FOR PREVENTING TIMER REPEAT
        aimtime[playerid] = 1;
    }
    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 AMAING ON SOMEONE AND IF PLAYER ISNT AIMING AT SOMEONE ELSE
    {
        aimtimer[playerid] = SetTimerEx("Aimtime",500,1,"dd",playerid); // 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
        aimtime[playerid] = 1;
    }
    return 1;
}

forward Aimtime(playerid);
public Aimtime(playerid)
{
    if(GetPlayerTargetPlayer(playerid) != aimid[playerid])
    {
        KillTimer(aimtimer[playerid]); //CHECK IF PLAYER HAS STOPPED AIMING ON THE TARGET, IF SO, CANCEL TIMER.
        aimtime[playerid] = 0;
        aimid[playerid] = -1;
        return 1;
    }
    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,"dd",playerid,aimid[playerid]); //SETS A TIMER TO DISABLE THE NAMETAG AFTER 5 SECONDS.
        KillTimer(aimtimer[playerid]);
        return 1;
    }
    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,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;
}
Fixed up the variable, resetted aimid and aimtime on timerkill. And removed AimID passing through the timer.

Still doesn't work :/
Reply
#6

Idk why it doesn't work. You should debug it - fill it with SendClientMessages and see which ones are sent and which ones aren't. Then make conclusions.
Reply
#7

Sorry for bumping old topic. May be someone interested and need a fix for this.
Default value for each aimid[MAX_PLAYERS] array element must be "INVALID_PLAYER_ID" or "-1"
So, you should add to OnPlayerConnect this:
Код:
aimid[playerid] = INVALID_PLAYER_ID
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)