[SSGM 4.0 Plugin] RadioCommands [message #470748] |
Wed, 04 July 2012 19:14 |
|
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.
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 #470759 is a reply to message #470748] |
Thu, 05 July 2012 01:40 |
|
Whitedragon
Messages: 832 Registered: February 2003 Location: California
Karma: 1
|
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 #470764 is a reply to message #470748] |
Thu, 05 July 2012 04:23 |
|
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 |
|
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.
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 #470780 is a reply to message #470748] |
Thu, 05 July 2012 13:41 |
|
Whitedragon
Messages: 832 Registered: February 2003 Location: California
Karma: 1
|
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 - )
|
|
|