if(sscanf(params, "u", targetid))
#1

How to make /locate command also works without typing the playerid that i want to locate.
example:
/locate 4 --> Player 4 location is %s
/locate (without ID) --> your location is %s

so how to make it work for me also ?

pawn Код:
CMD:locate(playerid,params[])
{
    new string[128], targetid;
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_WHITE, "/locate [playerid]");
    format(string,sizeof(string),"his location is %s", GetPlayerZone(targetid));
    SendClientMessage(playerid,COLOR_WHITE,string);
    return 1;
}
Reply
#2

pawn Код:
CMD:locate(playerid,params[])
{
    new string[128], targetid;
    if(sscanf(params, "u", targetid)) format(string,sizeof(string),"your location is %s", GetPlayerZone(playerid));
    else format(string,sizeof(string),"his location is %s", GetPlayerZone(targetid));
    SendClientMessage(playerid,COLOR_WHITE,string);
    return 1;
}
Reply
#3

pawn Код:
CMD:locate(playerid,params[])
{
    new string[128], targetid;
    if(sscanf(params, "u", targetid))
    {
        format(string,sizeof(string),"You location is %s", GetPlayerZone(playerid));
        SendClientMessage(playerid,COLOR_WHITE,string);
        return 1;
    }
    format(string,sizeof(string),"Targets location is %s", GetPlayerZone(targetid));
    SendClientMessage(playerid,COLOR_WHITE,string);
    return 1;
}
Simple as this. Instead of sending a message with the usage, you just show your own location.
Reply
#4

lol i'm really stupid, i didn't think of that :D
that's really easy haha
Reply
#5

You didn't check if the targetid is connected.
Reply
#6

pawn Код:
CMD:locate(playerid,params[])
{
    new string[128], targetid;
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_WHITE, "[playerid]");
    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_WHITE,"Player is not connected");
    format(string,sizeof(string),"Targets location is %s", GetPlayerZone(targetid));
    SendClientMessage(playerid,COLOR_WHITE,string);
    return 1;
}
Reply
#7

pawn Код:
CMD:locate(playerid, params[])
{
    if (isnull(params))
    {
        new
            string[64];
        format(string, sizeof (string),"Your location is %s", GetPlayerZone(playerid));
        SendClientMessage(playerid, COLOR_WHITE, string);
    }
    else
    {
        new
            targetid;
        if (!sscanf(params, "u", targetid))
        {
            if (targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_WHITE, "Invalid player");
            new
                string[64];
            format(string, sizeof (string), "Target's location is %s", GetPlayerZone(targetid));
            SendClientMessage(playerid, COLOR_WHITE, string);
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)