Fixing parameter cmds
#1

how can i fix this?

PHP код:
   CMD:afk(playerid,params[])
    {
        new 
targetidstring[128];
        if(
sscanf(params,"d",targetidparams[0])) return SendClientMessage(playerid, -1,"CMD: /afk [ID]");
          if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid,-1,""COL_RED"Player is not online!");
        if(
IsPlayerMoving(params[0]) == 0)
        {
            
format(stringsizeof(string), "%s is AFK for %d seconds",PlayerName(targetid), AFKTime[params[0]]);
            
SendClientMessage(playerid,-1,string);
        }
        else
        {
            
SendClientMessage(playerid,-1,"This player is not AFK");
        }
        return 
1;
    } 
In serverlogs it shows wrong parameter.
Reply
#2

You have 2 parameters but you use only "d".
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
Why are you using `params[0]`?
PHP код:
new bool:AFK[MAX_PLAYERS];
new 
AFKTime[MAX_PLAYERS];
public 
OnPlayerConnect(playerid)
{
     
AFKTime[playerid] = 0;
     
AFK[playerid] = false;
forward OneSecTimer(playerid);
public 
OneSecTimer(playerid)
    {
        if(
IsPlayerMoving(playerid) == 0)
        {
            
AFK[playerid] = true;
            
AFKTime[playerid]++;
        }
        else
        {
             
AFK[playerid] = false;
             
AFKTime[playerid] = 0;
        }
        return 
1;
    }
  
CMD:afk(playerid,params[])
    {
        new 
targetidstring[128];
        if(
sscanf(params,"d",targetidparams[0])) return SendClientMessage(playerid, -1,"CMD: /afk [ID]");
          if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid,-1,""COL_RED"Not online!");
        if(
IsPlayerMoving(params[0]) == 0)
        {
            
format(stringsizeof(string), "%s is afk for %d seconds",PlayerName(targetid), AFKTime[params[0]]);
            
SendClientMessage(playerid,-1,string);
        }
        else
        {
            
SendClientMessage(playerid,-1,"Not afk");
        }
        return 
1;
    } 
Reply
#4

Try using
PHP код:
   CMD:afk(playerid,params[])
    {
        new 
targetidstring[128];
        if(
sscanf(params,"d",targetidtargetid)) return SendClientMessage(playerid, -1,"CMD: /afk [ID]");
          if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid,-1,""COL_RED"Player is not online!");
        if(
IsPlayerMoving(targetid) == 0)
        {
            
format(stringsizeof(string), "%s is AFK for %d seconds",PlayerName(targetid), AFKTime[targetid]);
            
SendClientMessage(playerid,-1,string);
        }
        else
        {
            
SendClientMessage(playerid,-1,"This player is not AFK");
        }
        return 
1;
    } 
better than params[0]
Reply
#5

Quote:
Originally Posted by v1k1nG
Посмотреть сообщение
Try using
PHP код:
   CMD:afk(playerid,params[])
    {
        new 
targetidstring[128];
        if(
sscanf(params,"d",targetidtargetid)) return SendClientMessage(playerid, -1,"CMD: /afk [ID]");
          if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid,-1,""COL_RED"Player is not online!");
        if(
IsPlayerMoving(targetid) == 0)
        {
            
format(stringsizeof(string), "%s is AFK for %d seconds",PlayerName(targetid), AFKTime[targetid]);
            
SendClientMessage(playerid,-1,string);
        }
        else
        {
            
SendClientMessage(playerid,-1,"This player is not AFK");
        }
        return 
1;
    } 
better than params[0]
Should be like this.
Код:
if(sscanf(params,"d",targetid)) return SendClientMessage(playerid, -1,"CMD: /afk [ID]");
Reply
#6

I just hit Ctrl+v twice
Reply
#7

I can not understand why you use 2 times "targetid" if you have only one parameter ..

Код:
if(sscanf(params, "d", targetid))
Reply
#8

How, it shows targetid that he is not AFK even the player is not moving.
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
We need to see your `IsPlayerMoving` function.
Singlest function i have is those


PHP код:
forward OneSecTimer(playerid);
public 
OneSecTimer(playerid)
    {
        if(
IsPlayerMoving(playerid) == 0)
        {
            
AFK[playerid] = true;
            
AFKTime[playerid]++;
        }
        else
        {
             
AFK[playerid] = false;
             
AFKTime[playerid] = 0;
        }
        return 
1;
    } 
Reply
#10

There are some includes to detect that, I found this
https://sampforum.blast.hk/showthread.php?tid=525585
seems to work, I am not using it though
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)