Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » SSGM Chat Hook
SSGM Chat Hook [message #274298] Thu, 19 July 2007 17:09 Go to next message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
Can someone help me with this? I'm trying to figure out how to add commands and I think figured it out, but don't know the syntax for adding commands. Dont Get It

void Chat(int ID, TextMessageEnum Type, const wchar_t *Msg2) {
	if (!Data->Plugins.empty()) {
		std::vector<PluginInfo*>::const_iterator it;
		for (it = Data->Plugins.begin();it != Data->Plugins.end(); ++it) {
			if ((*it)->Type == Plugin) {
				if ((*it)->ChatHookHandle) {
					(*it)->ChatHookHandle(ID,Type,Msg2);	
				}
			}
		}
	}

	if (Type == 2) {
		return;
	}
	if (Settings->Gamelog && Settings->NewGamelog) {
		Gamelog_Chat_Hook(ID,Type,Msg2);
	}

	std::string Msg = WideCharToString(Msg2);
	if (Msg[0] == '!' && !Data->Commands.empty()) {
		TokenClass Text(Msg);
		std::string Command = Text[1];
		Text.erase(1);
		Data->Trigger_Chat_Command(ID,Type,Command,Text);
	}
}



I'm pretty sure that this is where I'd add the commands, but don't know the syntax. :/
	if (Type == 2) {
		return;
	}





-MathK1LL
Re: SSGM Chat Hook [message #274312 is a reply to message #274298] Thu, 19 July 2007 17:41 Go to previous messageGo to next message
Sn1per74* is currently offline  Sn1per74*
Messages: 939
Registered: April 2006
Karma: 0
Colonel
Try using LUA it's a lot less complicated.

http://i4.photobucket.com/albums/y133/FMAROCKS/sniper74halosigsnipedontforgettogiv.png
Creator: AoBFrost
Re: SSGM Chat Hook [message #274318 is a reply to message #274298] Thu, 19 July 2007 18:11 Go to previous messageGo to next message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
Uh...I've been using LUA, I'm trying something different now. :/


-MathK1LL
Re: SSGM Chat Hook [message #274343 is a reply to message #274298] Thu, 19 July 2007 21:02 Go to previous messageGo to next message
Whitedragon is currently offline  Whitedragon
Messages: 832
Registered: February 2003
Location: California
Karma: 1
Colonel
SSGM's chat commands are at the bottom of gmmain.cpp. There's also an example of a chat command in the plugin example source. Take a look at those.

Black-Cell.net
Network Administrator (2003 - )

DragonServ, Renegade's first IRC interface bot
Creator and lead coder (2002 - )

Dragonade, Renegade's first server side modification
Lead coder (2005 - )
Re: SSGM Chat Hook [message #274623 is a reply to message #274298] Fri, 20 July 2007 21:47 Go to previous messageGo to next message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
Ok, I seem to finally understand how to create plugins for SSGM. I just don't know the SSGM functions that manipulate players and stuff. :/

-MathK1LL



EDIT: Can someone post a list of all the "Commands->____" functions? :/


EDIT2: How is "ChatType" returned? 0 - all; 1 - team; 2 - page?

[Updated on: Fri, 20 July 2007 22:14]

Report message to a moderator

Re: SSGM Chat Hook [message #274634 is a reply to message #274298] Fri, 20 July 2007 22:48 Go to previous messageGo to next message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
Stupid edit button disappeared >.>


Nevermind on the "Commands->____" part xD.

Where can I find a list of the -exact- parameters of the Commands-> function?



Also, I need help with the donate command...Logic is working, but I don't know the correct syntax for some of the Commands->___

ie: What do I put for the "GameObject *" parameter when giving money to another player that doesn't trigger the command.

class DonateChatCommand : public ChatCommandClass {
	void Triggered(int ID,const TokenClass &Text,int ChatType) {
		// Usage: !donate <nick> <amt>
		// Text[1] - Nick
		// Text[2] - Amt
		int Amt = Text[2];
		char Nick[20] = Commands->Get_ID(Text[1]);
		Commands->Give_Money(ID,Commands->Get_Money(ID)-Amt), true);
		Commands->Give_Money(ID,Commands->Get_Money(ID)+Amt), true);
		Console_Input(StrFormat("ppage %d You have donated %d credits to %d.",ID,Text[2],Text[1]).c_str());
		Console_Input(StrFormat("ppage %d %d has donated you %d credits.",Nick,ID,Text[2]).c_str());
	}
}
ChatCommandRegistrant<DonateChatCommand> DonateChatCommandReg("!don8;!donat;!doante;!donate;!d",CHATTYPE_TEAM,2,GAMEMODE_ALL);
Re: SSGM Chat Hook [message #274637 is a reply to message #274298] Fri, 20 July 2007 23:28 Go to previous messageGo to next message
Whitedragon is currently offline  Whitedragon
Messages: 832
Registered: February 2003
Location: California
Karma: 1
Colonel
Amount/Game objects
int Amount = (int)atoi(Text[2].c_str()); //Turn the amount into an int.
GameObject *Donater = Get_GameObj(ID); //Get the gameobj of the player who's donating.
GameObject *Receiver = Get_GameObj_By_Player_Name(Text[1].c_str()); //Get the gameobj of the player being being donated to.



You also need to check if the amount is a valid number.
bool IsNum(const char *sPtr) {
	while (*sPtr != '\0') {
		if (*sPtr < 48 || *sPtr > 57) return false;
		++sPtr;
	}
	return true;
}

if (!IsNum(Text[2].c_str()) || Text[2].size() > 6) { //If it contains letters or is too big.
return;
}



And of course you need to check if the players are on the same team and if the donater has enough credits.


Black-Cell.net
Network Administrator (2003 - )

DragonServ, Renegade's first IRC interface bot
Creator and lead coder (2002 - )

Dragonade, Renegade's first server side modification
Lead coder (2005 - )
Re: SSGM Chat Hook [message #274640 is a reply to message #274298] Fri, 20 July 2007 23:58 Go to previous messageGo to next message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
How would I return the player's team? Also, How do I refer to:

GameObject *Donater = Get_GameObj(ID); //Get the gameobj of the player who's donating.
GameObject *Receiver = Get_GameObj_By_Player_Name(Text[1].c_str()); //Get the gameobj of the player being being donated to.


when I use them in"

Commands->Give_Money(GameObject *Donater,Commands->Get_Money(GameObject *Donater)-Amt), true);
Commands->Give_Money(GameObject *Reciever,Commands->Get_Money(GameObject *Reciever)+Amt), true);


and:
Commands->Get_Money(GameObject *Donater)


Do I refer to them as they are shown in my 'examples'?

-MathK1LL
Re: SSGM Chat Hook [message #274644 is a reply to message #274298] Sat, 21 July 2007 00:20 Go to previous messageGo to next message
Whitedragon is currently offline  Whitedragon
Messages: 832
Registered: February 2003
Location: California
Karma: 1
Colonel
Just "Donater" and "Receiver."

Black-Cell.net
Network Administrator (2003 - )

DragonServ, Renegade's first IRC interface bot
Creator and lead coder (2002 - )

Dragonade, Renegade's first server side modification
Lead coder (2005 - )
Re: SSGM Chat Hook [message #274648 is a reply to message #274298] Sat, 21 July 2007 00:56 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)
GameObject *Donater;


"Gameobject" is the data type, and "*Donater" is the variable.

some other statements for example:

double some_variable name;


int another_variable_name;


etc etc...


This should make more sense to you now, as you are most likely used to seeing int, float, double etc etc, but not really gameobject.






[Updated on: Sat, 21 July 2007 00:57]

Report message to a moderator

Re: SSGM Chat Hook [message #274691 is a reply to message #274640] Sat, 21 July 2007 10:06 Go to previous messageGo to next message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
MathK1LL wrote on Sat, 21 July 2007 00:58

How would I return the player's team?




Listen Dont Get It

[Updated on: Sat, 21 July 2007 10:06]

Report message to a moderator

Re: SSGM Chat Hook [message #274693 is a reply to message #274648] Sat, 21 July 2007 10:20 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)
Reborn wrote on Sat, 21 July 2007 08:56

GameObject *Donater;


"Gameobject" is the data type, and "*Donater" is the variable.
[/code]




"GameObject *" is the data type Wink
Re: SSGM Chat Hook [message #274697 is a reply to message #274298] Sat, 21 July 2007 10:29 Go to previous messageGo to next message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
GameObject * - Data type?
Donater - variable?

Blush Dont Get It

-MathK1LL
Re: SSGM Chat Hook [message #274705 is a reply to message #274697] Sat, 21 July 2007 11:10 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)
MathK1LL wrote on Sat, 21 July 2007 13:29

GameObject * - Data type?
Donater - variable?

Blush Dont Get It

-MathK1LL



In c++ you must declare a variable before using it.

The variable name is whatever you decide to use. So you could say "gameobject *Some_really_long_unhelpful_name_that_doesnt_really_help;"
(actually i think theres a limit to the length of a variable name, but i cant remember what it is)
A variable is something you can think of as a bucket, and this bucket holds information, or rather, data. But it can only hold the type of data you told it to hold when you declared it.
The type data that you can store in it is defined by the data type.
Data types are for example: int, float, char, double, short, signed char etc etc, however you will see in renegade allot, the data type "gameobject *".



Re: SSGM Chat Hook [message #274708 is a reply to message #274691] Sat, 21 July 2007 11:25 Go to previous messageGo to next message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
MathK1LL wrote on Sat, 21 July 2007 11:06

MathK1LL wrote on Sat, 21 July 2007 00:58

How would I return the player's team?




Listen Dont Get It



:/ Still not answered...

-MathK1LL
Re: SSGM Chat Hook [message #274709 is a reply to message #274298] Sat, 21 July 2007 11:33 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)
Commands->Get_Player_Type(obj/sender/ID/whatever you are using)


Re: SSGM Chat Hook [message #274710 is a reply to message #274709] Sat, 21 July 2007 11:40 Go to previous messageGo to next message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
bool IsNum(const char *sPtr) {
	while (*sPtr != '\0') {
		if (*sPtr < 48 || *sPtr > 57) return false;
		++sPtr;
	}
	return true; // else, return a true value :)
}

class DonateChatCommand : public ChatCommandClass {
	void Triggered(int ID,const TokenClass &Text,int ChatType) {
		// Text[1] - Nick ~~ Text[2] - Amt
		int Amt = (int)atoi(Text[2].c_str());
		char Nick[20] = Commands->Get_ID(Text[1]);
		GameObject *Donater = Get_GameObj(ID); //Get the gameobj of the player who's donating.
		GameObject *Receiver = Get_GameObj_By_Player_Name(Text[1].c_str()); //Get the gameobj of the player being being donated to.
		if (!IsNum(Text[2].c_str()) || Text[2].size() > 6) { //If it contains letters or is too big.
			return;
		}
		// Check to see if the players are on the same team, if so, proceed to donate.
		if (Commands->Get_Player_Type(*Donater) == Commands->Get_Player_Type(*Reciever)) { // Players are on the same teams
			// Now, check to see if they player has enough money to donate :)
			if (Commands->Get_Money(*Donater) > Amt) {
				Commands->Give_Money(*Donater,Commands->Get_Money(GameObject *Donater)-Amt), true);
				Commands->Give_Money(*Reciever,Commands->Get_Money(GameObject *Reciever)+Amt), true);
				Console_Input(StrFormat("ppage %d  You have donated %d credits to %d.",ID,Text[2],Text[1]).c_str());
				Console_Input(StrFormat("ppage %d  %d has donated you %d credits.",Nick,ID,Text[2]).c_str());
			}
			else {
				Console_Input(StrFormat("ppage %d You do not have enough credits to donate to the specified player.",ID).c_str());
			}
		}
		else {
			Console_Input(StrFormat("ppage %d You need to be on the same team to donate to this person.",ID).c_str());
		}
	}
}
ChatCommandRegistrant<DonateChatCommand> DonateChatCommandReg("!donate;!d",CHATTYPE_TEAM,2,GAMEMODE_ALL);




Would the !donate/!d command be like that? Smile

Thanks, in advance, for the help!

-MathK1LL

[Updated on: Sat, 21 July 2007 11:44]

Report message to a moderator

Re: SSGM Chat Hook [message #274712 is a reply to message #274298] Sat, 21 July 2007 12:07 Go to previous message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
You are declaring the variables "Donater" and "Receiver". "GameObject *" is the data type.
So you do not refer to the variable as "*Donater" and "*Receiver", just take those "*" bits off everywhere apart from where you are declaring it, as that is actually part of the data type declaration, and not the variable name.

Also I would do "Commands->Give_Money(Donater,(Amt * -1),false)", and "Commands->Give_Money(Reciever,(Amt * 1),false)".

There is more wrong too, but I have to go visit my mum now.



Previous Topic: 3ds max 9 problem
Next Topic: Anti Alias without 3.4.1
Goto Forum:
  


Current Time: Sun Dec 01 04:38:48 MST 2024

Total time taken to generate the page: 0.00902 seconds