Raised This Month: $51 Target: $400
 12% 

Need help with couple of basics


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
waltercl
Member
Join Date: Jun 2011
Old 06-03-2012 , 00:01   Need help with couple of basics
Reply With Quote #1

There may be a basic faq which covers what I need so if that's the case please point me to it, but I have really limited time so if a couple of quick answers can be given that would be great too.

I want to modify an existing plugin with a couple of lines of code to suit a particular need. The plugin already tracks consecutive wins and after so many wins it will give out money to the losing team. What I'd like to do is check the current map, and if it is anything other than Dust2 AND the consecutive wins reaches a particular number then I want to set the mp_timelimit to 5 or something that will make the map end and go to the next map in the rotation. This is essentially a modification to make my own "blowout" plugin.

Last edited by waltercl; 06-03-2012 at 00:24.
waltercl is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 06-03-2012 , 00:48   Re: Need help with couple of basics
Reply With Quote #2

Posting your code would help a lot.
__________________
Dr. McKay is offline
waltercl
Member
Join Date: Jun 2011
Old 06-03-2012 , 01:20   Re: Need help with couple of basics
Reply With Quote #3

Below is the code. As you can see I modified an existing plugin and changed it to effectively be a loser bonus mod. As I said in the original post I want to modify it further to also function as a blowout mod once the margin between teams reaches a certain number so it will lower the map time and change the map (unless it is Dust2).

/* Reverse Cash Flow by databomb
[email protected]
Original Compile Date: 06.05.09

This plugin revamps the cash flow system. A lot of times the winners keep on winning
and get better guns which enable them to win more - this created a downward spiral
for the losing team. Servers will give you 16k cash all the time to fix this. This plugin
tries to balance the cash flow system out and make the winners work harder to keep winning.
It tries to reverse the concepts of the current cash flow system and simplify them a
little as well. All the variables involved are modifable via the console so you can fine-tune
the numbers to further balance gameplay.

Current System:
The losing team gets 1,400 plus 500 for each consecutive loss up to a maximum of 2,900.
If the bomb was planted the terrorists get an additional 800 added to their total.
On DE maps, Ts and CTs both get 3,250 for winning UNLESS the bomb exploded, then Ts get 3,500
On CS maps, the Ts and CTs get 3,000 base +150 for each hostage that is untouched/touched and alive/dead

This Plugin:
The losing team is awarded a generous amount of money
The losing team will get less money if the winners manage to complete their objective (rescue hostages, bomb, etc.)
The winning team will get less money for each consecutive win

*/

#include <sourcemod>
//#include <sdktools>

// #ifndef directive not working, re-define then...
#define NULL 0
#define TRUE 1
#define FALSE 0
#define CT_TEAM 3
#define T_TEAM 2
#define INVALID_TEAM 5

new Handle:H_Enabled = INVALID_HANDLE;
new Handle:H_LoserMoney = INVALID_HANDLE;
new Handle:H_WinnerBase = INVALID_HANDLE;
new Handle:H_WinnerPenalty = INVALID_HANDLE;
new Handle:H_ObjectiveMoney = INVALID_HANDLE;

new g_CashEntLoc = 1;

new PlayerCash[MAXPLAYERS + 1];
new CashToWinners = 0;
new CashToLosers = 0;
new LastRoundWinningTeam = INVALID_TEAM;

public Plugin:myinfo =
{
name = "Reverse Cash Flow",
author = "databomb",
description = "Reverses the cash flow system to give winners less as they do better.",
version = "1.0",
url = ""
}

