Home » Renegade Discussions » Mod Forum » get_part_name, chathooks and strings
get_part_name, chathooks and strings [message #366913] |
Sun, 11 January 2009 07:25 |
|
reborn
Messages: 3231 Registered: September 2004 Location: uk - london
Karma:
|
General (3 Stars) |
|
|
I wanted to make it eaiser to get the GameObject * of a player by typing his name out. Then I found it was slightly annoying when players had stupid names like "11||1!\!!|\1\!|!|!\11\11|||", so I experimented with "Get_Part_Name". However, the function never seems to return a gameobject no matter how unique I start typing there name...
Here is a little chat hook I made to test the function out:
class testChatCommand : public ChatCommandClass {
void Triggered(int ID,const TokenClass &Text,int ChatType) {
GameObject *obj = Get_GameObj(ID);
if (!Text[1].empty()) {
std::string player = Text[1].c_str();
GameObject *pobj = Get_GameObj_By_Player_Name(player.c_str());
if(!pobj){
Console_Input(StrFormat("ppage %d You typed %s, there is no exact match to this name.",ID,player.c_str()).c_str());
}
else{
Console_Input(StrFormat("ppage %d You typed %s, i've found this player and I confirm his name is %s.",ID,player.c_str(),Get_Player_Name(pobj)).c_str());
}
GameObject *pobj2;
pobj2 = Get_Part_Name(player.c_str());
if(!pobj2){
Console_Input(StrFormat("ppage %d You typed %s, the name is not unique enough to find.",ID,player.c_str()).c_str());
}
else{
Console_Input(StrFormat("ppage %d You typed %s, you probably mean %s.",ID,player.c_str(),Get_Player_Name(pobj2)).c_str());
}
}
}
};
ChatCommandRegistrant<testChatCommand> testChatCommandReg("!find",CHATTYPE_ALL,1,GAMEMODE_AOW);
I used this chathook in a server with twenty players, I typed out a few players names that was long, but just missed off the last letter. I was always paged that the name was not unique enough.
Is there something wrong with the way I am using the function Get_Part_Name, or is the function itself not working how it should?
Get_Part_Name function is here if you cab't be bothered to look it up
GameObject *Get_Part_Name(const char *name1)
{
GenericSLNode *x = BaseGameObjList->HeadNode;
int count = 0;
GameObject *current = 0;
while (x)
{
GameObject *o = As_SoldierGameObj((GameObject *)x->NodeData);
if (o)
{
const char *name = Get_Player_Name(o);
if (!stristr(name,name1))
{
current = o;
count++;
}
delete[] name;
}
x = x->NodeNext;
}
if ((count == 1) && (current) && (Commands->Get_ID(current)))
{
return current;
}
else
{
return 0;
}
}
|
|
|
|
|
get_part_name, chathooks and strings
By: reborn on Sun, 11 January 2009 07:25
|
|
|
Re: get_part_name, chathooks and strings
By: cAmpa on Sun, 11 January 2009 08:04
|
|
|
Re: get_part_name, chathooks and strings
By: reborn on Sat, 17 January 2009 04:01
|
|
|
Re: get_part_name, chathooks and strings
By: reborn on Sun, 11 January 2009 08:05
|
|
|
Re: get_part_name, chathooks and strings
By: jnz on Sun, 11 January 2009 08:30
|
|
|
Re: get_part_name, chathooks and strings
|
|
|
Re: get_part_name, chathooks and strings
|
|
|
Re: get_part_name, chathooks and strings
By: jnz on Sun, 11 January 2009 09:16
|
|
|
Re: get_part_name, chathooks and strings
By: reborn on Sun, 11 January 2009 13:25
|
|
|
Re: get_part_name, chathooks and strings
|
|
|
Re: get_part_name, chathooks and strings
|
Goto Forum:
Current Time: Mon Dec 30 09:55:10 MST 2024
Total time taken to generate the page: 0.00922 seconds
|