AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved coding error (https://forums.alliedmods.net/showthread.php?t=344868)

Hakim Azizov 12-14-2023 11:25

coding error
 
Hi all, why this code doesn't work?

Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <hamsandwich>
#include <zombieplague>

#define PLUGIN "[ZP] Special Player Models"
#define VERSION "1.0"
#define AUTHOR "HakimKILLER44"

new const model_list[][][] =
{
        { "HakimKILLER44", {"owner_human_stonre", "owner_human_troll"}} // oyuncu id ve ya ismi, 
}

public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR)
        RegisterHam(Ham_Spawn, "player", "ham_spawn_post", 1)
}

public plugin_precache()
{
        new modelstring[128]
       
        for (new i = 0; i < sizeof(model_list); i++)
        {
                for (new j = 0; j < sizeof(model_list[i][1]); j++)
                {
                        formatex(modelstring, modelstring, "models/player/%s/%s.mdl", model_list[i][1][j], model_list[i][1][j])
                        precache_model(modelstring)
                }
        }
}

public ham_spawn_post(id)
{
        if (id < 1 || id > get_maxplayers())
                return
       
        if (!is_user_connected(id) || zp_get_user_zombie(id))
                return
       
        set_user_human_model(id)
}

public zp_user_humanized_post(id)
{
        if (id < 1 || id > get_maxplayers())
                return
       
        if (!is_user_connected(id) || zp_get_user_zombie(id))
                return
       
        set_user_human_model(id)
}

public set_user_human_model(id)
{
        new name[32], auth[35]
        get_user_authid(id, auth, charsmax(auth))
        get_user_name(id, name, charsmax(name))
       
        for (new i = 0; i < sizeof(model_list); i++)
        {
                if (containi(model_list[i][0], "STEAM_") != 1) // with steamid
                {
                        new random_model = model_list[i][1][random_num(0, charsmax(model_list[i][1]) - 1)]
                        cs_set_user_model(id, random_model)
                }
                else // with name
                {
                        new random_model = model_list[i][1][random_num(0, charsmax(model_list[i][1]) - 1)]
                        cs_set_user_model(id, random_model)
                }
        }
}


Hakim Azizov 12-14-2023 14:49

Re: coding error
 
anybody has no idea?

DJEarthQuake 12-14-2023 20:49

Re: coding error
 
Debug each line. Without sharing the custom include one is liable to be wondering much longer.

bigdaddy424 12-14-2023 22:24

Re: coding error
 
because arrays dont behave like json

fysiks 12-14-2023 23:57

Re: coding error
 
It looks like you need to read up on the basics of programming for plugins. You can find some good tutorials listed here. Specifically, you likely need to look at strings and arrays.

101 12-15-2023 04:24

Re: coding error
 
Quote:

Originally Posted by Hakim Azizov (Post 2814467)
Hi all, why this code doesn't work?

Because of 3d array and the function containi which is not exist .
i didn't know what u want from loop #1 , so i have to guess :

PHP Code:

#include <amxmisc>
#include <cstrike>
#include <hamsandwich>
#include <zombieplague>

#define PLUGIN "[ZP] Special Player Models"
#define VERSION "1.0"
#define AUTHOR "HakimKILLER44"

/*
 By Given Data Below : model_list looks like this : model_list[4][3][19]
 4 : is number of rows 
 3 : is number of columns per a row 
 19 : is the max letters per column 
 Note : leave it empty if u don't know the size 
*/

new const model_list[][][] = 
{
    {{
"HakimKILLER44"},{"owner_human_stonre"}, {"owner_human_troll"}},
    {{
"HakimKILLER43"},{"owner_human_stonre"}, {"owner_human_troll"}},
    {{
"HakimKILLER42"},{"owner_human_stonre"}, {"owner_human_troll"}},
    {{
"HakimKILLER41"},{"owner_human_stonre"}, {"owner_human_troll"}} 
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Spawn"player""ham_spawn_post"1)
}

public 
plugin_precache()
{
    new 
modelstring[128]
    
    for (new 
0sizeof(model_list); i++)
    {
        for (new 
13j++)
        {
            
//model_list[i][0] is the player name (row #i with column #0)
            //model_list[i][1] is the first model  (row #i with column #1)
            //model_list[i][2] is the second model  (row #i with column #2)

            
formatex(modelstring,128,"models/player/%s/%s.mdl"model_list[i][0], model_list[i][j])
            
precache_model(modelstring)
        }
    }
}

