Raised This Month: $ Target: $400
 0% 

Simple player model. [Please check]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
happy_2012
Senior Member
Join Date: Aug 2012
Old 10-18-2015 , 13:41   Simple player model. [Please check]
Reply With Quote #1

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;

__________________
Discord contacts:
I rarely look at private messages here, but I am very active on Discord!

Last edited by happy_2012; 10-18-2015 at 13:57. Reason: New code
happy_2012 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-18-2015 , 14:15   Re: Simple player model. [Please check]
Reply With Quote #2

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[].
__________________

Last edited by Arkshine; 10-18-2015 at 14:17.
Arkshine is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 10-18-2015 , 14:24   Re: Simple player model. [Please check]
Reply With Quote #3

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)]);

__________________
Discord contacts:
I rarely look at private messages here, but I am very active on Discord!
happy_2012 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-18-2015 , 16:01   Re: Simple player model. [Please check]
Reply With Quote #4

You will be out of bound with your random_num() for the max value.
__________________
Arkshine is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 10-18-2015 , 16:14   Re: Simple player model. [Please check]
Reply With Quote #5

so sizeof - 1 would solve it?
__________________
Discord contacts:
I rarely look at private messages here, but I am very active on Discord!
happy_2012 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-18-2015 , 16:30   Re: Simple player model. [Please check]
Reply With Quote #6

Would you mind to test things by yourself please? This is the scripting section, you are supposed to learn and test things.
__________________
Arkshine is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 10-18-2015 , 16:32   Re: Simple player model. [Please check]
Reply With Quote #7

Quote:
Originally Posted by Arkshine View Post
Would you mind to test things by yourself please? This is the scripting section, you are supposed to learn and test things.
Okey
__________________
Discord contacts:
I rarely look at private messages here, but I am very active on Discord!
happy_2012 is offline
Reply


Thread Tools
Display Modes

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 22:13.


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