Author Topic: UI Name Table for playertypes? [Solved]  (Read 936 times)

EDIT: Solved but highly inefficient. Please see this post: http://forum.blockland.us/index.php?topic=190126.msg5103849#msg5103849
solved

So the client-sided UI Name Table has values for bricks, emitters, items, lights, music, and vehicles:
Code: [Select]
$uiNameTable["4x8F"] = "258";
$uiNameTable_Emitters["Arrow Stick"] = "1176";
$uiNameTable_Items["bow"] = "1182";
$uiNameTable_Lights["Blue Light"] = "1349";
$uiNameTable_Music["After School Special"] = "1483";
$uiNameTable_Vehicle["Ball"] = "1248";

This lets you find the IDs for those types of objects.. But what about playertypes? How would I get the playertype's ID from its name, client-side?
« Last Edit: April 06, 2012, 12:13:12 AM by Greek2me »

tree()?
also loop through serverconnection section?

tree()?
also loop through serverconnection section?
Cool, I didn't know about tree() before. That's useful.

I still didn't find anything about the playertype list though.

I still need help with this.

Code: [Select]
function getPlayerData()
{
for(%i = 0; %i < serverconnection.getCount(); %i++) //For loop that will loop through every serverconnect object.
{
if(serverconnection.getObject(%i).ClassName $= "PlayerData" && serverconnection.getObject(%i).uiname !$= "") //if the serverconnection object is a player AND has a uiname
{
echo("Located PlayerData:  " SPC serverconnection.getobject(%i) SPC serverconnection.getobject(%i).uiname); //do stuff
continue; //skip the next 4 unneccesary lines of code, saving us basically no processing power! yay!
}
if(serverconnection.getObject(%i).ClassName $= "PlayerData") // comprable to above, except if it doesn't have a uiname, use the objects id.
{
echo("Located PlayerData:  " SPC serverconnection.getobject(%i) SPC "ERROR: No UINAME defined. Using object ID.");
}
}
}


Why are you calling serverConnection.getCount() over and over, for example even potentially 50000 times on large servers?

Ok, so this is the little function I created:
Code: [Select]
function SlayerClient_Support::getIDFromUiName(%uiName)
{
%count = serverConnection.getCount();
for(%i=0; %i < %count; %i++)
{
%obj = serverConnection.getObject(%i);
if(%obj.uiName $= %uiName)
return %obj;
}
return -1;
}

The only problem is that it's extremely inefficient, especially with larger brickcounts, etc.

Right now my benchmarking script gives this an average benchmark score of 29. For my use I would need that score to be anywhere from 0 to 10. Any ideas on how to make this more efficient?

I used this to get a simple list:
Code: [Select]
for(%i=0;%i<serverconnection.getCount();%i++)
{
     %o=serverconnection.getobject(%i);
     if(%o.getClassName()$="playerData")
     {
           echo(%o.uiname);
     }
}

EDIT: aw shat you beat me

EDIT2: I just tested this on glasses server, and it worked. Showed an neat list (it didn't take too long to loop through serverconnection, spat it out in less than a second)
« Last Edit: April 06, 2012, 12:05:20 AM by computermix »


End the loop as soon as you see an object with a class name that does not end with "Data". While datablocks could be made on-the-go for the server, it is highly unlikely to happen and is a bad idea anyway.

End the loop as soon as you see an object with a class name that does not end with "Data". While datablocks could be made on-the-go for the server, it is highly unlikely to happen and is a bad idea anyway.
That's risky, since people can name their datablocks anything. Here's what I ended up doing:

Code: [Select]
function SlayerClient_Support::getIDFromUiName(%uiName)
{
%count = serverConnection.getCount();
for(%i=0; %i < %count; %i++)
{
%obj = serverConnection.getObject(%i);
if(%obj.getClassName() $= "MissionArea")
break;
if(%obj.uiName $= %uiName)
return %obj;
}
return -1;
}

This reduces the benchmark score to around a 7. Thanks for your help everyone!


Uh, what?
MissionArea is for the map and is loaded after all add-ons but before any bricks.

People cannot "customize" the class name of their datablocks, and all the default class names end with "Data".

People cannot "customize" the class name of their datablocks, and all the default class names end with "Data".
Not true, there are many other class names. One example is "AudioProfile".

Anyway, my method completely works with these modifications:
Code: [Select]
function SlayerClient_Support::getIDFromUiName(%uiName)
{
if(serverConnection.isLocal())
%group = datablockGroup;
else
%group = serverConnection;

%count = %group.getCount();
for(%i=0; %i < %count; %i++)
{
%obj = %group.getObject(%i);
if(%obj.getClassName() $= "MissionArea")
break;
if(%obj.uiName $= %uiName)
return %obj;
}
return -1;
}

Not true, there are many other class names. One example is "AudioProfile".

I didn't sleep this night, I'm tired. But yes, I see what you mean.