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

Plugin Cvar per Map or Prefix


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ark_Procession
Senior Member
Join Date: Jun 2020
Location: Argentina
Old 01-17-2024 , 10:46   Plugin Cvar per Map or Prefix
Reply With Quote #1

Hi!

I just requested a plugin for bot freezetime for example (along many others that i can't set cvars to a specific value other than the amxx.cfg file)

HTML Code:
#include <amxmodx>
#include <engine>

#define PLUGIN "Bot Freeze"
#define VERSION "1.0"
#define AUTHOR "mlibre"

new const bot_cvar[][] =
{
	0,
	"bot_freeze",
	"yb_freeze_bots"
}

new mp_bot_freezetime, type

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_logevent("logevent_round_start", 2, "1=Round_Start") 
	
	mp_bot_freezetime = register_cvar("mp_bot_freezetime", "10")	//<-starts after mp_freezetime
}

public plugin_cfg()
{
	for(new i = 1; i < sizeof bot_cvar; i++)
	{
		if(cvar_exists(bot_cvar[i])) 
		{
			type = i
			
			break
		}
	}
	
	mp_bot_freezetime = get_pcvar_num(mp_bot_freezetime)
}

public logevent_round_start()
{
	if(task_exists(666))
	{
		remove_task(666)
	}
	
	set_task(float(mp_bot_freezetime), "bot_task", 666)
	
	bot_action(1)
}

public bot_task()
{
	bot_action(0)
}

stock bot_action(x)
{
	switch(type) 
	{
		case 1,2: set_cvar_num(bot_cvar[type], x)
		default:
		{
			new bots[32], maxbots
			
			get_players(bots, maxbots, "adh")
			
			for(new i, id; i < maxbots; i++)
			{
				id = bots[i]
				
				if(x)
					entity_set_int(id, EV_INT_flags, entity_get_int(id, EV_INT_flags) | FL_FROZEN)
				else
					entity_set_int(id, EV_INT_flags, entity_get_int(id, EV_INT_flags) & ~FL_FROZEN)
			}
		}
	}
}
SO, i noticed in the console that the cvar actually changes, but there is no impact on this particular plugin code i attached here.

so if i am on a fy_ map i see the cvar mp_bot_freezetime is indeed 0 and in a de_ map the cvar is indeed 30.
But its like its delayed, i have 0 seconds in de_ maps and 30 in fy_
Why is there an additional or 2 changelevels needed for the plugin actually work?

This is driving me insane!

Last edited by Ark_Procession; 01-17-2024 at 21:23. Reason: More Discoveries
Ark_Procession is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-17-2024 , 23:42   Re: Plugin Cvar per Map or Prefix
Reply With Quote #2

The per-map/prefix config files are executed 6.1 seconds after the cvar value is read by this plugin. This is completely unnecessary for a plugin like this. Use this version instead:

Code:
#include <amxmodx>
#include <engine>

#define PLUGIN "Bot Freeze"
#define VERSION "2.0"
#define AUTHOR "mlibre, fixed"

new const bot_cvar[][] =
{
	0,
	"bot_freeze",
	"yb_freeze_bots"
}

new g_pCvar, type

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_logevent("logevent_round_start", 2, "1=Round_Start") 
	
	g_pCvar = register_cvar("mp_bot_freezetime", "10")	//<-starts after mp_freezetime
}

public plugin_cfg()
{
	for(new i = 1; i < sizeof bot_cvar; i++)
	{
		if(cvar_exists(bot_cvar[i])) 
		{
			type = i
			
			break
		}
	}
	
}

public logevent_round_start()
{
	if(task_exists(666))
	{
		remove_task(666)
	}
	
	set_task(get_pcvar_float(g_pCvar), "bot_task", 666)
	
	bot_action(1)
}

public bot_task()
{
	bot_action(0)
}

