Raised This Month: $51 Target: $400
 12% 

[REQ] Plugin to Spawn Models on Map


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 07-26-2015 , 16:15   [REQ] Plugin to Spawn Models on Map
Reply With Quote #1

Is there any plugin which allows you to spawn a certain model on a map?
Also the model to be auto spawned every time ?

I tried this but i have a problem... it is always telling me "more than 2 models/sprites containing that name were found" even that i put it just once...

PHP Code:
/*
*   _______     _      _  __          __
*  | _____/    | |    | | \ \   __   / /
*  | |         | |    | |  | | /  \ | |
*  | |         | |____| |  | |/ __ \| |
*  | |   ___   | ______ |  |   /  \   |
*  | |  |_  |  | |    | |  |  /    \  |
*  | |    | |  | |    | |  | |      | |
*  | |____| |  | |    | |  | |      | |
*  |_______/   |_|    |_|  \_/      \_/
*
*
*
*  Last Edited: 12-31-07
*
*  ============
*   Changelog:
*  ============
*
*  v3.0
*    -Added ML
*
*  v2.0
*    -Optimized Code
*
*  v1.0
*    -Initial Release
*
*/

#define VERSION    "3.0"

#include <amxmodx>
#include <amxmisc>
#include <engine>

#define MAX_PRECACHES    200

new num
new precached[MAX_PRECACHES][32]
new 
precached_name[MAX_PRECACHES][32]
new 
precached_sequence[MAX_PRECACHES]
new 
configsdir[200]
new 
refferencefile[200]

public 
plugin_init()
{
    
register_plugin("Model / Sprite Spawner",VERSION,"GHW_Chronic")
    
register_concmd("amx_spawn","spawnent",ADMIN_LEVEL_G," Spawns a Model / Sprite <part of ent name> [Non-Default Sequence #]")
    
register_concmd("amx_spawn_remove","removeent",ADMIN_LEVEL_G," Removes Model / Sprite you are standing next to. ")
    
register_concmd("amx_spawn_list","listents",ADMIN_LEVEL_G," Lists Models / Sprites precached for this map. ")
    
set_task(1.0,"map_load")
}

public 
plugin_precache()
{
    
register_dictionary("GHW_Entspawner.txt")

    
get_configsdir(configsdir,199)
    new 
precachefile[200]
    
format(precachefile,199,"%s/GHW_entspawner.ini",configsdir)
    
format(refferencefile,199,"%s/GHW_entspawner_refferences.ini",configsdir)
    if(
file_exists(precachefile))
    {
        new 
mapname[32]
        
get_mapname(mapname,31)
        new 
read[96], trash
        
new string[96]
        new 
modelname[32]
        new 
modelname2[32]
        new 
map[32]
        new 
sequence
        
for(new i=0;i<file_size(precachefile,1);i++)
        {
            
read_file(precachefile,i,read,95,trash)
            
strbreak(read,modelname,31,string,95)
            
strbreak(string,modelname2,31,string,95)
            
strbreak(string,map,31,string,95)
            
sequence str_to_num(string)
            if(
strlen(modelname) && strlen(map) && containi(modelname,";")!=0)
            {
                if(
equali(map,mapname) || equali(map,"all"))
                {
                    if(
containi(modelname,".spr")!=strlen(modelname)-&& containi(modelname,".mdl")!=strlen(modelname)-4)
                    {
                        
log_amx("[Ent-Spawner] %L",0,"MSG_INVALIDLOAD",i+1)
                    }
                    else
                    {
                        
precache_model(modelname)
                        
format(precached[num],31,"%s",modelname)
                        
format(precached_name[num],31,"%s",modelname2)
                        
precached_sequence[num] = sequence
                        num
++
                    }
                }
            }
        }
    }
}

