SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 17/05/2019, 07:46 PM   #1
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 815
Reputation: 68
Default Argument type mismatch

pawn Code:
function ListStaff(playerid)
{
    new rows = cache_num_rows(), pn[MAX_PLAYER_NAME], alvl, string[144], dialog[512];

    if(!rows) return 0; // no administrators found

    for(new i; i < rows; i ++)
    {
        cache_get_value(i, "Username", pn);
        cache_get_value_int(i, "AdminLevel", alvl);
       
        string = "Name\tStaff Level\tStatus";

        if(alvl)
        {
            if(IsPlayerConnected(pn))
            {
                format(string, sizeof(string), "%s\n%s\t%d\t"GREEN"Online"WHITE"", string, pn, alvl);
            }
            else
            {
                format(string, sizeof(string), "%s\n%s\t%d\t"RED"Offline"WHITE"", string, pn, alvl);
            }
            strcat(dialog, string);
        }
    }
    ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_TABLIST_HEADERS, "Staff", dialog, "Ok", "");
    return 1;
}

Getting that error here:

pawn Code:
if(IsPlayerConnected(pn))

Basically it's a function to list all staff members (online and offline), but i divided in 2 string, since i wanna show their status.
__________________


"A server owner shouldn't be embarrassed or have fear to request help, because we're humans and we never stop learning."
Symon is offline   Reply With Quote
Old 17/05/2019, 07:54 PM   #2
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 22
Default Re: Argument type mismatch

IsPlayerConnected expects an id(integer) not a name(string).
Plastikmensch is offline   Reply With Quote
Old 17/05/2019, 07:55 PM   #3
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 815
Reputation: 68
Default Re: Argument type mismatch

Oh you're right. Then how i can show all offline staff members and at same time the online ones?
__________________


"A server owner shouldn't be embarrassed or have fear to request help, because we're humans and we never stop learning."
Symon is offline   Reply With Quote
Old 17/05/2019, 08:10 PM   #4
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 22
Default Re: Argument type mismatch

There is probably a function in the useful functions thread that gets the id by name, but basically create a function that checks if a name is connected and return the id or more useful in this case return a string.
Something like:
Code:
IsNameConnected(pn)
{
   for(i=0,j=GetPlayerPoolSize();i<=j;i++)
   {
      new name[MAX_PLAYER_NAME];
      GetPlayerName(i,name,sizeof(name));
      //if someone is connected with name in database return 1 
      if(!strcmp(name,pn))
      {
         return 1;
      }
   }
   //if not return 0
   return 0;
}
or as I said return a string put %s in format where "Online" and "Offline" is and use the function.
You don't really need to create a function though, if you don't want to use it again.

Last edited by Plastikmensch; 17/05/2019 at 08:10 PM. Reason: typo
Plastikmensch is offline   Reply With Quote
Old 17/05/2019, 08:14 PM   #5
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 815
Reputation: 68
Default Re: Argument type mismatch

Quote:
or as I said return a string put %s in format where "Online" and "Offline" is and use the function.
Can you explain more or give me an example? I don't wanna to create another function.
__________________


"A server owner shouldn't be embarrassed or have fear to request help, because we're humans and we never stop learning."
Symon is offline   Reply With Quote
Old 17/05/2019, 08:47 PM   #6
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 22
Default Re: Argument type mismatch