stock bot_action(x)
{
	switch(type) 
	{
		case 1,2: set_cvar_num(bot_cvar[type], x)
		default:
		{
			new bots[32], maxbots
			
			get_players(bots, maxbots, "adh")
			
			for(new i, id; i < maxbots; i++)
			{
				id = bots[i]
				
				if(x)
					entity_set_int(id, EV_INT_flags, entity_get_int(id, EV_INT_flags) | FL_FROZEN)
				else
					entity_set_int(id, EV_INT_flags, entity_get_int(id, EV_INT_flags) & ~FL_FROZEN)
			}
		}
	}
}
__________________
fysiks is offline
Ark_Procession
Senior Member
Join Date: Jun 2020
Location: Argentina
Old 01-19-2024 , 17:21   Re: Plugin Cvar per Map or Prefix
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
The per-map/prefix config files are executed 6.1 seconds after the cvar value is read by this plugin. This is completely unnecessary for a plugin like this. Use this version instead:

Code:
#include <amxmodx>
#include <engine>

#define PLUGIN "Bot Freeze"
#define VERSION "2.0"
#define AUTHOR "mlibre, fixed"

new const bot_cvar[][] =
{
	0,
	"bot_freeze",
	"yb_freeze_bots"
}

new g_pCvar, type

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_logevent("logevent_round_start", 2, "1=Round_Start") 
	
	g_pCvar = register_cvar("mp_bot_freezetime", "10")	//<-starts after mp_freezetime
}

public plugin_cfg()
{
	for(new i = 1; i < sizeof bot_cvar; i++)
	{
		if(cvar_exists(bot_cvar[i])) 
		{
			type = i
			
			break
		}
	}
	
}

public logevent_round_start()
{
	if(task_exists(666))
	{
		remove_task(666)
	}
	
	set_task(get_pcvar_float(g_pCvar), "bot_task", 666)
	
	bot_action(1)
}

public bot_task()
{
	bot_action(0)
}

stock bot_action(x)
{
	switch(type) 
	{
		case 1,2: set_cvar_num(bot_cvar[type], x)
		default:
		{
			new bots[32], maxbots
			
			get_players(bots, maxbots, "adh")
			
			for(new i, id; i < maxbots; i++)
			{
				id = bots[i]
				
				if(x)
					entity_set_int(id, EV_INT_flags, entity_get_int(id, EV_INT_flags) | FL_FROZEN)
				else
					entity_set_int(id, EV_INT_flags, entity_get_int(id, EV_INT_flags) & ~FL_FROZEN)
			}
		}
	}
}
Hi! thanks for anwering.

Author made this update on his github that fixed the error, thoughts?

HTML Code:
#include <amxmodx>
#include <engine>

#define PLUGIN "Bot Freeze"
#define VERSION "1.1"
#define AUTHOR "mlibre"

new const bot_cvar[][] =
{
	0,
	"bot_freeze",
	"yb_freeze_bots"
}

new mp_bot_freezetime, type

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_logevent("logevent_round_start", 2, "1=Round_Start") 
	
	mp_bot_freezetime = register_cvar("mp_bot_freezetime", "10")	//<-starts after mp_freezetime
}

public plugin_cfg()
{
	for(new i = 1; i < sizeof bot_cvar; i++)
	{
		if(cvar_exists(bot_cvar[i])) 
		{
			type = i
			
			break
		}
	}
}

public logevent_round_start()
{
	if(task_exists(666))
	{
		remove_task(666)
	}
	
	set_task(float(get_pcvar_num(mp_bot_freezetime)), "bot_task", 666)
	
	bot_action(1)
}

public bot_task()
{
	bot_action(0)
}

stock bot_action(x)
{
	switch(type) 
	{
		case 1,2: set_cvar_num(bot_cvar[type], x)
		default:
		{
			new bots[32], maxbots
			
			get_players(bots, maxbots, "adh")
			
			for(new i, id; i < maxbots; i++)
			{
				id = bots[i]
				
				if(x)
					entity_set_int(id, EV_INT_flags, entity_get_int(id, EV_INT_flags) | FL_FROZEN)
				else
					entity_set_int(id, EV_INT_flags, entity_get_int(id, EV_INT_flags) & ~FL_FROZEN)
			}
		}
	}
}
Ark_Procession is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-19-2024 , 17:57   Re: Plugin Cvar per Map or Prefix
Reply With Quote #4

It's functionally the same.
__________________
fysiks 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 09:04.


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