public 
map_load()
{
    if(
file_exists(refferencefile))
    {
        new 
mapname[32]
        
get_mapname(mapname,31)
        
format(mapname,31,"[%s]",mapname)
        new 
read[32], trash
        
new modelname[32], sequenceFloat:origin[3], Float:angles[3], Float:v_angle[3]
        for(new 
i=0;i<file_size(refferencefile,1);i++)
        {
            
read_file(refferencefile,i,read,31,trash)
            if(
equali(read,mapname))
            {
                
i++
                
read_file(refferencefile,i,read,31,trash)
                for(new 
i2=0;i2<num;i2++)
                {
                    if(
equali(precached[i2],read))
                    {
                        
format(modelname,31,"%s",read)
                        
i++
                        
read_file(refferencefile,i,read,31,trash)
                        
sequence str_to_num(read)
                        
i++
                        
read_file(refferencefile,i,read,31,trash)
                        
origin[0] = str_to_float(read)
                        
i++
                        
read_file(refferencefile,i,read,31,trash)
                        
origin[1] = str_to_float(read)
                        
i++
                        
read_file(refferencefile,i,read,31,trash)
                        
origin[2] = str_to_float(read)
                        
i++
                        
read_file(refferencefile,i,read,31,trash)
                        
angles[0] = str_to_float(read)
                        
i++
                        
read_file(refferencefile,i,read,31,trash)
                        
angles[1] = str_to_float(read)
                        
i++
                        
read_file(refferencefile,i,read,31,trash)
                        
angles[2] = str_to_float(read)
                        
i++
                        
read_file(refferencefile,i,read,31,trash)
                        
v_angle[0] = str_to_float(read)
                        
i++
                        
read_file(refferencefile,i,read,31,trash)
                        
v_angle[1] = str_to_float(read)
                        
i++
                        
read_file(refferencefile,i,read,31,trash)
                        
v_angle[2] = str_to_float(read)

                        new 
ent create_entity("info_target")

                        
entity_set_string(ent,EV_SZ_classname,"ghw_spawned_ent")

                        
entity_set_model(ent,modelname)

                        
entity_set_origin(ent,origin)
                        
entity_set_vector(ent,EV_VEC_v_angle,v_angle)
                        
entity_set_vector(ent,EV_VEC_angles,angles)

                        
entity_set_int(entEV_INT_solid,SOLID_NOT)
                        
entity_set_int(ent,EV_INT_movetype,MOVETYPE_FLY)
                        
entity_set_edict(ent,EV_ENT_owner,33)

                        
entity_set_float(ent,EV_FL_framerate,1.0)
                        
entity_set_int(ent,EV_INT_sequence,sequence)

                        
entity_set_size(ent,Float:{-0.1, -0.1, -0.1},Float:{0.10.10.1})

                        break;
                    }
                    if(
i2==num-1)
                    {
                        
log_amx("[Ent-Spawner] %L",0,"MSG_INVALIDSPAWN",read)
                    }
                }
            }
        }
    }
    return 
PLUGIN_CONTINUE
}


/***************
 amx_spawn_list
***************/

public listents(id,level,cid)
{
    if(!
cmd_access(id,level,cid,1))
    {
        return 
PLUGIN_HANDLED
    
}
    
console_print(id,"")
    
console_print(id,"[AMXX] %L",id,"MSG_LIST_BEGINNING1",num)
    
console_print(id,"[AMXX] %L",id,"MSG_LIST_BEGINNING2")
    
console_print(id,"[AMXX] -------")
    for(new 
i=0;i<num;i++)
    {
        
console_print(id,"[AMXX] %L",id,"MSG_LIST_MIDDLE ",1,precached[i],precached_name[i],precached_sequence[i])
    }
    
console_print(id,"[AMXX] -------")
    
console_print(id,"")
    return 
PLUGIN_HANDLED
}


/*****************
 amx_spawn_remove
*****************/

public removeent(id,level,cid)
{
    if(!
cmd_access(id,level,cid,1))
    {
        return 
PLUGIN_HANDLED
    
}
    new 
Float:origin[3]
    
entity_get_vector(id,EV_VEC_origin,origin)
    new 
closest=0
    
new Float:closestdis=99999.0
    
new ent find_ent_in_sphere(get_maxplayers(),origin,100.0)
    new 
Float:origin2[3]
    new 
classname[32]
    while(
ent)
    {
        
entity_get_string(ent,EV_SZ_classname,classname,31)
        if(
equali(classname,"ghw_spawned_ent"))
        {
            
entity_get_vector(ent,EV_VEC_origin,origin2)
            if(
get_distance_f(origin,origin2)<closestdis)
            {
                
closestdis=get_distance_f(origin,origin2)
                
closest=ent
            
}
        }
        
ent find_ent_in_sphere(ent,origin,100.0)
    }
    if(
closest)
    {
        
entity_get_vector(closest,EV_VEC_origin,origin)
        new 
read[32], trash
        
new string[8]
        new 
mapname[32]
        
get_mapname(mapname,31)
        
format(mapname,31,"[%s]",mapname)
        for(new 
i=0;i<file_size(refferencefile,1);i++)
        {
            
read_file(refferencefile,i,read,31,trash)
            if(
equali(read,mapname))
            {
                
i+=3
                read_file
(refferencefile,i,read,31,trash)
                
format(string,7,"%f",origin[0])
                if(
str_to_float(read)==origin[0])
                {
                    
console_print(id,"2")
                    
i++
                    
read_file(refferencefile,i,read,31,trash)
                    
format(string,7,"%f",origin[1])
                    if(
str_to_float(read)==origin[1])
                    {
                        
i++
                        
read_file(refferencefile,i,read,31,trash)
                        
format(string,7,"%f",origin[2])
                        if(
str_to_float(read)==origin[2])
                        {
                            
remove_entity(closest)
                            
write_file(refferencefile,"",i-5)
                            
write_file(refferencefile,"",i-4)
                            
write_file(refferencefile,"",i-3)
                            
write_file(refferencefile,"",i-2)
                            
write_file(refferencefile,"",i-1)
                            
write_file(refferencefile,"",i)
                            
write_file(refferencefile,"",i+1)
                            
write_file(refferencefile,"",i+2)
                            
write_file(refferencefile,"",i+3)
                            
write_file(refferencefile,"",i+4)
                            
write_file(refferencefile,"",i+5)
                            
write_file(refferencefile,"",i+6)
                            
console_print(id,"[AMXX] %L",id,"MSG_REMOVED")
                            return 
PLUGIN_HANDLED
                        
}
                    }
                }
            }
        }
    }
    
console_print(id,"[AMXX] %L",id,"MSG_NOREMOVE")
    return 
PLUGIN_HANDLED
}


