AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   enable/disable a plugin depending on map.. (https://forums.alliedmods.net/showthread.php?t=99391)

HLM 08-04-2009 17:32

enable/disable a plugin depending on map..
 
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <tfcx>

#define PLUGIN "MODEL SETTER"
#define VERSION "0.0.2"
#define AUTHOR "Master"

#define MODEL_NAME_LEN 14
#define MAX_MODELS 256

//precaching was edited in from "very simple precache mod"
// (-  https://forums.alliedmods.net/showthread.php?t=26784  -)
// vey simple precache mod was made by hjvl
//all credit for the precaching code gotes to hjvl (-  https://forums.alliedmods.net/member.php?u=7471  -)


new g_szModels[MAX_MODELS][MODEL_NAME_LEN+1]
new 
g_iModelsNum 
new g_pMenu 
new g_currentmodel[33][65]

public 
handle_say(id
{
    new 
said[192]
    
read_args(said,192)
    
remove_quotes(said)
    
    
    if( (
containi(said"models") != -1) && !(containi(said"!models") != -1) || (containi(said"model") !=-1) && !(containi(said"!models") != -1) && !(containi(said"!model") !=-1) ) {
        
client_print(idprint_chat"[AMXX] For a menu to select your model, say !models")
        
client_print(id,print_chat"[AMXX] Alternatively if you know the modelname, you can say ^"!model MODELNAME^"")
    }
    
    if(
containi(said"!model") != -&& (containi(said"!models") ==-1) )
    {
        
        
replace(said,192,"!model ","")
        
        if(
is_valid_model(said))
        {
            
tfc_setmodel(idsaid"1")
            
client_print(id,print_chat"[AMXX] Player model set to ^"%s^""said)
        }
        else if(!
is_valid_model(said))
        {
            
client_print(id,print_chat"[AMXX] Invalid model, perhaps you should use the menu?")
        }
        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_CONTINUE
}


public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("amx_model","set_model",0,"<skin name>"
    
register_concmd("amx_modelmenu""cmdModelMenu"0" - Displays Menu of possible player models.")
    
register_clcmd("say","handle_say")
    
register_clcmd("say !models","cmdModelMenu"0" - Displays Menu of possible player models.")
    
register_clcmd("say !random","random_model",0,"Sets a Random model")
    
register_cvar("amx_pmod_mode","0"FCVAR_SPONLY)
    
    
    
}

public 
plugin_precache()
{
    new 
mode =(get_cvar_num("amx_pmod_mode"))
    
    new 
szModelFilePath[64]
    
get_configsdir(szModelFilePathsizeof(szModelFilePath) - 1)
    if(
mode == 2)
    {
        
add(szModelFilePathsizeof(szModelFilePath) - 1"/player_models.ini")
        if( 
file_exists(szModelFilePath) )
        {
            new 
fopen(szModelFilePath"rt")
            
            new 
data[20], szModelPath[64]
            
            while( !
feof(f) && g_iModelsNum MAX_MODELS 
            { 
                
fgets(fdatasizeof(data) - 1)
                
                
trim(data)
                if( !
data[0] || data[0] == ';' || data[0] == '/' && data[1] == '/' ) continue;
                
                
// Stuff here.
                
server_print(">>>%s<<<"data)
                
formatex(szModelPath63"models/player/%s/%s.mdl"datadata)
                if(
file_exists(szModelPath))
                {
                    
server_print("File exists!!!! ^"%s^""szModelPath)
                    
precache_model(szModelPath)
                    
copy(g_szModels[g_iModelsNum], MODEL_NAME_LENdata)
                    
g_iModelsNum++
                }
                else
                {
                    
server_print("DNE DNE!!!! ^"%s^""szModelPath)
                }
            }
            
            
fclose(f)
        }
        
// Build Model Menu:
        
g_pMenu menu_create("Player Models""actionModelMenu")
        new 
str[6]
        
menu_additem(g_pMenu"Off""-1"// First option is to reset the model
        
for(new 0g_iModelsNumi++)
        {
            
num_to_str(istr5)
            
menu_additem(g_pMenug_szModels[i], str)
        }
        
// for(new i = 0; i < 20; i++)
        // { // Here just to check how pages work with the "new" menu style.
        // menu_additem(g_pMenu, "Option", "-2")
        // }
        
menu_setprop(g_pMenuMPROP_EXITMEXIT_ALL)
        return 
PLUGIN_CONTINUE
    
}
    
    else if(
mode == 1)
    {
        
add(szModelFilePathsizeof(szModelFilePath) - 1"/pmod_lite.ini")
        if( 
file_exists(szModelFilePath) )
        {
            new 
fopen(szModelFilePath"rt")
            
            new 
data[20], szModelPath[64]
            
            while( !
feof(f) && g_iModelsNum MAX_MODELS 
            { 
                
fgets(fdatasizeof(data) - 1)
                
                
trim(data)
                if( !
data[0] || data[0] == ';' || data[0] == '/' && data[1] == '/' ) continue;
                
                
// Stuff here.
                
server_print(">>>%s<<<"data)
                
formatex(szModelPath63"models/player/%s/%s.mdl"datadata)
                if(
file_exists(szModelPath))
                {
                    
server_print("File exists!!!! ^"%s^""szModelPath)
                    
precache_model(szModelPath)
                    
copy(g_szModels[g_iModelsNum], MODEL_NAME_LENdata)
                    
g_iModelsNum++
                }
                else
                {
                    
server_print("DNE DNE!!!! ^"%s^""szModelPath)
                }
            }
            
            
fclose(f)
        }
        
// Build Model Menu:
        
g_pMenu menu_create("Player Models""actionModelMenu")
        new 
str[6]
        
menu_additem(g_pMenu"Off""-1"// First option is to reset the model
        
for(new 0g_iModelsNumi++)
        {
            
num_to_str(istr5)
            
menu_additem(g_pMenug_szModels[i], str)
        }
        
// for(new i = 0; i < 20; i++)
        // { // Here just to check how pages work with the "new" menu style.
        // menu_additem(g_pMenu, "Option", "-2")
        // }
        
menu_setprop(g_pMenuMPROP_EXITMEXIT_ALL)
        return 
PLUGIN_CONTINUE
    
}
    
    else if(
mode == 0)
    {
        return 
PLUGIN_CONTINUE
    
}
    return 
PLUGIN_CONTINUE
}


public 
set_model(id)
{
    new 
mode =(get_cvar_num("amx_pmod_mode"))
    
    if(
mode == 0)
    {
        
client_print(id,print_console,"[AMXX] Pmod has been disabled for stability reasons!")
        return 
PLUGIN_HANDLED
    
}
    else if((
mode == 1) || (mode == 2))
    {
        new 
szArg[MODEL_NAME_LEN+1]
        
read_argv(1szArgMODEL_NAME_LEN)
        
        if(
equal(szArg"off"))
        {
            
tfc_clearmodel(id)
            
console_print(id"Your model is set to default."szArg)
        }
        else if(
is_valid_model(szArg))
        {
            
tfc_setmodel(idszArg"1")
            
console_print(id"Your model is set to ^"%s^""szArg)
        }
        else
        {
            
console_print(id"Number of Models Loaded: %d"g_iModelsNum)
            for(new 
0g_iModelsNumi++)
            {
                
console_print(id"%d. %s"i+1g_szModels[i])
            }
        }  
        
    }
    return 
PLUGIN_HANDLED
}

bool:is_valid_model(arg[])
{
for(new 
0g_iModelsNumi++)
{
    if(
equal(argg_szModels[i]))
    {
        return 
true
    
}
}
return 
false
}

public 
cmdModelMenu(id,level,cid)
{
new 
mode =(get_cvar_num("amx_pmod_mode"))
if(
mode == 0)
{
    
client_print(id,print_chat,"[AMXX] Pmod has been disabled for stability reasons!")
    return 
PLUGIN_HANDLED
}
else if((
mode == 1) || (mode == 2))
{
    if(!
cmd_access(id,level,cid,1))
    {
        return 
PLUGIN_HANDLED
    
}
    
    
menu_display(idg_pMenu0)
}
return 
PLUGIN_HANDLED
}

public 
actionModelMenu(id,menu,item)
{
if( 
item == MENU_EXIT )
{
    
// DO NOT DESTROY MENU
    
return PLUGIN_HANDLED
}

new 
data[6], iName[64]
new 
access_callback

menu_item_getinfo
(menuitemaccess_data,5iName63callback)

new 
iModelNum str_to_num(data)

if(
iModelNum 0)
{
    
tfc_clearmodel(id)
    
client_print(idprint_chat"[AMXX] Player model is now default.")
}
else
{
    
tfc_setmodel(idg_szModels[iModelNum], "1")
    
client_print(idprint_chat"[AMXX] Player model set to ^"%s^""g_szModels[iModelNum])
}

return 
PLUGIN_HANDLED
}


public 
plugin_end()
{
menu_destroy(g_pMenu)
}

public 
random_model(id)
{
new 
mode =(get_cvar_num("amx_pmod_mode"))

if(
mode == 0)
{
    
client_print(id,print_chat,"[AMXX] Pmod has been disabled for stability reasons!")
    return 
PLUGIN_HANDLED
}
else if((
mode == 1) || (mode ==2))
{
    new 
RandID random_num(1,MAX_MODELS-1)
    if (
is_valid_model(g_szModels[RandID]))
    {
        
tfc_setmodel(idg_szModels[RandID] , "1")
        
client_print(idprint_chat"[AMXX] Model randomly selected as ^"%s^"",g_szModels[RandID])
        
copy(g_currentmodel[id],64,g_szModels[RandID])
    }
    else
    {
        
set_task(0.1,"random_model",id)
    }
}
return 
PLUGIN_HANDLED


basically I want to know if I do..
Code:

amx_pmode_mode 0/1/2
in amxmodx/configs/maps/MAPNAME.cfg will it work properly and load the right file? or none at all, thus not precaching anything or whatnot.. just want to know.. if this will work as I expect it to.. so can someone tell me if it will or not?

Arkshine 08-04-2009 17:54

Re: enable/disable a plugin depending on map..
 
Why don't you test yourself ?

By the way you fail to declare your cvar.

HLM 08-04-2009 17:59

Re: enable/disable a plugin depending on map..
 
yeah, I just found this out... I need to go more in depth with what im doing I guess.. I edited my first post.. the plugin doesnt 'properly' load.. can someone help me out a tiny bit?

there were no errors about a missing log file.. nothing at all when I do a command..

edit: well, I modified the code a little bit, that didnt help.. it wont load any models, even though the log shows it loads NO models, even if I set the right cvar.. can someone help me out?


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

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