Raised This Month: $90 Target: $400
 22% 

HookEvent PlayerSpawned and RoundStart with commands


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TrullSin
Senior Member
Join Date: Jun 2018
Old 11-10-2018 , 13:07   HookEvent PlayerSpawned and RoundStart with commands
Reply With Quote #1

Hi, Im trying to execute some commands after player spawned and round started but no results so far. No errors in sourcemod logs.

PHP Code:
#include <sourcemod>

public void OnPluginStart() 
{
    
HookEvent("player_spawned"player_spawned);
    
HookEvent("round_start"round_start);

public 
Action round_start(Event event, const char[] namebool dontBroadcast
{
    
LogMessage("Round Start Working...");
    
ServerCommand("sm_say 123");

}

public 
Action player_spawned(Event event, const char[] namebool dontBroadcast
{
    
LogMessage("Spawn Working...");
    
ServerCommand("sm_say spawned");


*edit
It is for CS:GO

Last edited by TrullSin; 11-10-2018 at 13:39.
TrullSin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-10-2018 , 13:32   Re: HookEvent PlayerSpawned and RoundStart with commands
Reply With Quote #2

In which game ??

Try this in your console when you play...
net_dumpeventstats

*edit
dam, CS:GO cvar
__________________
Do not Private Message @me

Last edited by Bacardi; 11-10-2018 at 13:35.
Bacardi is offline
Rohanlogs
Senior Member
Join Date: Nov 2015
Old 11-10-2018 , 13:57   Re: HookEvent PlayerSpawned and RoundStart with commands
Reply With Quote #3

Your round start looks OK but instead of
PHP Code:
HookEvent("player_spawned"player_spawned); 
Do
PHP Code:
HookEvent("player_spawn"player_spawned); 
And to get client index in spawn use
PHP Code:
GetClientOfUserIdevent.GetInt("userid") ); 
__________________
Rohanlogs is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 11-10-2018 , 14:38   Re: HookEvent PlayerSpawned and RoundStart with commands
Reply With Quote #4

If you wish to exclude player_spawn that is due to stuff like mp_respawn_on_death_t/ct or !revive, you'll have to hook for player_spawn as usual but make another two conditions that the player didn't die this round AND that when he spawned, GetGameTime() < GameRules_GetPropFloat("m_fRoundStartTime") + GetConVarFloat(FindConVar("mp_join_grace_time ") + GetConVarFloat(FindConVar("mp_freezetime")).

IIRC, you can only get the value of freezetime in the beginning of the round and not in the spawn since it's only effective when a round starts. About mp_join_grace_time I really don't know.
__________________
Accepting private work. Contact me if you're interested.
If you like my work, feel free to donate in appreciation with PayPal or CSGO Skins.

Total Donated: 10$

Last edited by eyal282; 11-10-2018 at 14:42.
eyal282 is online now
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine
Old 11-13-2018 , 18:48   Re: HookEvent PlayerSpawned and RoundStart with commands
Reply With Quote #5

Quote:
ServerCommand("sm_say 123");
Why not PrintToChatAll ?

You need to make a little delay (using Timer) to see that round start msg, as well as a delay on player_spawn if you want to apply player specific commands.
__________________
Expert of CMD/VBS/VB6. Malware analyst.
Dragokas is offline
poachedegg
Junior Member
Join Date: Nov 2018
Location: China
Old 11-18-2018 , 22:07   Re: HookEvent PlayerSpawned and RoundStart with commands
Reply With Quote #6

Maybe it's because sm_say is a console command, I thought.
poachedegg is offline
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 11-19-2018 , 02:23   Re: HookEvent PlayerSpawned and RoundStart with commands
Reply With Quote #7

PHP Code:
#include <sourcemod>

public void OnPluginStart() 
{
    
HookEvent("player_spawn"player_spawn);
    
HookEvent("round_start"round_start);
}

public 
Action round_start(Event event, const char[] namebool dontBroadcast
{
    
LogMessage("Round Start Working...");
    
PrintToChatAll("123... Round Start Working");
    
ServerCommand("mp_buy_allow_grenades 0"); // disable grenades
    
PrintToChatAll("disabled grenades");
}

public 
Action player_spawn(Event event, const char[] namebool dontBroadcast
{
    
LogMessage("Spawn Working...");
    
PrintToChatAll("spawned");
    
ServerCommand("mp_friendlyfire 0"); // To turn FF 0 after player spawned
    
PrintToChatAll("FF set to 0");


Last edited by iskenderkebab33; 11-19-2018 at 07:19.
iskenderkebab33 is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Rimini, Italy
Old 11-19-2018 , 13:25   Re: HookEvent PlayerSpawned and RoundStart with commands
Reply With Quote #8

Quote:
Originally Posted by iskenderkebab33 View Post
PHP Code:
#include <sourcemod>

public void OnPluginStart() 
{
    
HookEvent("player_spawn"player_spawn);
    
HookEvent("round_start"round_start);
}

public 
Action round_start(Event event, const char[] namebool dontBroadcast
{
    
LogMessage("Round Start Working...");
    
PrintToChatAll("123... Round Start Working");
    
ServerCommand("mp_buy_allow_grenades 0"); // disable grenades
    
PrintToChatAll("disabled grenades");
}

public 
Action player_spawn(Event event, const char[] namebool dontBroadcast
{
    
LogMessage("Spawn Working...");
    
PrintToChatAll("spawned");
    
ServerCommand("mp_friendlyfire 0"); // To turn FF 0 after player spawned
    
PrintToChatAll("FF set to 0");

Do not use ServerCommand to set a cvar value, do:

PHP Code:
FindConVar("mp_friendlyfire").BoolValue false;
//or
FindConVar("mp_friendlyfire").SetBool(false); 
you may also wont to check against the FindConVar("mp_friendlyfire") to don't return null.
__________________
Papero is offline
Send a message via Skype™ to Papero
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 11-19-2018 , 14:16   Re: HookEvent PlayerSpawned and RoundStart with commands
Reply With Quote #9

Quote:
Originally Posted by Papero View Post
Do not use ServerCommand to set a cvar value, do:

PHP Code:
FindConVar("mp_friendlyfire").BoolValue false;
//or
FindConVar("mp_friendlyfire").SetBool(false); 
you may also wont to check against the FindConVar("mp_friendlyfire") to don't return null.
and how to turn it 0 and/or 1?
like this?
PHP Code:
FindConVar("mp_friendlyfire").BoolValue true
and how to give a player start weapon like mp_ct_default_primary
PHP Code:
FindConVar("mp_ct_default_primary").BoolValue "weapon_awp"
aaand why should we don't use ServerCommand to set a cvar value?

Last edited by iskenderkebab33; 11-19-2018 at 14:18.
iskenderkebab33 is offline
Whai
Senior Member
Join Date: Jul 2018
Location: In Hell
Old 11-19-2018 , 17:14   Re: HookEvent PlayerSpawned and RoundStart with commands
Reply With Quote #10

Quote:
Originally Posted by iskenderkebab33 View Post
and how to give a player start weapon like mp_ct_default_primary
PHP Code:
FindConVar("mp_ct_default_primary").BoolValue "weapon_awp"
"weapon_awp" is not a bool value, it's a string or a char if you want, you can do

PHP Code:
FindConVar("mp_ct_default_primary").SetString("weapon_awp"); 
or

PHP Code:
SetConVarString(FindConVar("mp_ct_default_primary"), "weapon_awp"); 
__________________
My GitHub repo. (Plugins are often up to date on GitHub than here)
My plugins

Last edited by Whai; 11-19-2018 at 17:15.
Whai 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 08:27.


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