SA-MP Forums Archive
argument type mismatch (argument 1) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: argument type mismatch (argument 1) (/showthread.php?tid=623965)



argument type mismatch (argument 1) - Cerealguy - 08.12.2016

PHP код:
error 035argument type mismatch (argument 1)
if(
IsPlayerConnected(GetPlayerID(targetid))) // ERROR
stock GetPlayerID(playername[])
{
  for(new 
i=GetPlayerPoolSize(); != -1i--)
  {
    if(
IsPlayerConnected(i))
    {
      if(
strcmp(GetPlayerName(i), playernametruestrlen(playername)) == 0)
      {
        return 
i;
      }
    }
  }
  return 
INVALID_PLAYER_ID;

ї?,


Re: argument type mismatch (argument 1) - AroseKhanNiazi - 08.12.2016

if(IsPlayerConnected(GetPlayerID(targetid))) could you show me what you are using for 'targetid' ?


Re: argument type mismatch (argument 1) - iLearner - 08.12.2016

You have to pass a string, by 'targetid' I assume you're passing a Integer.


Respuesta: argument type mismatch (argument 1) - Cerealguy - 08.12.2016

PHP код:
new targetid[MAX_PLAYER_NAME], reason[50];

if(
sscanf(params"s[24]s[50]"targetidreason)) 



Re: argument type mismatch (argument 1) - iamjems - 08.12.2016

PHP код:
stock IsOnline(text[])
{
    new
        
strPos,
        
returnID 0,
        
boolisnum true;
    while(
text[strPos]) {
        if(
isnum) {
            if(
'0' <= text[strPos] <= '9'returnID = (returnID 10) + (text[strPos] - '0');
            else 
isnum false;
        }
        
strPos++;
    }
    if(
isnum) {
        if(
IsPlayerConnected(returnID)) return returnID;
    }
    else {
        new
            
sz_playerName[MAX_PLAYER_NAME];
        foreach(
Playeri) {
            
GetPlayerName(isz_playerNameMAX_PLAYER_NAME);
            if(!
strcmp(sz_playerNametexttruestrPos)) return i;
        }
    }
    return 
INVALID_PLAYER_ID;
}
// Later on:
new target IsOnline(targetid);
if(
IsPlayerConnected(target))
{
      ...




Re: Respuesta: argument type mismatch (argument 1) - Yaa - 08.12.2016

Quote:
Originally Posted by Cerealguy
Посмотреть сообщение
PHP код:
new targetid[MAX_PLAYER_NAME], reason[50];
if(
sscanf(params"s[24]s[50]"targetidreason)) 
serious ?

PHP код:
new targetid[MAX_PLAYERS_NAME];
if(
sscanf(params"s[24]"targetid)) 



Re: Respuesta: argument type mismatch (argument 1) - AroseKhanNiazi - 08.12.2016

Quote:
Originally Posted by Yaa
Посмотреть сообщение
serious ?

PHP код:
new targetid[MAX_PLAYERS_NAME];
if(
sscanf(params"s[24]"targetid)) 
can you explain what's wrong in his code? Because I can't find why he can't use reason?


Re: Respuesta: argument type mismatch (argument 1) - oMa37 - 08.12.2016

Quote:
Originally Posted by AroseKhanNiazi
Посмотреть сообщение
can you explain what's wrong in his code? Because I can't find why he can't use reason?
You doubt in the 'SA-MP Lead Scripter' code? How dare you?!


OT: Just use the specifier in the sscanf check, You can use both ID and player name in the sscanf's specifier 'u'. That if you are trying for example kick a player by his name.


Quote:
Originally Posted by iamjems
Посмотреть сообщение
PHP код:
// woah 
Why all that? Just use this;

PHP код:
GetID(name[])
{
    for(new 
iGetPlayerPoolSize(); <= ji++) // or foreach(new i : Player)
    
{
        if(!
strcmp(GetName(i), nametrue)) return i;
    }
    return 
INVALID_PLAYER_ID;
}
GetName(playerid)
{
    new 
pName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNameMAX_PLAYER_NAME);
    return 
pName;




Re: argument type mismatch (argument 1) - AroseKhanNiazi - 08.12.2016

Yep using 'u' makes lot more sense or 'r' if you don't wanna include NPC's in it.


Respuesta: Re: argument type mismatch (argument 1) - Cerealguy - 08.12.2016

Quote:
Originally Posted by oMa37
Посмотреть сообщение
You doubt in the 'SA-MP Lead Scripter' code? How dare you?!


OT: Just use the specifier in the sscanf check, You can use both ID and player name in the sscanf's specifier 'u'. That if you are trying for example kick a player by his name.




Why all that? Just use this;

PHP код:
GetID(name[])
{
    for(new 
iGetPlayerPoolSize(); <= ji++) // or foreach(new i : Player)
    
{
        if(!
strcmp(GetName(i), nametrue)) return i;
    }
    return 
INVALID_PLAYER_ID;
}
GetName(playerid)
{
    new 
pName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNameMAX_PLAYER_NAME);
    return 
pName;

Quote:
Originally Posted by AroseKhanNiazi
Посмотреть сообщение
Yep using 'u' makes lot more sense or 'r' if you don't wanna include NPC's in it.
thanks bro's!, fix.

PHP код:
stock GetPlayerID(playername[])
{
  for(new 
i=GetPlayerPoolSize(); != -1i--)
  {
      if(
strcmp(GetPlayerName(i), playernametruestrlen(playername)) == 0) return i;
  }
  return 
INVALID_PLAYER_ID;