public OnPluginStart()
{
// Store cash entity offset location
g_CashEntLoc = FindSendPropOffs("CCSPlayer", "m_iAccount");
if ((g_CashEntLoc == NULL) || (g_CashEntLoc == -1))
{
// quit for error. might occur if loaded for non cs:s game...
return Plugin_Handled;
}

// Register console variables
CreateConVar("sm_cashflow_version", "1.0", "Reverse Cash Flow version",FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_ NOTIFY);
H_Enabled = CreateConVar("sm_cashflow", "1", "Enables the reverse cash flow system", FCVAR_PLUGIN);

// *** do we need to go back and handle these or are the min/max #s enforced??

H_LoserMoney = CreateConVar("sm_cashflow_loser", "3500", "Money given to losing team", FCVAR_PLUGIN, TRUE, 0.0, TRUE, 16000.00);

H_WinnerBase = CreateConVar("sm_cashflow_winner_base", "3250", "Base money given to losing team after first win", FCVAR_PLUGIN, TRUE, 0.0, TRUE, 16000.00);

H_WinnerPenalty = CreateConVar("sm_cashflow_winner_penalty", "750", "Money subtracted from base for each consecutive win", FCVAR_PLUGIN, TRUE, 0.0, TRUE, 5333.00);

H_ObjectiveMoney = CreateConVar("sm_cashflow_objective_penalty", "800", "Money subtracted from losers if objective was completed", FCVAR_PLUGIN, TRUE, 0.0, TRUE, 16000.00);

// Auto generates a config file, plugin_cashflow.cfg, with default values
AutoExecConfig(true, "plugin_cashflow");

// Look for changes to act on
HookConVarChange(H_Enabled, ConVarChange_Enabled);

HookEvent("round_end",Event_RoundEnded,EventH ookMode_Post);
//HookEvent("round_start",Event_RoundStarted,Ev entHookMode_Post);

} // end OnPluginStart

public ConVarChange_Enabled(Handle:cvar, const StringldVal[], const String:newVal[])
{
if (StringToInt(newVal) != TRUE)
{
// Unhook events
UnhookEvent("round_end",Event_RoundEnded,Even tHookMode_Post);
//UnhookEvent("round_start",Event_RoundStarted, EventHookMode_Post);
// Unhook convar changes EXCEPT this one
}
else if (StringToInt(oldVal) != StringToInt(newVal)) // Don't waste time "re"hooking
{
HookEvent("round_end",Event_RoundEnded,EventH ookMode_Post);
//HookEvent("round_start",Event_RoundStarted,Ev entHookMode_Post);
}
} // end ConVarChange_Enabled



public Event_RoundEnded(Handle:event, const String:name[], bool:dontBroadcast)
{
static ConsecutiveWins = 0;

new EndingMethod = GetEventInt(event, "reason");
new WinningTeam = GetEventInt(event, "winner");


// Check for consecutive wins
if (WinningTeam == LastRoundWinningTeam)
{
ConsecutiveWins++;
}
else
{
ConsecutiveWins = 1;
}
// If round was a draw or game is commencing, don't assign a winner yet!
if ((EndingMethod == 10) || (EndingMethod == 16))
{
LastRoundWinningTeam = INVALID_TEAM;
}
else
{
LastRoundWinningTeam = WinningTeam;
}

// Put cash values in an array (used GetMaxClients() because GetNumPlayers() wasn't working)
for (new idx = 1; idx <= GetMaxClients(); idx++)
{
if (IsClientInGame(idx))
{
PlayerCash[idx] = GetEntData(idx, g_CashEntLoc);
}
}

// Determine Losers Cash
// Was objective completed? (bomb exploded, VIP escaped, Ts escaped, hostage(s) rescued)
if ((EndingMethod == 1) || (EndingMethod == 2) || (EndingMethod == 4) || (EndingMethod == 11))
{
CashToLosers = GetConVarInt(H_LoserMoney);
}
else
{
CashToLosers = GetConVarInt(H_LoserMoney);
}

new IndividualCash = 0;

for (new idx = 1; idx <= GetMaxClients(); idx++)
{
if (ConsecutiveWins>3)
{

// Bound check the cash before we set it
if (IndividualCash > 16000)
IndividualCash = 16000;
if (IndividualCash < 0)
IndividualCash = 0;

if (GetClientTeam(idx) == LastRoundWinningTeam)
{
//do nothing with winning team's cash
}
else
{
IndividualCash = PlayerCash[idx] + CashToLosers;
SetEntData(idx, g_CashEntLoc, IndividualCash);
}
}
}
return Plugin_Handled;

} // end Event_RoundEnded

