Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
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 Go to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
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 Razz

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;
	}
}



Re: get_part_name, chathooks and strings [message #366915 is a reply to message #366913] Sun, 11 January 2009 08:04 Go to previous messageGo to next message
cAmpa is currently offline  cAmpa
Messages: 597
Registered: March 2006
Karma: 0
Colonel
In "GameObject *Get_Part_Name(const char *name1)" is a small bug,
replace

if (!stristr(name,name1))


with

if (stristr(name,name1))


Bückstabü!
Re: get_part_name, chathooks and strings [message #366916 is a reply to message #366913] Sun, 11 January 2009 08:05 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
This fix works, Campa is the man.


Re: get_part_name, chathooks and strings [message #366918 is a reply to message #366913] Sun, 11 January 2009 08:30 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
int FindPlayer(const char *Part) //-2: not unique, -1: not found
{
	int Player = -1;
	for(GenericSLNode *x = PlayerList->HeadNode; x != 0; x = x->NodeNext)
	{
		cPlayer *p = (cPlayer *)x->NodeData;
		if(p && p->IsActive)
		{
			const char *pName = WideCharToChar(p->PlayerName);
			if(stricmp(pName, Part) == 0)
			{
				delete []pName;
				Player = p->PlayerId;
				break;
			}
			if(stristr(pName, Part))
			{
				if(Player >= 0)
				{
					delete []pName;
					return -2;
				}
				else
				{
					Player = p->PlayerId;
				}
			}
			delete []pName;
		}
	}
	return Player;	
}
Re: get_part_name, chathooks and strings [message #366929 is a reply to message #366913] Sun, 11 January 2009 09:08 Go to previous messageGo to next message
mrãçķz is currently offline  mrãçķz
Messages: 3069
Registered: August 2007
Karma: 0
General (3 Stars)
Permabanned for trying and failing DDoS
"remeber RoShAmBo is always right :P"
Re: get_part_name, chathooks and strings [message #366931 is a reply to message #366913] Sun, 11 January 2009 09:16 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
With Get_Part_Name, if a player has a sub string of another player's name, it is impossible to get it.

Lets say we have RoShamBo and ShamBo in game, you will never be able to get ShamBo with Get_Part_Name.
Re: get_part_name, chathooks and strings [message #366972 is a reply to message #366913] Sun, 11 January 2009 13:25 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
Some really interesting results have come out of this thread. Thanks cAmpa and Roshambo. <3


Re: get_part_name, chathooks and strings [message #366986 is a reply to message #366913] Sun, 11 January 2009 15:49 Go to previous messageGo to next message
mrãçķz is currently offline  mrãçķz
Messages: 3069
Registered: August 2007
Karma: 0
General (3 Stars)
Permabanned for trying and failing DDoS
reborn you should take a look at the "YaRR" aka "Yet another Renegade Regulator" source by RoShAmBo Wink
Re: get_part_name, chathooks and strings [message #367617 is a reply to message #366915] Sat, 17 January 2009 04:01 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
cAmpa wrote on Sun, 11 January 2009 10:04

In "GameObject *Get_Part_Name(const char *name1)" is a small bug,
replace

if (!stristr(name,name1))


with

if (stristr(name,name1))




This bug also exists in the "Get_Part_Names" function too. It needs to be changed to:

int Get_Part_Names(const char *name1)
{
	GenericSLNode *x = BaseGameObjList->HeadNode;
	int count = 0;
	while (x)
	{
		GameObject *o = As_SoldierGameObj((GameObject *)x->NodeData);
		if (o /*&& Commands->Is_A_Star(o)*/)
		{
			const char *name = Get_Player_Name(o);
			if (stristr(name,name1))
			{
				count++;
			}
			delete[] name;
		}
		x = x->NodeNext;
	}
	return count;
}


Just an FYI if anyone ever wondered why it doesn't work how they might expect it to.



Re: get_part_name, chathooks and strings [message #367618 is a reply to message #366913] Sat, 17 January 2009 04:24 Go to previous messageGo to next message
mrãçķz is currently offline  mrãçķz
Messages: 3069
Registered: August 2007
Karma: 0
General (3 Stars)
Permabanned for trying and failing DDoS
reborn In Love
Re: get_part_name, chathooks and strings [message #367678 is a reply to message #366918] Sat, 17 January 2009 20:37 Go to previous message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
RoShamBo wrote on Sun, 11 January 2009 08:30

int FindPlayer(const char *Part) //-2: not unique, -1: not found
{
	int Player = -1;
	for(GenericSLNode *x = PlayerList->HeadNode; x != 0; x = x->NodeNext)
	{
		cPlayer *p = (cPlayer *)x->NodeData;
		if(p && p->IsActive)
		{
			const char *pName = WideCharToChar(p->PlayerName);
			if(stricmp(pName, Part) == 0)
			{
				delete []pName;
				Player = p->PlayerId;
				break;
			}
			if(stristr(pName, Part))
			{
				if(Player >= 0)
				{
					delete []pName;
					return -2;
				}
				else
				{
					Player = p->PlayerId;
				}
			}
			delete []pName;
		}
	}
	return Player;	
}




Nice Very Happy
Previous Topic: Renegade SSMods Archive
Next Topic: Camera.ini
Goto Forum:
  


Current Time: Sat Dec 21 18:35:52 MST 2024

Total time taken to generate the page: 0.01028 seconds