Raised This Month: $ Target: $400
 0% 

[REQ TF2] Changing Point Values For Player Actions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Whispy
New Member
Join Date: Mar 2016
Old 03-10-2016 , 12:43   [REQ TF2] Changing Point Values For Player Actions
Reply With Quote #1

I searched around a bunch on these forums, but couldn't find any information. I found this thread from 2008 with no responses, yet I didn't find much else that was relevant.

Is it possible to change what points are given for which actions? For example, instead of an assist being worth 1/2 a point, it could be changed to be worth 1 point. Or instead of a kill being worth 1 point, it could be changed to be worth 3 points.

I think it would be interesting to play with this in order to change players' incentives to guide them towards playing as a team, instead of going for solo frags. I'm not sure if something already exists to do this, or if it's even possible to do.

More info:
Quote:
Goal: Incentivize teamwork and deincentivize solo frags.

Assumption: Players go for frags because 1) it's fun and 2) it gives them points and players want to top the scoreboardsboards.

Hypothesis: By changing what points are given for which actions, we can change players habits and priorities to encourage teamwork.

Potential Changes:
- Fewer points for solo kills
- More points for assist kills (currently you only get 1/2 a point for an assist kill)
- More points for extinguishing teammates
- More points for upgrading engies buildings
- More points for staying by teammates
- More points for healing via dispenser
- More points for players using your tele
- More points for removing a sapper (as pyro or engie)
- More points for defending cap points

However, this entire idea depends on whether you can detect events like that without adding too much load on the server, and whether you can edit the scoring system at all. Does anyone have any experience with this sort of thing?

Main question I'd like answered: Is this even possible?

Last edited by Whispy; 03-10-2016 at 15:49.
Whispy is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 03-10-2016 , 20:05   Re: [REQ TF2] Changing Point Values For Player Actions
Reply With Quote #2

Yes it's possible, since i'm so nice... just compile and run.
sm_spc_enabled - on/off
sm_spc_kills - points per kill
sm_spc_assists - points per assists
sm_spc_deaths - points LOST per death

You can use float values 0.2, 0.3, 0.5..etc but there's a slight bug that i'm too lazy to fix so try to use whole numbers.

Code:
#pragma semicolon 1
#include <sdktools>
#pragma newdecls required
#include <sourcemod>
#include <sdkhooks>

#define PLUGIN_VERSION "1.0"

ConVar ConVars[4] = {null, ...};
int gEnabled;
float gKills, gAssists, gDeaths;
float gScore[MAXPLAYERS+1];

public Plugin myinfo = 
{
	name = "[TF2] Score Points Changer",
	author = "Tak (Chaosxk)",
	description = "Changes how much points you get from kills / assists",
	version = PLUGIN_VERSION,
	url = ""
}

public void OnPluginStart()
{
	CreateConVar("sm_blackhole_version", "1.0", PLUGIN_VERSION, FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	ConVars[0] = CreateConVar("sm_spc_enabled", "1", "Enables/Disables Black hole rockets.");
	ConVars[1] = CreateConVar("sm_spc_kills", "3.0", "How many poitns for each kill?");
	ConVars[2] = CreateConVar("sm_spc_assists", "2.0", "How many points for each assist?");
	ConVars[3] = CreateConVar("sm_spc_deaths", "1.0", "How many points for each death?");
	
	for(int i = 0; i < 4; i++)
		ConVars[i].AddChangeHook(OnConvarChanged);
		
	HookEvent("player_death", Event_PlayerDeath, EventHookMode_Pre);
}

public void OnConfigsExecuted()
{
	gEnabled = !!GetConVarInt(ConVars[0]);
	gKills = GetConVarFloat(ConVars[1]);
	gAssists = GetConVarFloat(ConVars[2]);
	gDeaths = GetConVarFloat(ConVars[3]);
	
	FindPlayerManager();
}

public void OnConvarChanged(Handle convar, char[] oldValue, char[] newValue) 
{
	if (StrEqual(oldValue, newValue, true))
		return;
		
	float iNewValue = StringToFloat(newValue);
	
	if(convar == ConVars[0])
		gEnabled = !!RoundFloat(iNewValue);
	else if(convar == ConVars[1])
		gKills = iNewValue;
	else if(convar == ConVars[2])
		gAssists = iNewValue;
	else if(convar == ConVars[3])
		gDeaths = iNewValue;
}

public void OnClientPostAdminCheck(int client) 
{
	gScore[client] = 0.0;
}

public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast)
{
	if(!gEnabled) 
		return Plugin_Continue;
	int client = GetClientOfUserId(GetEventInt(event, "userid"));
	int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
	int assister = GetClientOfUserId(GetEventInt(event, "assister"));
	if(IsClientValid(client)) 
	{
		if(gScore[client] > 0.0)
		{
			gScore[client] -= gDeaths;
		}
	}
	if(IsClientValid(attacker) && attacker != client)
	{
		gScore[attacker] += gKills;
	}
	if(IsClientValid(assister))
	{
		gScore[assister] += gAssists;
	}
	return Plugin_Continue;
}

public void Hook_ThinkPost(int entity) 
{
	if(!gEnabled)
		return;
	for(int i = 1; i <= MaxClients; i++)
	{
		if(!IsClientInGame(i) || gScore[i] < 0) 
			continue;
		int iScore = RoundToFloor(gScore[i]);
		SetEntProp(entity, Prop_Send, "m_iTotalScore", iScore, _, i);
	}
}

public void FindPlayerManager()
{
	int entity = GetPlayerResourceEntity();
	SDKHook(entity, SDKHook_ThinkPost, Hook_ThinkPost);
}

public bool IsClientValid(int client)
{
	return (1 <= client <= MaxClients && IsClientInGame(client));
}
__________________

Last edited by Chaosxk; 03-10-2016 at 20:07.
Chaosxk is offline
Whispy
New Member
Join Date: Mar 2016
Old 03-11-2016 , 12:26   Re: [REQ TF2] Changing Point Values For Player Actions
Reply With Quote #3

Awesome, Chaosxk! I really appreciate you taking the time to write this!

If I wanted to detect and grant points for other actions, such as upgrading a friendly engie's buildings or something like that, would that be possible to do? I'm browsing the Events page on the wiki, and, specifically for the engie case, I see 'player_upgradedobject' with the bool 'isbuilder'. I assume it would be something like (just logically, not syntactically) 'if player_upgradedobject AND isbuilder == false, then give X points'.

EDIT: and what's the bug with decimal values? And what are the black hole rockets used for (is that just text left from another script of yours)?

Last edited by Whispy; 03-11-2016 at 12:38.
Whispy is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 03-11-2016 , 17:29   Re: [REQ TF2] Changing Point Values For Player Actions
Reply With Quote #4

Your welcome, you have to hook the event then add points to gScore[client], i think i will expand this plugin and post it in the plugins page.

The bug is if you set kills to 0.5 and assists to 0.5, 2 kills = 1 point but if i did 1 kill and 1 assist that also adds 1 point. It's because i used 1 variable to handle adding points.

And yes i copied and paste some code from another of my plugins, just forgot to rename it.
__________________
Chaosxk 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 01:56.


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