public Event_RoundStarted(Handle:event, const String:name[], bool:dontBroadcast)
{
new IndividualCash = 0;

// Adjust cash flows (we don't care what the game did, we're using round_end as reference)
for (new idx = 1; idx <= GetMaxClients(); idx++)
{
// Check to see if client is connected and that we actually had a winner last round!
if (IsClientInGame(idx) && (LastRoundWinningTeam != INVALID_TEAM))
{
//Modifying this to not get Winning Team since we don't care about their cash
// Check for winning team
//if (GetClientTeam(idx) == LastRoundWinningTeam)
//{
//IndividualCash = PlayerCash[idx] + CashToWinners;
//}
//else
//{
if (ConsecutiveWins>3)
{
IndividualCash = PlayerCash[idx] + CashToLosers;

//}
// Bound check the cash before we set it
if (IndividualCash > 16000)
IndividualCash = 16000;
if (IndividualCash < 0)
IndividualCash = 0;
// Finally..
if (GetClientTeam(idx) == LastRoundWinningTeam)
{
//do nothing with winning team's cash
}
else
{
SetEntData(idx, g_CashEntLoc, IndividualCash);
}
}
}
}

return Plugin_Handled;
} // end Event_RoundStarted
waltercl is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 06-03-2012 , 08:23   Re: Need help with couple of basics
Reply With Quote #4

Use tags please.
Dr. Greg House is offline
waltercl
Member
Join Date: Jun 2011
Old 06-03-2012 , 18:09   Re: Need help with couple of basics
Reply With Quote #5

Is there a faq on basic commands. All I really need is the command to get the current map and check to see if it is Dust 2. If it is then do nothing, and if it isn't then set mp_timelimit 5.
waltercl is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 06-03-2012 , 19:08   Re: Need help with couple of basics
Reply With Quote #6

Quote:
Originally Posted by waltercl View Post
Is there a faq on basic commands. All I really need is the command to get the current map and check to see if it is Dust 2. If it is then do nothing, and if it isn't then set mp_timelimit 5.
http://docs.sourcemod.net/api
__________________
Dr. McKay is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-04-2012 , 14:43   Re: Need help with couple of basics
Reply With Quote #7

Quote:
Originally Posted by waltercl View Post
Is there a faq on basic commands. All I really need is the command to get the current map and check to see if it is Dust 2. If it is then do nothing, and if it isn't then set mp_timelimit 5.
The commands you'll need for that are GetCurrentMap, StrEqual, FindConVar (which should be in OnPluginStart), and SetConVarInt.

It'll look something like this:

PHP Code:
new Handleg_Cvar_Timelimit INVALID_HANDLE;

public 
OnPluginStart()
{
    
// Copy other stuff from existing OnPluginStart
    
g_Cvar_Timelimit FindConVar("mp_timelimit");
}

// While in some sort of command, either one you wrote or something like OnMapStart
    
decl String:map[64];
    
GetCurrentMap(mapsizeof(map));
    if (!
StrEqual(map"de_dust2"))
    {
        
SetConVarInt(g_Cvar_Timelimit5);
    } 
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-04-2012 at 14:44.
Powerlord is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 06-04-2012 , 14:59   Re: Need help with couple of basics
Reply With Quote #8

Quote:
Originally Posted by waltercl View Post
Is there a faq on basic commands. All I really need is the command to get the current map and check to see if it is Dust 2. If it is then do nothing, and if it isn't then set mp_timelimit 5.
Why not just make map-specific config files? css/maps/cfg/de_dust2.cfg:

Code:
mp_timelimit 5
(at least I think that's where it goes for CS:S)
__________________
Dr. McKay is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-04-2012 , 16:00   Re: Need help with couple of basics
Reply With Quote #9

Quote:
Originally Posted by Dr. McKay View Post
Why not just make map-specific config files? css/maps/cfg/de_dust2.cfg:

Code:
mp_timelimit 5
(at least I think that's where it goes for CS:S)
Well, you have that backwards... he wants mp_timelimit 5 for every other map.

Still, you'd just put mp_timelimit 5 in server.cfg and mp_timelimit something else in de_dust2.cfg...

which makes me feel derpy for writing code to do it.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 06-04-2012 , 16:59   Re: Need help with couple of basics
Reply With Quote #10

Quote:
Originally Posted by Powerlord View Post
Well, you have that backwards... he wants mp_timelimit 5 for every other map.

Still, you'd just put mp_timelimit 5 in server.cfg and mp_timelimit something else in de_dust2.cfg...

which makes me feel derpy for writing code to do it.
I need to read better.
__________________
Dr. McKay is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode