Raised This Month: $305 Target: $400
 76%   Almost there!

player_spawn - fails to keep setting after respawn.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ph
AlliedModders Donor
Join Date: Mar 2006
Old 07-19-2019 , 16:24   player_spawn - fails to keep setting after respawn.
Reply With Quote #1

Team Fortress 2

Script below works, but the client keeps having to type !kson after respawn.
Code:
#pragma semicolon 1
#include <sourcemod>

public OnPluginStart()
{
    RegAdminCmd( "sm_kson", Cmd_Enable, ADMFLAG_CUSTOM6 );
}

public Action:Cmd_Enable( client, args )
{
    SetEntProp( client, Prop_Send, "m_nStreaks", 100 );
    return Plugin_Handled;
}
How do I....
enable for the player (client) to aviod the need to type !kson *again* after respawn.
__________________
ph is offline
Dr.Doctor
AlliedModders Donor
Join Date: Feb 2017
Location: Hong Kong
Old 07-19-2019 , 16:50   Re: player_spawn - fails to keep setting after respawn.
Reply With Quote #2

Try this
PHP Code:
#pragma semicolon 1

#include <sourcemod>

bool g_bEnableKson[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_kson"Cmd_EnableADMFLAG_CUSTOM6);
    
    
HookEvent("player_spawn"Event_PlayerSpawn);
}

public 
void OnClientPutInServer(int client)
{
    
g_bEnableKson[client] = false;
}

public 
Action Cmd_Enable(int clientint args)
{
    if (
client <= || client MaxClients || !IsClientInGame(client))
    {
        return 
Plugin_Handled;
    }
    
    
g_bEnableKson[client] = !g_bEnableKson[client];
    
    if (
g_bEnableKson[client])
    {
        
SetEntProp(clientProp_Send"m_nStreaks"100);
    }
    
    return 
Plugin_Handled;
}

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

    if (
g_bEnableKson[client])
    {
        
SetEntProp(clientProp_Send"m_nStreaks"100);
    }

__________________
Dr.Doctor is offline
ph
AlliedModders Donor
Join Date: Mar 2006
Old 07-19-2019 , 17:09   Re: player_spawn - fails to keep setting after respawn.
Reply With Quote #3

Thank you very much, really appreciated.

Working nicely.
__________________
ph is offline
ph
AlliedModders Donor
Join Date: Mar 2006
Old 03-25-2021 , 12:08   Re: player_spawn - fails to keep setting after respawn.
Reply With Quote #4

Quote:
Originally Posted by Dr.Doctor View Post
Try this
PHP Code:
#pragma semicolon 1

#include <sourcemod>

bool g_bEnableKson[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_kson"Cmd_EnableADMFLAG_CUSTOM6);
    
    
HookEvent("player_spawn"Event_PlayerSpawn);
}

public 
void OnClientPutInServer(int client)
{
    
g_bEnableKson[client] = false;
}

public 
Action Cmd_Enable(int clientint args)
{
    if (
client <= || client MaxClients || !IsClientInGame(client))
    {
        return 
Plugin_Handled;
    }
    
    
g_bEnableKson[client] = !g_bEnableKson[client];
    
    if (
g_bEnableKson[client])
    {
        
SetEntProp(clientProp_Send"m_nStreaks"100);
    }
    
    return 
Plugin_Handled;
}

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

    if (
g_bEnableKson[client])
    {
        
SetEntProp(clientProp_Send"m_nStreaks"100);
    }


Can the script be amended to do the following:-


a) !kson automatically applied on player connection/join, without typing !kson (ADMFLAG_CUSTOM6)


Thanks in advance.
__________________

Last edited by ph; 03-25-2021 at 12:10.
ph is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-25-2021 , 13:20   Re: player_spawn - fails to keep setting after respawn.
Reply With Quote #5

Try this :/
Code:
#pragma semicolon 1

#include <sourcemod>

bool g_bEnableKson[MAXPLAYERS + 1];

public void OnPluginStart()
{
    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];
    
    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 client = GetClientOfUserId(event.GetInt("userid"));

    if (g_bEnableKson[client])
    {
        SetEntProp(client, Prop_Send, "m_nStreaks", 100);
    }
}
Bacardi is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 03-25-2021 , 13:22   Re: player_spawn - fails to keep setting after respawn.
Reply With Quote #6

Quote:
Originally Posted by ph View Post
Can the script be amended to do the following:-


a) !kson automatically applied on player connection/join, without typing !kson (ADMFLAG_CUSTOM6)


Thanks in advance.
PHP Code:

#pragma semicolon 1 

#include <sourcemod> 

bool g_bEnableKson[MAXPLAYERS 1]; 

public 
void OnPluginStart() 

    
RegAdminCmd("sm_kson"Cmd_EnableADMFLAG_CUSTOM6); 
     
    
HookEvent("player_spawn"Event_PlayerSpawn); 


public 
void OnClientPutInServer(int client

    
g_bEnableKson[client] = false
}

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

public 
Action Cmd_Enable(int clientint args

    if (
client <= || client MaxClients || !IsClientInGame(client)) 
    { 
        return 
Plugin_Handled
    } 
     
    
g_bEnableKson[client] = !g_bEnableKson[client]; 
     
    if (
g_bEnableKson[client]) 
    { 
        
SetEntProp(clientProp_Send"m_nStreaks"100); 
    } 
     
    return 
Plugin_Handled


public 
void Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast

    
int client GetClientOfUserId(event.GetInt("userid")); 

    if (
g_bEnableKson[client]) 
    { 
        
SetEntProp(clientProp_Send"m_nStreaks"100); 
    } 

ThatKidWhoGames is offline
ph
AlliedModders Donor
Join Date: Mar 2006
Old 03-25-2021 , 17:53   Re: player_spawn - fails to keep setting after respawn.
Reply With Quote #7

Thank you, I shall give this a try.
__________________
ph is offline
ph
AlliedModders Donor
Join Date: Mar 2006
Old 03-25-2021 , 19:31   Re: player_spawn - fails to keep setting after respawn.
Reply With Quote #8

Quote:
Originally Posted by ThatKidWhoGames View Post
PHP Code:

#pragma semicolon 1 

#include <sourcemod> 

bool g_bEnableKson[MAXPLAYERS 1]; 

public 
void OnPluginStart() 

    
RegAdminCmd("sm_kson"Cmd_EnableADMFLAG_CUSTOM6); 
     
    
HookEvent("player_spawn"Event_PlayerSpawn); 


public 
void OnClientPutInServer(int client

    
g_bEnableKson[client] = false
}

public 
void OnClientPostAdminCheck(int client)
{
    
g_bEnableKson[client] = CheckCommandAccess(client, &#8220;sm_kson”, ADMFLAG_CUSTOM6);
}

public 
Action Cmd_Enable(int clientint args

    if (
client <= || client MaxClients || !IsClientInGame(client)) 
    { 
        return 
Plugin_Handled
    } 
     
    
g_bEnableKson[client] = !g_bEnableKson[client]; 
     
    if (
g_bEnableKson[client]) 
    { 
        
SetEntProp(clientProp_Send"m_nStreaks"100); 
    } 
     
    return 
Plugin_Handled


public 
void Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast

    
int client GetClientOfUserId(event.GetInt("userid")); 

    if (
g_bEnableKson[client]) 
    { 
        
SetEntProp(clientProp_Send"m_nStreaks"100); 
    } 

Quote:
Originally Posted by Bacardi View Post
Try this :/
Code:
#pragma semicolon 1

#include <sourcemod>

bool g_bEnableKson[MAXPLAYERS + 1];

public void OnPluginStart()
{
    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];
    
    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 client = GetClientOfUserId(event.GetInt("userid"));

    if (g_bEnableKson[client])
    {
        SetEntProp(client, Prop_Send, "m_nStreaks", 100);
    }
}



Both scripts work, but there is a problem.

Example:

A player joins the server, however streak effects failed to be applied immediately, unless player respawns/dies.

Can this be fixed so that the streak effects is instantly applied? rather than waiting to respawn.
__________________

Last edited by ph; 03-25-2021 at 21:02.
ph is offline
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
ph
AlliedModders Donor
Join Date: Mar 2006
Old 03-26-2021 , 07:50   Re: player_spawn - fails to keep setting after respawn.
Reply With Quote #10

Thank you Barcadi, working nicely.

<3
__________________
ph is offline
Reply


Thread Tools
Display Modes

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 18:33.


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