loc command
#1

Hello,i've maked this loc command. (Show location of player)

pawn Код:
CMD:loc(playerid, params[])
{
if(IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"You can't use this command when you are dead or spawning.");
if(isnull(params))return SendClientMessage(playerid, 0xFF0000FF, "Usage: /loc [playerid]");
new target, current_zone;
current_zone = player_zone[target];
if(current_zone != -1 && IsPlayerConnected(target)) {
new playername[MAX_PLAYER_NAME],message2[170];
GetPlayerName(target,playername,MAX_PLAYER_NAME);
format(message2,sizeof(message2),"%s(%d)'s current location: %s",playername,target,zones[current_zone][zone_name]);
SendClientMessage(playerid,0x00C7FFAA,message2);
} else {
SendClientMessage(playerid,red,"Invalid Player ID");
}
return true;
}
I've some problems.

It shows location ONLY at id 0,so if i type /loc 1,2,3 etc... it shows only player id 0 location.
If i type an invalid id (ex: player offline),it shows again id 0.

What's wrong?
Reply
#2

This happened to me but it was solved by updating sscanf
Reply
#3

My sscanf is updated.
Reply
#4

This should work:

PHP код:
CMD:loc(playeridparams[])
{
    new 
id;
    new 
targetcurrent_zone;
    
current_zone player_zone[target];
    if(
sscanf(params"u"id))
    {
        
SendClientMessage(playerid0xFF0000FF"Usage: /loc [playerid]");
    }
    else
    {
        if(
current_zone != -&& IsPlayerConnected(target))
        {
            new 
playername[MAX_PLAYER_NAME],message2[170];
            
GetPlayerName(id,playername,MAX_PLAYER_NAME);
            
format(message2,sizeof(message2),"%s(%d)'s current location: %s",playername,target,zones[current_zone][zone_name]);
            
SendClientMessage(playerid,0x00C7FFAA,message2);
        }
        else
        {
            
SendClientMessage(playerid,red,"Invalid Player ID");
        }
    }

Reply
#5

not sure if this will change anything
pawn Код:
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, red, "USAGE: /loc [playerid]");
Reply
#6

Quote:
Originally Posted by Nuke547
Посмотреть сообщение
This should work:

PHP код:
CMD:loc(playeridparams[])
{
    new 
id;
    new 
targetcurrent_zone;
    
current_zone player_zone[target];
    if(
sscanf(params"u"id))
    {
        
SendClientMessage(playerid0xFF0000FF"Usage: /loc [playerid]");
    }
    else
    {
        if(
current_zone != -&& IsPlayerConnected(target))
        {
            new 
playername[MAX_PLAYER_NAME],message2[170];
            
GetPlayerName(id,playername,MAX_PLAYER_NAME);
            
format(message2,sizeof(message2),"%s(%d)'s current location: %s",playername,target,zones[current_zone][zone_name]);
            
SendClientMessage(playerid,0x00C7FFAA,message2);
        }
        else
        {
            
SendClientMessage(playerid,red,"Invalid Player ID");
        }
    }

Quote:
Originally Posted by googamalugafoo
Посмотреть сообщение
not sure if this will change anything
pawn Код:
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, red, "USAGE: /loc [playerid]");
Googamalugafoo, well that is actually a better coded way than the one above
Reply
#7

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
Googamalugafoo, well that is actually a better coded way than the one above
yeah i dont understand why he made it on multiple lines when it can be on one lol
Reply
#8

Delete your "return true;", and let only the "else"-statement be at the end!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)