public 
ham_spawn_post(id)
{
    if (
id || id get_maxplayers())
        return
    
    if (!
is_user_connected(id) || zp_get_user_zombie(id))
        return
    
    
set_user_human_model(id)
}

public 
zp_user_humanized_post(id)
{
    if (
id || id get_maxplayers())
        return
    
    if (!
is_user_connected(id) || zp_get_user_zombie(id))
        return
    
    
set_user_human_model(id)
}

public 
set_user_human_model(id)
{
    new 
name[32], auth[35]
    
get_user_authid(idauthcharsmax(auth))
    
get_user_name(idnamecharsmax(name))
    
    for (new 
0sizeof(model_list); i++)
    {
        if (
contain(model_list[i][0],auth) != || contain(model_list[i][0],name) != -1
        {
            
//I don't know if this will work : 
            
cs_set_user_model(idmodel_list[i][random_num(1,2)])
            
/*
            Or u have to do this  :
            new modelstring[128]
            formatex(modelstring,128,"models/player/%s/%s.mdl", model_list[i][0], model_list[i][random_num(1,2)])
            cs_set_user_model(id, modelstring)
            */
        
}
    }



Hakim Azizov 12-15-2023 11:41

Re: coding error
 
Quote:

Originally Posted by 101 (Post 2814497)
Because of 3d array and the function containi which is not exist .
i didn't know what u want from loop #1 , so i have to guess :

PHP Code:

#include <amxmisc>
#include <cstrike>
#include <hamsandwich>
#include <zombieplague>

#define PLUGIN "[ZP] Special Player Models"
#define VERSION "1.0"
#define AUTHOR "HakimKILLER44"

/*
 By Given Data Below : model_list looks like this : model_list[4][3][19]
 4 : is number of rows 
 3 : is number of columns per a row 
 19 : is the max letters per column 
 Note : leave it empty if u don't know the size 
*/

new const model_list[][][] = 
{
    {{
"HakimKILLER44"},{"owner_human_stonre"}, {"owner_human_troll"}},
    {{
"HakimKILLER43"},{"owner_human_stonre"}, {"owner_human_troll"}},
    {{
"HakimKILLER42"},{"owner_human_stonre"}, {"owner_human_troll"}},
    {{
"HakimKILLER41"},{"owner_human_stonre"}, {"owner_human_troll"}} 
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Spawn"player""ham_spawn_post"1)
}

public 
plugin_precache()
{
    new 
modelstring[128]
    
    for (new 
0sizeof(model_list); i++)
    {
        for (new 
13j++)
        {
            
//model_list[i][0] is the player name (row #i with column #0)
            //model_list[i][1] is the first model  (row #i with column #1)
            //model_list[i][2] is the second model  (row #i with column #2)

            
formatex(modelstring,128,"models/player/%s/%s.mdl"model_list[i][0], model_list[i][j])
            
precache_model(modelstring)
        }
    }
}

public 
ham_spawn_post(id)
{
    if (
id || id get_maxplayers())
        return
    
    if (!
is_user_connected(id) || zp_get_user_zombie(id))
        return
    
    
set_user_human_model(id)
}

public 
zp_user_humanized_post(id)
{
    if (
id || id get_maxplayers())
        return
    
    if (!
is_user_connected(id) || zp_get_user_zombie(id))
        return
    
    
set_user_human_model(id)
}

public 
set_user_human_model(id)
{
    new 
name[32], auth[35]
    
get_user_authid(idauthcharsmax(auth))
    
get_user_name(idnamecharsmax(name))
    
    for (new 
0sizeof(model_list); i++)
    {
        if (
contain(model_list[i][0],auth) != || contain(model_list[i][0],name) != -1
        {
            
//I don't know if this will work : 
            
cs_set_user_model(idmodel_list[i][random_num(1,2)])
            
/*
            Or u have to do this  :
            new modelstring[128]
            formatex(modelstring,128,"models/player/%s/%s.mdl", model_list[i][0], model_list[i][random_num(1,2)])
            cs_set_user_model(id, modelstring)
            */
        
}
    }



thanks man, this is my wanted answer. )


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

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