| Blockland Forums > Modification Help |
| Get clients in server |
| << < (3/3) |
| ThinkInvisible:
--- Quote from: lilboarder32 on March 25, 2011, 09:31:00 PM ---What exactly are you trying to do? You can get the names from the Player List: --- Code: ---for(%i=0;%i<NPL_List.rowCount();%i++) { %name = getField(NPL_List.getRowText(%i),1); //Do stuff with name? } --- End code --- --- End quote --- THANK YOU. THANK YOU SO MUCH. |
| MegaScientifical:
Wait, Think... You were really looking for that? This is what I use: --- 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) { for(%i = 0; %i < NPL_List.rowCount(); %i++) { %list = NPL_List.getRowRext(%i); %pname = getField(%list, 1); %id = getField(%list, 3); if(strStr(%pname, %name) > -1 && strLen(%name)) 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); else return -1; } --- End code --- The either check, I was planning to use so I could enter either into some chat command and the name from both. That way, I could either use part of the name or an ID for full name. Mostly for people with odd characters in their name, although the they make their name 100% odd characters. |
| ThinkInvisible:
--- Quote from: MegaScientifical on March 26, 2011, 05:14:40 AM ----gianteffingsnip- --- End quote --- ...Just look at my code and you'll understand what i needed. --- Code: ---function returnPlayers(%IDname) { //Blah blah blah if(!%IDname $= "ID" && !%IDname $= "name") { //If %IDname isn't the proper value... echo("Error running returnPlayers : Please enter ID or Name."); //Notify the user return; //End command } //Moarblahblahblah %count = NPL_list.rowCount(); //Get the number of players for(%i=0;%i<%count;%i++) //For loop. { //Blah %listname = %listname@" "@strReplace((getField(NPL_List.getRowText(%i),1))," ","_"); //Append this to listname %listid = %listid@" "@(getField(NPL_List.getRowText(%i),3)); //Append this to listID } //asf. if(%IDname $= "ID") { //If the case is ID... if(!%listID) {echo("ERROR : No players can be found.");} //Uh oh. return(%count@%listID); //Append the count to the start for tagging purposes. Return ID list. } //Fasf. if(%IDname $= "name") { //If the case is name... if(!%listname) {echo("ERROR : No players can be found.");} //Oh noes! return(%count@%listname); //Return this thing. } //Stuff. } //Stuffy stuff. --- End code --- Edit : Added comments and stuff. And stuffy stuff. Editedit : Woo. Pagestretch. |
| MegaScientifical:
--- Code: ---function returnPlayers(%IDname) { switch$(%IDName) { case "ID": %field = 1; case "name": %field = 3; default: echo("\c3Error running returnPlayers : Please enter ID or Name."); return; } %count = NPL_list.rowCount(); for(%i = 0; %i < %count; %i++) %list = %list SPC strReplace(getField(NPL_List.getRowText(%i), %field), " ", "_"); if(strLen(trim(%list))) return %count @ %list; else echo("\c3Error running returnPlayers : No players can be found."); } --- End code --- Simplified it. Probably can be simplified more. |
| Xalos:
Late by a few days, but the two %fields defined should be reversed: You have it set up to return the IDs for "name" and the names for "ID". |
| Navigation |
| Message Index |
| Previous page |