View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-26-2021 , 06:08   Re: player_spawn - fails to keep setting after respawn.
Reply With Quote #9

- I added check, when player spawn actually in team, not at the time when enter in server (team 0)
- One frame delay after spawn. Maybe game reset something from player at spawn event ?
-- If plugin is reloaded, it loop all clients in game, setting feature back. (They need respawn after this tough )

Code:
#pragma semicolon 1

#include <sourcemod>

bool g_bEnableKson[MAXPLAYERS + 1];

public void OnPluginStart()
{
	// Plugin reloaded ?
	for(int i = 1; i <= MaxClients; i++)
	{
		if(IsClientInGame(i)) OnClientPostAdminCheck(i);
	}


	RegAdminCmd("sm_kson", Cmd_Enable, ADMFLAG_CUSTOM6);

	HookEvent("player_spawn", Event_PlayerSpawn);
}

public void OnClientPostAdminCheck(int client)
{
	g_bEnableKson[client] = CheckCommandAccess(client, "sm_kson", ADMFLAG_CUSTOM6);
}

public Action Cmd_Enable(int client, int args)
{
	if (client <= 0 || client > MaxClients || !IsClientInGame(client))
	{
		return Plugin_Handled;
	}
	
	g_bEnableKson[client] = !g_bEnableKson[client];
	
	ReplyToCommand(client, "[SM] You have %s sm_kson", g_bEnableKson[client] ? "ENABLED":"DISABLED");
	
	if (g_bEnableKson[client])
	{
		SetEntProp(client, Prop_Send, "m_nStreaks", 100);
	}
	
	return Plugin_Handled;
}

public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
	int userid = event.GetInt("userid");
	int client = GetClientOfUserId(userid);

	if (g_bEnableKson[client] && GetClientTeam(client) > 1)
	{
		RequestFrame(nextframe, userid);
	}
}

public void nextframe(int userid)
{
	int client = GetClientOfUserId(userid);
	
	if(!client || !IsClientInGame(client)) return;

	SetEntProp(client, Prop_Send, "m_nStreaks", 100);
}

Last edited by Bacardi; 03-26-2021 at 06:10.
Bacardi is offline