/**********
 amx_spawn
**********/

public spawnent(id,level,cid)
{
    if(!
cmd_access(id,level,cid,2))
    {
        return 
PLUGIN_HANDLED
    
}
    new 
arg1[32]
    
read_argv(1,arg1,31)
    new 
arg2[32]
    
read_argv(2,arg2,31)
    new 
num2=-1
    
for(new i=0;i<num;i++)
    {
        if(
containi(precached_name[i],arg1)!=-1)
        {
            if(
num2!=-1)
            {
                
console_print(id,"[AMXX] %L",id,"MSG_NOSPAWN_MORE",arg1)
                return 
PLUGIN_HANDLED
            
}
            
num2=i
        
}
    }
    if(
num2==-1)
    {
        
console_print(id,"[AMXX] %L",id,"MSG_NOSPAWN_NONE",arg1)
        return 
PLUGIN_HANDLED
    
}
    new 
sequence str_to_num(arg2)
    if(!
strlen(arg2))
    {
        
sequence precached_sequence[num2]
    }
    new 
Float:origin[3]
    new 
Float:angles[3]
    new 
Float:v_angle[3]
    
entity_get_vector(id,EV_VEC_origin,origin)
    
entity_get_vector(id,EV_VEC_v_angle,v_angle)
    
entity_get_vector(id,EV_VEC_angles,angles)

    new 
ent create_entity("info_target")

    
entity_set_string(ent,EV_SZ_classname,"ghw_spawned_ent")

    
entity_set_model(ent,precached[num2])

    
entity_set_origin(ent,origin)
    
entity_set_vector(ent,EV_VEC_v_angle,v_angle)
    
entity_set_vector(ent,EV_VEC_angles,angles)

    
entity_set_int(entEV_INT_solid,SOLID_NOT)
    
entity_set_int(ent,EV_INT_movetype,MOVETYPE_FLY)
    
entity_set_edict(ent,EV_ENT_owner,33)

    
entity_set_float(ent,EV_FL_framerate,1.0)
    
entity_set_int(ent,EV_INT_sequence,sequence)

    
entity_set_size(ent,Float:{-0.1, -0.1, -0.1},Float:{0.10.10.1})

    new 
mapname[32]
    new 
string[16]
    
get_mapname(mapname,31)
    
format(mapname,31,"[%s]",mapname)
    
write_file(refferencefile,mapname,-1)
    
write_file(refferencefile,precached[num2],-1)
    
format(string,15,"%d",sequence)
    
write_file(refferencefile,string,-1)
    
format(string,15,"%f",origin[0])
    
write_file(refferencefile,string,-1)
    
format(string,15,"%f",origin[1])
    
write_file(refferencefile,string,-1)
    
format(string,15,"%f",origin[2])
    
write_file(refferencefile,string,-1)
    
format(string,15,"%f",angles[0])
    
write_file(refferencefile,string,-1)
    
format(string,15,"%f",angles[1])
    
write_file(refferencefile,string,-1)
    
format(string,15,"%f",angles[2])
    
write_file(refferencefile,string,-1)
    
format(string,15,"%f",v_angle[0])
    
write_file(refferencefile,string,-1)
    
format(string,15,"%f",v_angle[1])
    
write_file(refferencefile,string,-1)
    
format(string,15,"%f",v_angle[2])
    
write_file(refferencefile,string,-1)

    
console_print(id,"[AMXX] %L",id,"MSG_SPAWN",precached_name[num2],sequence)
    return 
PLUGIN_HANDLED
}

/*

.INI File Syntax:

//GHW_entspawner.ini
location model_short_name map(or all) defaultsequence#
models/blah.mdl "Big Tree" de_dust2 0

//GHW_entspawner_refferences.ini
[mapname]
modelname
sequence
origin[0]
origin[1]
origin[2]
angle[0]
angle[1]
angle[2]
v_angle[0]
v_angle[1]
v_angle[2]
*/ 
Depresie is offline
Reply



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 15:34.


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