AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Simple player model. [Please check] (https://forums.alliedmods.net/showthread.php?t=273412)

happy_2012 10-18-2015 13:41

Simple player model. [Please check]
 
Hey guys,
I just randomly coded this plugin, and I just wanted to know if it has a good quality and would actually function properly?

PHP Code:

#include < amxmodx >
#include < cstrike >
#include < hamsandwich >

new Array:g_ArrPlayerModel;
new const 
g_szPlayerModel[][] = { "model_one""model_two" };

public 
plugin_precache()
{
    
g_ArrPlayerModel ArrayCreate(321);
    
    new 
Index;
    for(
Index 0Index sizeof g_szPlayerModelIndex++)
        
ArrayPushString(g_ArrPlayerModelg_szPlayerModel[index]);
    
    new 
Path[100];
    for(
Index 0Index ArraySize(g_ArrPlayerModel); Index++)
    {
        
ArrayGetString(g_ArrPlayerModelIndexPathcharsmax(Path));
        
format(Pathcharsmax(Path), "models/player/%s/%s.mdl"PathPath);
        
precache_model(Path);
        
        
format(Pathcharsmax(Path), "models/player/%s/%sT.mdl"PathPath);
        if( 
file_exists(Path) )
            
precache_model(Path);
    }
}

public 
plugin_init()
{
    
register_plugin("Model Set""1.0""Chilimax");
    
    
RegisterHam(Ham_Spawn"player""Ham_PlayerSpawn_Post"true);
}

public 
Ham_PlayerSpawn_Post(Index)
{
    if( !
is_user_alive(Index) || !cs_get_user_team(Index) )
        return;
    
    new 
Model[32];
    
ArrayGetString(g_ArrPlayerModelrandom_num(0ArraySize(g_ArrPlayerModel) - 1), Modelcharsmax(Model));
    
cs_set_user_model(IndexModel);


And what about this one, too?
PHP Code:

#include < amxmodx >
#include < cstrike >
#include < hamsandwich >

new const g_szPlayerModel[][] = { "model_one""model_two" };

public 
plugin_precache()
{
    new 
Path[100];
    for(
Index 0Index sizeof g_szPlayerModelIndex++)
    {
        
formatex(Pathcharsmax(Path), "models/player/%s/%s.mdl"g_szPlayerModel[Index], g_szPlayerModel[Index]);
        
precache_model(Path);
        
        
formatex(Pathcharsmax(Path), "models/player/%s/%sT.mdl"g_szPlayerModel[Index], g_szPlayerModel[Index]);
        if( 
file_exists(Path) )
            
precache_model(Path);
    }
}

public 
plugin_init()
{
    
register_plugin("Model Set""1.0""Chilimax");
    
    
RegisterHam(Ham_Spawn"player""Ham_PlayerSpawn_Post"true);
}

public 
Ham_PlayerSpawn_Post(Index)
{
    if( !
is_user_alive(Index) || !cs_get_user_team(Index) )
        return;
    
    new 
Model[32];
    
GetRandomModel(random_num(0sizeof g_szPlayerModel), Modelcharsmax(Model));
    
cs_set_user_model(IndexModel);
}

GetRandomModel(iRandomModel[], iLen)
{
    new 
Index;
    for(
Index 0Index sizeof g_szPlayerModelIndex++)
    {
        if( 
iRandom == Index )
            return 
formatex(ModeliLen"%s"g_szPlayerModel[iRandom]);
    }
    
    return -
1;



Arkshine 10-18-2015 14:15

Re: Simple player model. [Please check]
 
Using a Trie with an hard-coded array with few entries is kind of silly.
Looping to get a random model is even more silly, random_num could be used directly in g_szPlayerModel[].

happy_2012 10-18-2015 14:24

Re: Simple player model. [Please check]
 
So just this would work?
PHP Code:

#include < amxmodx >
#include < cstrike >
#include < hamsandwich >

new const g_szPlayerModel[][] = { "model_one""model_two" };

public 
plugin_precache()
{
    new 
Path[100];
    for(
Index 0Index sizeof g_szPlayerModelIndex++)
    {
        
formatex(Pathcharsmax(Path), "models/player/%s/%s.mdl"g_szPlayerModel[Index], g_szPlayerModel[Index]);
        
precache_model(Path);
        
        
formatex(Pathcharsmax(Path), "models/player/%s/%sT.mdl"g_szPlayerModel[Index], g_szPlayerModel[Index]);
        if( 
file_exists(Path) )
            
precache_model(Path);
    }
}

public 
plugin_init()
{
    
register_plugin("Model Set""1.0""Chilimax");
    
    
RegisterHam(Ham_Spawn"player""Ham_PlayerSpawn_Post"true);
}

public 
Ham_PlayerSpawn_Post(Index)
{
    if( !
is_user_alive(Index) || !cs_get_user_team(Index) )
        return;
    
    
cs_set_user_model(Indexg_szPlayerModel[random_num(0sizeof g_szPlayerModel)]);



Arkshine 10-18-2015 16:01

Re: Simple player model. [Please check]
 
You will be out of bound with your random_num() for the max value.

happy_2012 10-18-2015 16:14

Re: Simple player model. [Please check]
 
so sizeof - 1 would solve it?

Arkshine 10-18-2015 16:30

Re: Simple player model. [Please check]
 
Would you mind to test things by yourself please? This is the scripting section, you are supposed to learn and test things.

happy_2012 10-18-2015 16:32

Re: Simple player model. [Please check]
 
Quote:

Originally Posted by Arkshine (Post 2354513)
Would you mind to test things by yourself please? This is the scripting section, you are supposed to learn and test things.

Okey :attack:


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

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