| Blockland Forums > Modification Help |
| If player in list |
| (1/1) |
| xcruso:
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? |
| mp7964:
Maaany functions for this, but here's 2 ways, one is unnessisarily complicated, the other not so much. Complicated one --- Code: --- for(%i=0;%i<ClientGroup.getCount();%i++) { %cl = ClientGroup.getObject(%i); if(%cl.name $= %cl.name) --- End code --- Easier one :) --- Code: --- if(isObject(findclientbyname(%asdf))) { %obj = findclientbyname(%asdf).player; %obj.commands(args); } --- End code --- Example function --- Code: ---function servercmdslap(%this,%target) { if(client.isAdmin) { if(isobject(findclientbyname(%target))) { obj.setVelocity(0 50 200); } } } --- End code --- |
| xcruso:
--- Quote from: mp7964 on September 07, 2011, 06:28:49 PM ---Maaany functions for this, but here's 2 ways, one is unnessisarily complicated, the other not so much. Complicated one --- Code: --- for(%i=0;%i<ClientGroup.getCount();%i++) { %cl = ClientGroup.getObject(%i); if(%cl.name $= %cl.name) --- End code --- Easier one :) --- Code: --- if(isObject(findclientbyname(%asdf))) { %obj = findclientbyname(%asdf).player; %obj.commands(args); } --- End code --- Example function --- Code: ---function servercmdslap(%this,%target) { if(client.isAdmin) { if(isobject(findclientbyname(%target))) { obj.setVelocity(0 50 200); } } } --- End code --- --- End quote --- Ty, i tell you if i got more problems. |
| otto-san:
mp i think after the first example you forgot what the point was. How does the list work? An array? A file? |
| MegaScientifical:
--- Code: ---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; } --- End code --- That's what I use for searching playerlist. |
| Navigation |
| Message Index |