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

Simple plugin freezes game on load


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LOCKJAWVENOM
New Member
Join Date: Jun 2014
Old 12-18-2018 , 07:48   Simple plugin freezes game on load
Reply With Quote #1

I'm a total newbie in every respect (first time posting as well) and this plugin is very simple, so I'm going to assume I'm making a really stupid mistake somewhere here.

This is a very simple Sven Co-op plugin I'm writing that will automatically adjust certain cvars in proportion to the number of players currently connected. I just started writing it and it'll be for personal use, so I'm not worried about efficiency, redundancy, or the fact that there's unnecessary code scattered about. However, I am worried about the fact that the plugin completely freezes the game every time I try to test it to the point where the only option I'm left with afterward is task manager. Removing it from my plugins.ini lets the game load normally and changing the set_task delay directly affects how long the game takes to freeze when loading, so the problem has to be in here somewhere.

Code:
#include <amxmodx>
#include <amxmisc>
#include <core>
#include <fun>
#include <engine>

#define VERSION "1.0"
#define LASTUPDATE "18th, December (12), 2018"

public plugin_init()
{
	register_plugin("Autobalance",VERSION,"AxonVenom")
	create_cvar("autobalance_level","0",FCVAR_NONE,"Sets the current balance level. Default is 0, which is automatic.",true,0.0,false)
	set_task(0.5,"ab_balance",0,"",0,"b")
}

public ab_balance()
{
	set_cvar_num("mp_respawntime",45)
	while(get_cvar_num("autobalance_level")==0)
	{
		//for(new rate=0;rate<100;rate++)
		//{
			new level=get_playersnum()-1
			ab_adjust(level)
		//}
	}
}

public ab_adjust(level)
{
	set_cvar_float("sk_monster_head",4*(3.5-0.5*(level-1)))
	set_cvar_float("sk_monster_chest",1*(3.5-0.5*(level-1)))
	set_cvar_float("sk_monster_stomach",2.5*(3.5-0.5*(level-1)))
	set_cvar_float("sk_monster_arm",0.25*(3.5-0.5*(level-1)))
	set_cvar_float("sk_monster_leg",0.75*(3.5-0.5*(level-1)))
	
	set_cvar_float("sk_player_head",4*(0.75-0.25*(level-1)))
	set_cvar_float("sk_player_chest",1*(0.75-0.25*(level-1)))
	set_cvar_float("sk_player_stomach",2.5*(0.75-0.25*(level-1)))
	set_cvar_float("sk_player_arm",0.25*(0.75-0.25*(level-1)))
	set_cvar_float("sk_player_leg",0.75*(0.75-0.25*(level-1)))
}
LOCKJAWVENOM is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 12-18-2018 , 15:00   Re: Simple plugin freezes game on load
Reply With Quote #2

Quote:
while(get_cvar_num("autobalance_level")==0) // if this cvar is 0, you have infinite loop
{
//for(new rate=0;rate<100;rate++)
//{
new level=get_playersnum()-1
ab_adjust(level)
//}
}
This is an ifinite loop => crash.

Also, 0.5 task is overkill:
Quote:
set_task(0.5,"ab_balance",0,"",0,"b")
Learn about loops.
__________________
My English is A0

Last edited by E1_531G; 12-18-2018 at 15:00.
E1_531G 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 15:15.


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