View Single Post
LithuanianJack
Senior Member
Join Date: Nov 2013
Location: Vilnius, Lithuania
Old 01-26-2021 , 03:33   Re: Random locations generator
Reply With Quote #40

Quote:
Originally Posted by HamletEagle View Post
If I want to change superspawns to your's "rog", what is need to be changed in my plugin's code? Can you change that? Thank you.

PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <csgo_skins>
#include <fakemeta> 
#include <hamsandwich> 
#include <engine> 
#include <cellarray> 
#include <xs> 
#include <rog>

#define MAX_MODELS 5
#define MAX_CONTENTS 100
new const model_present[MAX_MODELS][128];
new 
pcvar_presents_on_mapcvar_min_playerscvar_glowcvar_spincvar_glow_enabledcvar_announcemodels_countcvar_spawn_after_time_mincvar_spawn_after_time_max
new presentItems[MAX_CONTENTS][8], hasItem[MAX_CONTENTS][8], presentAmountsMinimum[MAX_CONTENTS][8], presentAmountsMaximum[MAX_CONTENTS][8], Float:presentChances[MAX_CONTENTS];
new 
contentsCount;
public 
plugin_init() 
{
    
register_plugin("CSGO SKINS: Presents""1.0""InvIs")
    
check_extra_plugin();
    
    
register_event("HLTV""spawn_gifts""a""1=0""2=0"
    
register_forward(FM_Touch,"forward_touch"
    
    
pcvar_presents_on_map register_cvar("csgo_presents_on_round""15")
    
cvar_min_players register_cvar("csgo_presents_min_players""5");
    
cvar_glow register_cvar("csgo_presents_glow""255 0 0");
    
cvar_announce register_cvar("csgo_presents_spawn_announce""1");
    
cvar_spin register_cvar("csgo_presents_glow_enabled""1");
    
cvar_glow_enabled register_cvar("csgo_presents_spin""1");
    
cvar_spawn_after_time_min register_cvar("csgo_spawn_after_time_min""5.0");
    
cvar_spawn_after_time_max register_cvar("csgo_spawn_after_time_min""15.0");
    
SsInit(800.0);
    
SsScan();
    
    
loadPresents();
}
public 
giveItems(id)
{
    new 
item pickRandomItem();
    new 
random;
    new 
name[64];
    
get_user_name(idnamecharsmax(name));
    if(
item != -1)
    {
        for(new 
18i++)
        {
            if(
hasItem[item][i] == 1)
            {
                switch(
i)
                {
                    case 
ITEM_TYPE_SKIN:
                    {
                        if(
presentAmountsMinimum[item][i] == presentAmountsMaximum[item][i]) random presentAmountsMinimum[item][i]
                        else 
random random_num(presentAmountsMinimum[item][i], presentAmountsMaximum[item][i]);
                        new 
s_name[64], w_name[64]
                        for(new 
jrandomj++)
                        {
                            new 
skin_id = -1;
                            if(
presentItems[item][i] == -2skin_id cs_pick_random_skin(idcs_pick_random_chest(id));
                            else 
skin_id presentItems[item][i];
                            if(
skin_id != -&& skin_id <= cs_get_skins_count())
                            {
                                
cs_get_skin_name(skin_ids_name);
                                
cs_get_weapon_name(cs_get_skin_weapon_id(skin_id), w_name);
                                
                                
client_printcolor(id"/y[/ctrCSGO/y] You got /g%s /y(/g%s/y) skin from a present!"s_namew_name);
                                
cs_give_skin(idskin_id0);
                                
client_printcolor(0"/y[/ctrCSGO/y] Player /g%s /ygot /g%s /y(/g%s/y) skin from a present!"names_namew_name);
                            }
                        }
                    }
                    case 
ITEM_TYPE_SKIN_PART:
                    {
                        if(
presentAmountsMinimum[item][i] == presentAmountsMaximum[item][i]) random presentAmountsMinimum[item][i]
                        else 
random random_num(presentAmountsMinimum[item][i], presentAmountsMaximum[item][i]);
                        new 
s_name[64], w_name[64]
                        for(new 
jrandomj++)
                        {
                            new 
skin_id = -1;
                            if(
presentItems[item][i] == -2skin_id cs_pick_random_skin(idcs_pick_random_chest(id));
                            else 
skin_id presentItems[item][i];
                            if(
skin_id != -&& skin_id <= cs_get_skins_count())
                            {
                                
cs_get_skin_name(skin_ids_name);
                                
cs_get_weapon_name(cs_get_skin_weapon_id(skin_id), w_name);
                                
                                
client_printcolor(id"/y[/ctrCSGO/y] You got /g%s /y(/g%s/y) skin part from a present!"s_namew_name);
                                
cs_set_skin_parts(idskin_idcs_get_skin_parts(idskin_id)+1);
                                
client_printcolor(0"/y[/ctrCSGO/y] Player /g%s /ygot /g%s /y(/g%s/y) skin part from a present!"names_namew_name);
                            }
                        }
                    }
                    case 
ITEM_TYPE_CHEST:
                    {
                        if(
presentAmountsMinimum[item][i] == presentAmountsMaximum[item][i]) random presentAmountsMinimum[item][i]
                        else 
random random_num(presentAmountsMinimum[item][i], presentAmountsMaximum[item][i]);
                        new 
c_name[64];
                        for(new 
jrandomj++)
                        {
                            new 
chest_id = -1;
                            if(
presentItems[item][i] == -2chest_id cs_pick_random_chest(id);
                            else 
chest_id presentItems[item][i];
                            if(
chest_id != -&& chest_id <= cs_get_chests_count())
                            {
                                
cs_get_chest_name(chest_idc_name);
                                
                                
client_printcolor(id"/y[/ctrCSGO/y] You got /g%s /ychest from a present!"c_name);
                                
cs_set_chest_count(idchest_idcs_get_chest_count(idchest_id)+1);
                                
client_printcolor(0"/y[/ctrCSGO/y] Player /g%s /ygot /g%s /ychest from a present!"namec_name);
                            }
                        }
                    }
                    case 
ITEM_TYPE_KEY:
                    {
                        if(
presentAmountsMinimum[item][i] == presentAmountsMaximum[item][i]) random presentAmountsMinimum[item][i]
                        else 
random random_num(presentAmountsMinimum[item][i], presentAmountsMaximum[item][i]);
                        
                        
cs_set_keys_count(idcs_get_keys_count(id)+random);
                        
client_printcolor(id"/y[/ctrCSGO/y] You got /g%d /ykey(s) from a present!"random);
                        
client_printcolor(0"/y[/ctrCSGO/y] Player /g%s /ygot /g%d /ykey(s) from a present!"namerandom);
                    }
                    case 
ITEM_TYPE_MATERIAL:
                    {
                        if(
presentAmountsMinimum[item][i] == presentAmountsMaximum[item][i]) random presentAmountsMinimum[item][i]
                        else 
random random_num(presentAmountsMinimum[item][i], presentAmountsMaximum[item][i]);
                        new 
m_name[64];
                        for(new 
jrandomj++)
                        {
                            new 
material = -1;
                            if(
presentItems[item][i] == -2material cs_pick_random_material(id);
                            else 
material presentItems[item][i];
                            if(
material != -&& material MAX_MATERIALS)
                            {
                                
cs_get_material_name(materialm_name);
                                
                                
client_printcolor(id"/y[/ctrCSGO/y] You got /g%s /ymaterial part from a present!"m_name);
                                
cs_set_materials(idmaterialcs_get_materials(idmaterial)+1);
                                
client_printcolor(0"/y[/ctrCSGO/y] Player /g%s /ygot /g%s /ymaterial part from a present!"namem_name);
                            }
                        }
                    }
                    case 
ITEM_TYPE_POINTS:
                    {
                        if(
presentAmountsMinimum[item][i] == presentAmountsMaximum[item][i]) random presentAmountsMinimum[item][i]
                        else 
random random_num(presentAmountsMinimum[item][i], presentAmountsMaximum[item][i]);
                        
                        
cs_set_points(idcs_get_points(id)+random);
                        
client_printcolor(id"/y[/ctrCSGO/y] You got /g%d /ypoint(s) from a present!"random);
                    }
                    case 
ITEM_TYPE_MONEY:
                    {
                        if(
presentAmountsMinimum[item][i] == presentAmountsMaximum[item][i]) random presentAmountsMinimum[item][i]
                        else 
random random_num(presentAmountsMinimum[item][i], presentAmountsMaximum[item][i]);
                        
                        
cs_set_money(idcs_get_money(id)+random);
                        
client_printcolor(id"/y[/ctrCSGO/y] You got /g$%d /yfrom a present!"random);
                    }
                }
            }
        }
    }
}
public 
plugin_precache() 
{
    
loadModels();

public 
loadModels()
{
    new 
configs_dir[128], configuration_file[128];
    
get_configsdir(configs_dircharsmax(configs_dir));
    
    
format(configuration_filecharsmax(configuration_file), "%s/csgo"configs_dir);
    if(!
dir_exists(configuration_file)) mkdir(configuration_file);
    
    
format(configuration_filecharsmax(configuration_file), "%s/csgo/presents"configs_dir);
    if(!
dir_exists(configuration_file)) mkdir(configuration_file);
    
    
format(configuration_filecharsmax(configuration_file), "%s/csgo/presents/models.ini"configs_dir);
    if(
file_exists(configuration_file))
    {
        new 
szData[256], iTextLengthiLinemodel[128];
        while (
read_file(configuration_fileiLineszDatacharsmax(szData), iTextLength) != 0)
        {
            if(
models_count >= MAX_MODELS) break;
            if (
szData[0] == ';' || !szData[0] || strlen(szData) < || szData[0] == '/')
            {
                
iLine++;
                continue;
            }
            
parse(szDatamodelcharsmax(model));
            
formatex(model_present[models_count], charsmax(model_present[]), model);
            
engfunc(EngFunc_PrecacheModel,model_present[models_count])
            
            
models_count++;
            
iLine++;
        }
    }
    else
    {
        
write_file(configuration_file";Presents model files (You can multiple models)");
        
write_file(configuration_file";Example: ^"models/csgo/presents/example.mdl^"");
        
        
//formatex(model_present[0], charsmax(model_present[]), "models/csgo/presents/example.mdl");
        //engfunc(EngFunc_PrecacheModel,model_present[0]) 
        //models_count = 1;
    
}
}
public 
loadPresents()
{
    new 
configs_dir[128], configuration_file[128];
    
get_configsdir(configs_dircharsmax(configs_dir));
    
    
format(configuration_filecharsmax(configuration_file), "%s/csgo"configs_dir);
    if(!
dir_exists(configuration_file)) mkdir(configuration_file);
    
    
format(configuration_filecharsmax(configuration_file), "%s/csgo/presents"configs_dir);
    if(!
dir_exists(configuration_file)) mkdir(configuration_file);
    
    
format(configuration_filecharsmax(configuration_file), "%s/csgo/presents/items.ini"configs_dir);
    if(
file_exists(configuration_file))
    {
        new 
szData[256], iTextLengthiLinetypes[256], item_id[256], item_amount[256], chance[64], szLeft[64], szRight[64], item[7];
        new 
results[7][256], totalContents 0i;
        while (
read_file(configuration_fileiLineszDatacharsmax(szData), iTextLength) != 0)
        {
            if(
models_count >= MAX_MODELS) break;
            if (
szData[0] == ';' || !szData[0] || strlen(szData) < || szData[0] == '/')
            {
                
iLine++;
                continue;
            }
            
totalContents 0
            parse
(szDatatypescharsmax(types), item_idcharsmax(item_id), item_amountcharsmax(item_amount), chancecharsmax(chance));
            
            
ExplodeString(results7charsmax(results[]), types' ');
            for(
07i++)
            {
                if(
equal(results[i], "CHEST")) 
                {
                    
item[totalContents] = ITEM_TYPE_CHEST
                    hasItem
[contentsCount][item[totalContents]] = 1;
                    
totalContents++
                }
                else if(
equal(results[i], "SKIN")) 
                {
                    
item[totalContents] = ITEM_TYPE_SKIN
                    hasItem
[contentsCount][item[totalContents]] = 1;
                    
totalContents++
                }
                else if(
equal(results[i], "SKIN_PART")) 
                {
                    
item[totalContents] = ITEM_TYPE_SKIN_PART
                    hasItem
[contentsCount][item[totalContents]] = 1;
                    
totalContents++
                }
                else if(
equal(results[i], "KEY")) 
                {
                    
item[totalContents] = ITEM_TYPE_KEY
                    hasItem
[contentsCount][item[totalContents]] = 1;
                    
totalContents++
                }
                else if(
equal(results[i], "MATERIAL")) 
                {
                    
item[totalContents] = ITEM_TYPE_MATERIAL
                    hasItem
[contentsCount][item[totalContents]] = 1;
                    
totalContents++
                }
                else if(
equal(results[i], "POINTS")) 
                {
                    
item[totalContents] = ITEM_TYPE_POINTS
                    hasItem
[contentsCount][item[totalContents]] = 1;
                    
totalContents++
                }
                else if(
equal(results[i], "MONEY")) 
                {
                    
item[totalContents] = ITEM_TYPE_MONEY
                    hasItem
[contentsCount][item[totalContents]] = 1;
                    
totalContents++
                }
            }
            
ExplodeString(results7charsmax(results[]), item_id' ');
            for(
0totalContentsi++) // Put item_id values
            
{
                if(
equal(results[i], "*")) presentItems[contentsCount][item[i]] = -2
                
else presentItems[contentsCount][item[i]] = str_to_num(results[i]);
            }
            
            
ExplodeString(results7charsmax(results[]), item_amount' ');
            for(
0totalContentsi++) // Put amount values
            
{
                if(
containi(results[i], "-") != -1)
                {
                    
split(results[i], szLeftcharsmax(szLeft), szRightcharsmax(szRight), "-");

                    
presentAmountsMinimum[contentsCount][item[i]] = str_to_num(szLeft);
                    
presentAmountsMaximum[contentsCount][item[i]] = str_to_num(szRight);
                }
                else
                {
                    
presentAmountsMinimum[contentsCount][item[i]] = str_to_num(results[i]);
                    
presentAmountsMaximum[contentsCount][item[i]] = str_to_num(results[i]);
                }
            }
            
            
presentChances[contentsCount] = str_to_float(chance);
            
contentsCount++;
            
iLine++;
        }
    }
    else
    {
        
write_file(configuration_file";Configuration of present contents");
        
write_file(configuration_file";ITEM_TYPE {SKIN, SKIN_PART, CHEST, KEY, MATERIAL, MONEY, POINTS}");
        
write_file(configuration_file";if ITEM_ID is '*' server will pick random ITEM_ID");
        
write_file(configuration_file";ITEM_TYPE ITEM_ID AMOUNT CHANCE%");
        
write_file(configuration_file";This example shows, that player has 0.5% chance to get 1 RANDOM SKIN, 1 RANDOM CHEST and from 1 to 2 KEYS from a present at the same time");
        
write_file(configuration_file";Multiple contents example: ^"SKIN CHEST KEY^" ^"* * -1^" ^"1 1 1-2^" 0.5");
        
write_file(configuration_file"^"MONEY^" ^"-1^" ^"300-500^" ^"0.5^"");
        
        
presentChances[contentsCount] = 0.5;
        
presentAmountsMinimum[contentsCount][ITEM_TYPE_MONEY] = 300;
        
presentAmountsMaximum[contentsCount][ITEM_TYPE_MONEY] = 500;
        
contentsCount 1;
    }
}
public 
spawn_gifts() 
{
    
remove_task(111);
    new 
ent = -1
    
while ((ent engfunc(EngFunc_FindEntityByStringent"classname""present_box")))
        
engfunc(EngFunc_RemoveEntityent)
        
    if(
get_playersnum() >= get_pcvar_num(cvar_min_players)) {
        
set_task(random_float(get_pcvar_float(cvar_spawn_after_time_min), get_pcvar_float(cvar_spawn_after_time_max)), "func_spawn"111);
    }


public 
func_spawn() 
{
    if(
models_count 0)
    {
        new 
Float:origin[3
        new 

        
        
for(i=0iget_pcvar_num(pcvar_presents_on_map); i++) 
        { 
            if(
SsGetOrigin(origin)) 
            { 
                new 
ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target")) 
                if(
pev_valid(ent)) 
                { 
                    
engfunc(EngFunc_SetModel,ent,model_present[random_num(0models_count-1)]) 
                    
engfunc(EngFunc_SetOriginentorigin
                    static 
Float:fMaxs[3] = { 2.02.04.0 
                    static 
Float:fMins[3] = { -2.0, -2.0, -4.0 
                    
                    
set_pev(ent,pev_movetype,MOVETYPE_NOCLIP)
    
                    
set_pev(ent,pev_solid,SOLID_TRIGGER)
                    
                    
//set_pev(ent,pev_solid,SOLID_BBOX) 
                    
engfunc(EngFunc_SetSize,ent,fMins,fMaxs
                    
engfunc(EngFunc_DropToFloorent
                
                    
set_pev(ent,pev_classname,"present_box")
                    
                    if(
get_pcvar_num(cvar_glow_enabled))
                    {
                        new 
Float:fGlowColors[3];
                        new 
gColors[3][64];
                        new 
cvar[64];
                        
get_pcvar_string(cvar_glowcvarcharsmax(cvar))
                        
                        
parse(cvargColors[0], charsmax(gColors[]), gColors[1], charsmax(gColors[]), gColors[2], charsmax(gColors[]));
                        
fGlowColors[0] = str_to_float(gColors[0]);
                        
fGlowColors[1] = str_to_float(gColors[1]);
                        
fGlowColors[2] = str_to_float(gColors[2]);
                        
entity_set_int(entEV_INT_renderfxkRenderFxGlowShell
                        
entity_set_vector(entEV_VEC_rendercolorfGlowColors)
                    }
                    if(
get_pcvar_num(cvar_spin)) set_task(0.1,"spin_present",ent)
                } 
            } 
        }
        if(
get_pcvar_num(cvar_announce) > 0client_printcolor(0"/y[/ctrCSGO/y] Presents appreared somewhere! Go pick it up!");
    }
}
public 
spin_present(ent)
{
    if(
pev_valid(ent))
    {
        static 
Float:floatvector[3]
    
        
floatvector[0] = 0.0
        floatvector
[1] = 25.0
        floatvector
[2] = 0.0
    
        set_pev
(ent,pev_avelocity,floatvector)
    }
}
public 
forward_touch(ent,id

    if(!
pev_valid(ent)) 
        return 
FMRES_IGNORED 
    
    
static class[20
    
    
pev(ent,pev_classname,class,sizeof class - 1
    
    if(!
equali(class,"present_box")) 
        return 
FMRES_IGNORED
    
    
if(!is_user_alive(id)) 
        return 
FMRES_IGNORED 
    
    set_pev
(ent,pev_solid,SOLID_NOT
    
set_pev(ent,pev_effects,EF_NODRAW
    
    
giveItems(id);
    
    
remove_entity(ent)
    return 
FMRES_IGNORED 
}
public 
pickRandomItem()
{
    new 
Float:number random_float(0.000000001100.0);
    new 
contents[MAX_CONTENTS], cont;
    for(new 
icontentsCounti++)
    {
        if(
presentChances[i] >= number)
        {
            
contents[cont] = i;
            
cont++;
        }
    }

    if(
cont <= 0) return -1;
    else if(
cont == 1) return contents[0];
    return 
contents[random_num(0cont-1)];
}
stock ExplodeStringp_szOutput[][], p_nMaxp_nSizep_szInput[], p_szDelimiter )
{
    new 
nIdx 0strlen(p_szInput)
    new 
nLen = (copycp_szOutput[nIdx], p_nSizep_szInputp_szDelimiter ))
    while( (
nLen l) && (++nIdx p_nMax) )
        
nLen += (copycp_szOutput[nIdx], p_nSizep_szInput[nLen], p_szDelimiter ))
    return

Attached Thumbnails
Click image for larger version

Name:	err.png
Views:	42
Size:	25.6 KB
ID:	186744  
Attached Files
File Type: sma Get Plugin or Get Source (csgo-presents.sma - 100 views - 16.0 KB)
LithuanianJack is offline