Code:
//What I meant with return string:
SomeFittingNameForThis(pn)
{
  new name[MAX_PLAYER_NAME],connected[10]="Offline";
  for(new i=0,j=GetPlayerPoolSize();i<=j;i++)
  {
    GetPlayerName(i,name,sizeof(name)+1);
    if(!strcmp(name,pn))
    {
      connected="Online";
    }
  }
  return connected;
}
//and in format:
format(string, sizeof(string), "%s\n%s\t%d\t"RED"%s"WHITE"", string, pn, alvl,SomeFittingNameForThis(pn));
If you don't want to create a separate function you can do it like this:
Code:
//Liststaff function
if(alvl)
{
  //for every id connected it gets the name,
  //compares it with name in database,
  //if it matches connected is set to true and string is formatted accordingly
  new name[MAX_PLAYER_NAME],bool:connected;
  for(new i=0,j=GetPlayerPoolSize();i<=j;i++)
  {
    GetPlayerName(i,name,sizeof(name)+1);
    if(!strcmp(name,pn))
    {
      connected=true;
    }
  }
  if(connected) format(string, sizeof(string), "%s\n%s\t%d\t"RED"Online"WHITE"", string, pn, alvl);
  else format(string, sizeof(string), "%s\n%s\t%d\t"RED"Offline"WHITE"", string, pn, alvl);
  strcat(dialog, string);
}
Note: I don't know how samp assigns ids if someone disconnects and what name will be if id is not connected
(GetPlayerPoolSize only returns the highest id)
if(IsPlayerConnected(i)) before GetPlayerName is probably needed to be safe.
Plastikmensch is offline   Reply With Quote
Old 17/05/2019, 08:54 PM   #7
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 815
Reputation: 68
Default Re: Argument type mismatch

Maybe i'll use foreach instead of GetPlayerPoolSize.
__________________


"A server owner shouldn't be embarrassed or have fear to request help, because we're humans and we never stop learning."
Symon is offline   Reply With Quote
Old 17/05/2019, 09:02 PM   #8
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 22
Default Re: Argument type mismatch

That is completely up to you. I just wanted to give a quick example how that would work/of the basic principle.
Plastikmensch is offline   Reply With Quote
Old 17/05/2019, 09:04 PM   #9
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 815
Reputation: 68
Default Re: Argument type mismatch

Ok mh, sorry for double post. This is the situation:



I did some tweaks and it works, but i don't understand why it shows "Name" near Online/Offline status.

pawn Code:
function ListStaff(playerid)
{
    new rows = cache_num_rows(), pn[MAX_PLAYER_NAME], alvl, string[144], dialog[512];

    if(!rows) return 0; // no administrators found

    for(new i; i < rows; i ++)
    {
        cache_get_value(i, "Username", pn);
        cache_get_value_int(i, "AdminLevel", alvl);

        string = "Name\tStaff Level\tStatus";

        if(alvl)
        {
            new name[MAX_PLAYER_NAME],bool:connected;

            foreach(new j : Player)
            {
                GetPlayerName(j, name, sizeof(name)+1);
                if(!strcmp(name, pn)) connected = true;
            }
           
            if(connected) format(string, sizeof(string), "%s\n%s\t%d\t"GREEN"Online"WHITE"", string, pn, alvl);
            else format(string, sizeof(string), "%s\n%s\t%d\t"RED"Offline"WHITE"", string, pn, alvl);
            strcat(dialog, string);
        }
    }
    ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_TABLIST_HEADERS, "Staff", dialog, "Ok", "");
    return 1;
}
__________________


"A server owner shouldn't be embarrassed or have fear to request help, because we're humans and we never stop learning."
Symon is offline   Reply With Quote
Old 17/05/2019, 09:17 PM   #10
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 22
Default Re: Argument type mismatch

print functions help with that, to see what the string is. I don't get it either but maybe because of the "" behind WHITE? I guess you defined WHITE as "{FFFFFF}"? Which makes them obsolete and causes a bug? But I seriously don't get it. It looks like it should work.
//Edit
Oh, try to put string="..." outside the loop?
Plastikmensch is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assistance Needed | error 035: argument type mismatch (argument 2) KevTheJoker Scripting Help 4 14/01/2019 09:29 PM
D:\server\gamemodes\ExtremeGame.pwn(22326) : error 035: argument type mismatch (argument 2) enzulikeS Scripting Help 2 25/04/2018 03:38 PM
C:\Users\Lirbo\Desktop\Roleplay\gamemodes\ERP.pwn( 19) : error 035: argument type mismatch (argument 1) Lirbo Scripting Help 2 12/12/2014 02:51 PM
argument type mismatch (argument type 2) on sendclientmessage? Jack_Leslie Help Archive 2 31/07/2011 05:12 AM


All times are GMT. The time now is 10:24 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.