Author Topic: If player in list  (Read 536 times)

Hello, is it possible to make like in a gui there is a list of ppl and is there a way to check if their name is in the list? then if their in the list the function for that will work?

Maaany functions for this, but here's 2 ways, one is unnessisarily complicated, the other not so much.

Complicated one
Code: [Select]
               for(%i=0;%i<ClientGroup.getCount();%i++)
                {
                        %cl = ClientGroup.getObject(%i);
                        if(%cl.name $= %cl.name)

Easier one :)
Code: [Select]
           if(isObject(findclientbyname(%asdf)))
            {
                %obj = findclientbyname(%asdf).player;
                %obj.commands(args);
            }

Example function
Code: [Select]
function servercmdslap(%this,%target)
{
   if(client.isAdmin)
     {
         if(isobject(findclientbyname(%target)))
           {
               obj.setVelocity(0 50 200);
            }
      }
}
« Last Edit: September 07, 2011, 06:31:23 PM by mp7964 »

Maaany functions for this, but here's 2 ways, one is unnessisarily complicated, the other not so much.

Complicated one
Code: [Select]
               for(%i=0;%i<ClientGroup.getCount();%i++)
                {
                        %cl = ClientGroup.getObject(%i);
                        if(%cl.name $= %cl.name)

Easier one :)
Code: [Select]
           if(isObject(findclientbyname(%asdf)))
            {
                %obj = findclientbyname(%asdf).player;
                %obj.commands(args);
            }

Example function
Code: [Select]
function servercmdslap(%this,%target)
{
   if(client.isAdmin)
     {
         if(isobject(findclientbyname(%target)))
           {
               obj.setVelocity(0 50 200);
            }
      }
}

Ty, i tell you if i got more problems.

mp i think after the first example you forgot what the point was.


How does the list work? An array? A file?

Code: [Select]
function findNameByPLID(%id) {
for(%i = 0; %i < NPL_List.rowCount(); %i++) {
%list = NPL_List.getRowText(%i);
%name = getField(%list,1);
%pid = getField(%list,3);
if(%id == %pid)
return %name;
}
return false;
}

function findIDByPLName(%name) {
if(strLen(%name)) {
for(%i = 0; %i < NPL_List.rowCount(); %i++) {
%list = NPL_List.getRowText(%i);
%pname = getField(%list, 1);
%id = getField(%list, 3);
if(strStr(%pname, %name) > -1)
return %id SPC %pname;
}
}
return -1;
}

function findNameByEither(%either) {
%PLID = findNameByPLID(%either);
%PLName = findIDByPLName(%either);
if(%PLName == 0 && %PLID != -1)
return %PLID;
else if(%PLID == -1 && firstWord(%PLName) != 0)
return restWords(%PLName);
return -1;
}

That's what I use for searching playerlist.