AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   PLugin server CPU Optimization (https://forums.alliedmods.net/showthread.php?t=48193)

raa 12-06-2006 21:49

PLugin server CPU Optimization
 
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 }
*/


stupok 12-06-2006 22:30

Re: PLugin server CPU Optimization
 
See if you can come up with something yourself :).

http://wiki.amxmodx.org/index.php/Optimizing_Plugins

watch 12-07-2006 07:27

Re: PLugin server CPU Optimization
 
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

Zenith77 12-07-2006 09:09

Re: PLugin server CPU Optimization
 
Cache the model names.


All times are GMT -4. The time now is 06:50.

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