Home » Renegade Discussions » Mod Release Forum » [SSGM 4.0 Plugin] TeamDonate Plugin
Re: [SSGM 4.0 Plugin] TeamDonate Plugin [message #472786 is a reply to message #472619] |
Sat, 04 August 2012 18:18 |
|
roszek
Messages: 296 Registered: June 2010
Karma:
|
Recruit |
|
|
I wanted to add a timer to your team donate (like the !donate) as it had none and I also wanted to change some other things.
It seems to work okay.
TeamDonate.h
Toggle Spoiler#pragma once
#include "gmplugin.h"
void __cdecl PPage(int ID, const char* rgb_colour, const char *Format, ...);
void Console(const char *Format, ...);
int Get_Team_Player_Count_Working(int Team);
TeamDonate.cpp
Toggle Spoiler#include "General.h"
#include "TeamDonate.h"
#include "engine_tt.h"
#include "engine_io.h"
#include "gmgame.h"
#define GREEN "104,234,40"
int ct;
void PPage(int ID, const char* rgb_colour, const char *Format, ...)
{
if(ID < 1 || ID > 128)
{
return;
}
if (!Get_GameObj(ID))
{
return;
}
char buffer[256];
va_list va;
_crt_va_start(va, Format);
vsnprintf(buffer, 256, Format, va);
va_end(va);
float Version = Get_Client_Version(ID);
if(Version < 2.9)
{
Console("ppage %d %s",ID, buffer);
return;
}
else
{
Console("cmsgp %d %s %s", ID, rgb_colour, buffer);
}
}
void Console(const char *Format, ...)
{
char buffer[256];
va_list va;
_crt_va_start(va, Format);
vsnprintf(buffer, 256, Format, va);
va_end(va);
Console_Input(buffer);
}
int Get_Team_Player_Count_Working(int Team)
{
int Total = 0;
for (SLNode<cPlayer>* PlayerIter = Get_Player_List()->Head(); (PlayerIter != NULL); PlayerIter = PlayerIter->Next())
{
cPlayer *p = PlayerIter->Data();
if (p->IsActive)
{
int ID = p->PlayerId;
if (Get_Team(ID) == Team)
{
Total++;
}
}
}
return Total;
}
class TeamDonate : public Plugin
{
public:
int WaitTime;
TeamDonate()
{
RegisterEvent(EVENT_CHAT_HOOK,this);
RegisterEvent(EVENT_GLOBAL_INI,this);
}
~TeamDonate()
{
UnregisterEvent(EVENT_CHAT_HOOK,this);
UnregisterEvent(EVENT_GLOBAL_INI,this);
}
virtual void OnLoadGlobalINISettings(INIClass *SSGMIni)
{
WaitTime = SSGMIni->Get_Int("TeamDonate", "WaitTime", 300);
}
virtual bool TeamDonate::OnChat(int PlayerID,TextMessageEnum Type,const wchar_t *Message,int recieverID)
{
if (Message[0] == L'!')
{
if ((wcsistr(Message,L"!teamdonate") == Message) || (wcsistr(Message,L"!tdonate") == Message)
|| (wcsistr(Message,L"!td") == Message))
{
char throwaway[64];
float Credits = 0;
int ret = swscanf(Message, L"%s %f", throwaway, &Credits);
if (ret == 1)
{
Credits = Get_Money(PlayerID);
}
ct = The_Game()->Get_Game_Duration_S();
if(ct>WaitTime)
{
if (Credits > 0)
{
float PlayerMoney = Get_Money(PlayerID);
if(PlayerMoney >= Credits)
{
int Team = Get_Team(PlayerID);
int Count = Get_Team_Player_Count_Working(Team);
if(Count > 1)
{
int DonateAmount = (int)Credits/(Count - 1);
for (SLNode<cPlayer>* PlayerIter = Get_Player_List()->Head(); (PlayerIter != NULL); PlayerIter = PlayerIter->Next())
{
cPlayer *p = PlayerIter->Data();
if (p->IsActive)
{
int ID = p->PlayerId;
if ((Get_Team(ID) == Team) && (ID != PlayerID))
{
Commands->Give_Money(Get_GameObj(ID),(float)DonateAmount,false);
PPage(ID, GREEN, "You have just been team donated %i credits by player %s.", DonateAmount, Get_Player_Name_By_ID(PlayerID));
}
}
}
Commands->Give_Money(Get_GameObj(PlayerID),(Credits * -1),false);
PPage(PlayerID, GREEN, "You have donated %i credits to every member of your team.", DonateAmount);
}
else
{
PPage(PlayerID, GREEN, "Sorry %s%, but you can't team-donate without a team!",Get_Player_Name_By_ID(PlayerID));
}
}
else
{
PPage(PlayerID,GREEN, "Sorry %s%, but you do not have %.0f credits%, please lower your donation amount.",Get_Player_Name_By_ID(PlayerID), Credits);
}
}
else
{
PPage(PlayerID,GREEN, "Sorry %s%, but you have entered an invalid amount%, please try again.",Get_Player_Name_By_ID(PlayerID));
}
}
else
{
PPage(PlayerID, GREEN, "Sorry %s%, but you need to wait another %i seconds before you can donate to your team.",Get_Player_Name_By_ID(PlayerID), WaitTime - ct + 1);
}
return false;
}
}
return true;
}
};
TeamDonate teamdonate;
extern "C" __declspec(dllexport) Plugin* Plugin_Init()
{
return &teamdonate;
}
ssgm.ini stuff
[TeamDonate]
; WaitTime=
;
; Number of seconds before players can team donate.
WaitTime=180
I've never messed with the ssgm plugins before and wouldn't mind some tips.
[Updated on: Wed, 15 August 2012 03:55] Report message to a moderator
|
|
|
|
|
[SSGM 4.0 Plugin] TeamDonate Plugin
By: iRANian on Fri, 23 September 2011 16:44
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: zunnie on Fri, 23 September 2011 18:01
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: zunnie on Fri, 23 September 2011 22:33
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: iRANian on Sat, 24 September 2011 01:33
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: zunnie on Sat, 24 September 2011 04:44
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: reborn on Sun, 25 September 2011 05:57
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: iRANian on Mon, 02 July 2012 06:36
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: iRANian on Wed, 01 August 2012 15:00
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: Xpert on Wed, 01 August 2012 15:11
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: iRANian on Wed, 01 August 2012 15:27
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: roszek on Wed, 01 August 2012 16:26
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: iRANian on Thu, 02 August 2012 00:08
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: roszek on Sat, 04 August 2012 18:18
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: iRANian on Sun, 05 August 2012 00:41
|
|
|
Re: [SSGM 4.0 Plugin] TeamDonate Plugin
By: roszek on Sun, 05 August 2012 01:25
|
Goto Forum:
Current Time: Sat Nov 09 09:00:04 MST 2024
Total time taken to generate the page: 0.00901 seconds
|