Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Release Forum » [SSGM 4.0 Plugin] RadioCommands
[SSGM 4.0 Plugin] RadioCommands [message #470748] Wed, 04 July 2012 19:14 Go to next message
Xpert is currently offline  Xpert
Messages: 1588
Registered: December 2005
Location: New York City
Karma: 0
General (1 Star)
This is a simple SSGM 4.0 plugin that outputs when players use ingame Radio Commands.

This will be the first of many stuff I plan on releasing.


Example from my bot:
Quote:


<CloudyServ2> [Radio] &WNxSmiLey: Affirmative.
<CloudyServ2> [Radio] &WNxSmiLey: Negative.
<CloudyServ2> [Radio] &WNxSmiLey: Don't get in my way!
<CloudyServ2> [Radio] &WNxSmiLey: Don't get in my way!
<CloudyServ2> [Radio] &WNxSmiLey: Watch where you're pointing that!



Enjoy.


http://i32.photobucket.com/albums/d42/XpertMaverick/xpertyankee.jpg

Creator of NetGuard, an IRC network regulator.
Developer of the CloudyServ 0.982-X project.
Developer of the CloudyServ Ren-X bot.

Part time streamer - https://twitch.tv/gg_wonder

[Updated on: Thu, 05 July 2012 05:53]

Report message to a moderator

Re: [SSGM 4.0 Plugin] RadioCommands [message #470755 is a reply to message #470748] Wed, 04 July 2012 21:38 Go to previous messageGo to next message
Sir Kane
Messages: 1701
Registered: March 2003
Location: Angerville
Karma: 0
General (1 Star)
That'll spam you good!

Proud N9500 and proud N6270 user. Creator of the IEE libraries (original bhs.dll) and the RB series software.
http://n00bstories.com/image.fetch.php?id=1189992501http://www.n00bstories.com/image.fetch.php?id=1257492907
Re: [SSGM 4.0 Plugin] RadioCommands [message #470757 is a reply to message #470748] Thu, 05 July 2012 00:06 Go to previous messageGo to next message
iRANian is currently offline  iRANian
Messages: 4299
Registered: April 2011
Karma: 0
General (4 Stars)
You could have it log invalid radio commands too.

Long time and well respected Renegade community member, programmer, modder and tester.

Scripts 4.0 private beta tester since May 2011.

My Renegade server plugins releases
Re: [SSGM 4.0 Plugin] RadioCommands [message #470759 is a reply to message #470748] Thu, 05 July 2012 01:40 Go to previous messageGo to next message
Whitedragon is currently offline  Whitedragon
Messages: 829
Registered: February 2003
Location: California
Karma: 0
Colonel
You're leaking memory. You could rewrite the entire thing as simply:

Console_Output("[Radio] %ls: %ls\n",Get_Wide_Player_Name_By_ID(PlayerID),TranslateDBClass::Get_String(AnnouncementID));


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 4.0 Plugin] RadioCommands [message #470760 is a reply to message #470748] Thu, 05 July 2012 02:09 Go to previous messageGo to next message
iRANian is currently offline  iRANian
Messages: 4299
Registered: April 2011
Karma: 0
General (4 Stars)
What's the memory leak?

Long time and well respected Renegade community member, programmer, modder and tester.

Scripts 4.0 private beta tester since May 2011.

My Renegade server plugins releases
Re: [SSGM 4.0 Plugin] RadioCommands [message #470761 is a reply to message #470748] Thu, 05 July 2012 02:12 Go to previous messageGo to next message
Whitedragon is currently offline  Whitedragon
Messages: 829
Registered: February 2003
Location: California
Karma: 0
Colonel
Using Get_Player_Name_By_ID.

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 4.0 Plugin] RadioCommands [message #470762 is a reply to message #470748] Thu, 05 July 2012 02:18 Go to previous messageGo to next message
iRANian is currently offline  iRANian
Messages: 4299
Registered: April 2011
Karma: 0
General (4 Stars)
You're right, should use Get_Wide_Player_Name() or Find_Player(PlayerID)->PlayerName, and change the '%s' to a '%S' in the format string.

Long time and well respected Renegade community member, programmer, modder and tester.

Scripts 4.0 private beta tester since May 2011.

My Renegade server plugins releases
Re: [SSGM 4.0 Plugin] RadioCommands [message #470764 is a reply to message #470748] Thu, 05 July 2012 04:23 Go to previous messageGo to next message
cAmpa is currently offline  cAmpa
Messages: 597
Registered: March 2006
Karma: 0
Colonel
TT should remove WideCharToChar or replace it with this function.
This one doesn't create memleaks.

Quote:

const char* WideCharToChar
(const wchar_t* string)
{
struct AutoDelete
{
public:
char* pointer;

AutoDelete() : pointer(0) {}
~AutoDelete() { delete[] this->pointer; }
};

static AutoDelete _autoDelete[10];
static unsigned int _index = 0;


if (!string || !*string)
return "";

++_index;
if (_index >= 10)
_index = 0;

if (_autoDelete[_index].pointer)
delete[] _autoDelete[_index].pointer;

int length = ::wcslen (string);
char* text = new char[length + 1];

_autoDelete[_index].pointer = text;

::wcstombs (text, string, length + 1);

return text;
}


Bückstabü!
Re: [SSGM 4.0 Plugin] RadioCommands [message #470766 is a reply to message #470762] Thu, 05 July 2012 05:52 Go to previous messageGo to next message
Xpert is currently offline  Xpert
Messages: 1588
Registered: December 2005
Location: New York City
Karma: 0
General (1 Star)
Whitedragon wrote on Thu, 05 July 2012 04:40

You're leaking memory. You could rewrite the entire thing as simply:

Console_Output("[Radio] %ls: %ls\n",Get_Wide_Player_Name_By_ID(PlayerID),TranslateDBClass::Get_String(AnnouncementID));



If I remember correctly, Get_Wide_Player_Name_By_ID doesn't exist in SSGM 4.0, or am I not seeing it?

iRANian wrote on Thu, 05 July 2012 05:18

You're right, should use Get_Wide_Player_Name() or Find_Player(PlayerID)->PlayerName, and change the '%s' to a '%S' in the format string.


I don't know why but in my private code, I did use Get_Wide_Player_Name() instead of Get_Player_Name_By_ID.



Updated 1st post with v2.


http://i32.photobucket.com/albums/d42/XpertMaverick/xpertyankee.jpg

Creator of NetGuard, an IRC network regulator.
Developer of the CloudyServ 0.982-X project.
Developer of the CloudyServ Ren-X bot.

Part time streamer - https://twitch.tv/gg_wonder
Re: [SSGM 4.0 Plugin] RadioCommands [message #470767 is a reply to message #470748] Thu, 05 July 2012 05:56 Go to previous messageGo to next message
iRANian is currently offline  iRANian
Messages: 4299
Registered: April 2011
Karma: 0
General (4 Stars)
I didn't see it at first either although I always check scripts.dll API functions that return a string because some allocate on the heap while some don't. :/

Long time and well respected Renegade community member, programmer, modder and tester.

Scripts 4.0 private beta tester since May 2011.

My Renegade server plugins releases
Re: [SSGM 4.0 Plugin] RadioCommands [message #470780 is a reply to message #470748] Thu, 05 July 2012 13:41 Go to previous message
Whitedragon is currently offline  Whitedragon
Messages: 829
Registered: February 2003
Location: California
Karma: 0
Colonel
const wchar_t *Get_Wide_Player_Name_By_ID(int ID) {
	cPlayer *x = Find_Player(ID);
	if (!x) {
		return L"None";
	}
	return x->PlayerName;
}


For things that are stored as wide chars internally, like player names and translated strings, it's always better to use the wide version of their function. This produces cleaner, slightly more efficient code that doesn't have a chance of leaking memory if you forget to delete it.

If you need them in a char for some reason, such as comparison, you can convert them like this:

StringClass Name = Get_Wide_Player_Name_By_ID(ID);

or 

StringClass(Get_Wide_Player_Name_By_ID(ID))


And StringClass will automatically handle the conversion and memory allocation.


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 - )
Previous Topic: [TOOL] chunky
Next Topic: Westwood Scripts [M02]
Goto Forum:
  


Current Time: Fri Apr 19 01:15:02 MST 2024

Total time taken to generate the page: 0.01469 seconds