Raised This Month: $ Target: $400
 0% 

PLugin server CPU Optimization


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
raa
Senior Member
Join Date: Oct 2005
Old 12-06-2006 , 21:49   PLugin server CPU Optimization
Reply With Quote #1

How could the below code be optimized/made to use less server cpu resources?

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


public plugin_init() {
	register_plugin("Bender model replacement", "0.1", "Front Line & nightscream - modified by raa")
	register_event("ResetHUD", "resetModel", "b")
	register_logevent("Event_RoundStart",2,"0=World triggered","1=Round_Start");
	return PLUGIN_CONTINUE
}

new g_szMdl[] = "models/b_hostage.mdl";

public plugin_precache() {
	
	precache_model("models/player/b_terror/b_terror.mdl")
	precache_model("models/player/b_arctic/b_arctic.mdl")
	precache_model("models/player/b_leet/b_leet.mdl")
	precache_model("models/player/b_guerilla/b_guerilla.mdl")
	
	precache_model("models/player/b_gsg9/b_gsg9.mdl")
	precache_model("models/player/b_urban/b_urban.mdl")
	precache_model("models/player/b_sas/b_sas.mdl")
	precache_model("models/player/b_gign/b_gign.mdl")
	
	precache_model("models/player/b_vip/b_vip.mdl")
	if(file_exists(g_szMdl))
		precache_model(g_szMdl);
	
	
	
	return PLUGIN_CONTINUE
}

public Event_RoundStart()
	{
	new iEnt;
	while((iEnt = find_ent_by_class(iEnt,"hostage_entity")) != 0)
		{
		if(file_exists(g_szMdl))
			entity_set_model(iEnt,g_szMdl);
	}
}

public resetModel(id) {
	new usermodel[33]
	cs_get_user_model(id, usermodel, 32)
	if(cs_get_user_team(id) == CS_TEAM_CT) {
		if(equali(usermodel, "GSG9")) {
			cs_set_user_model(id, "b_gsg9")
			}else{
			
			if(equali(usermodel, "GIGN")) {
				cs_set_user_model(id, "b_gign")
				}else{
				
				if(equali(usermodel, "URBAN")) {
					cs_set_user_model(id, "b_urban")
					}else{
					if(equali(usermodel, "SAS")) {
						cs_set_user_model(id, "b_sas")
						}else{
						
						if(equali(usermodel, "VIP")) {
							cs_set_user_model(id, "b_vip")
						}
					}
				}
			}
		}
	}
	if(equali(usermodel, "TERROR")) {
		
		cs_set_user_model(id, "b_terror")
		
		}else{
		
		if(equali(usermodel, "ARCTIC")) {
			
			cs_set_user_model(id, "b_arctic")
			
			}else{
			
			if(equali(usermodel, "GUERILLA")) {
				
				cs_set_user_model(id, "b_guerilla")
				}else{
				
				if(equali(usermodel, "LEET")) {
					
					cs_set_user_model(id, "b_leet")
					
				}
			}
		}
	}
	return PLUGIN_HANDLED
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1252\\ deff0\\ deflang1033{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/
raa is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 12-06-2006 , 22:30   Re: PLugin server CPU Optimization
Reply With Quote #2

See if you can come up with something yourself .

http://wiki.amxmodx.org/index.php/Optimizing_Plugins
stupok is offline
watch
Senior Member
Join Date: Sep 2005
Old 12-07-2006 , 07:27   Re: PLugin server CPU Optimization
Reply With Quote #3

If you really have to check the model file exists make a global variable
g_exists = file_exists(g_szMdl)
Then rather than calling a natives all the time you can just do if (g_exists) {

Also look up switch statements to replace all that if else else elsekadiwadowamawmdawd stuff and you might also look up how to use 'if' properly. :>
http://wiki.amxmodx.org/index.php/Pa...tch_Statements
__________________
Code:
#include <amusing_small_signiture>

Last edited by watch; 12-07-2006 at 07:40.
watch is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 12-07-2006 , 09:09   Re: PLugin server CPU Optimization
Reply With Quote #4

Cache the model names.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 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 06:50.


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