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

Saving and Loading objects/entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
iNvectus
Member
Join Date: Sep 2014
Location: Bulgaria
Old 01-02-2017 , 17:14   Saving and Loading objects/entities
Reply With Quote #1

Hello.I would like to ask if there is anybody who can explain me how I can save/load entities/objects in amxx? So far, I created one and I can delete one, but how can I save and load one?

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fakemeta>
#include <engine>

#include <coll_msg>
#define level ADMIN_RCON

enum {
    
ITEM_CREATE,
    
ITEM_DELETE,
    
ITEM_SAVE
}

new 
g_fileName[256]
new const 
Classname[] = "Block"
new const blockmodel[] = "models/RandomBlock.mdl"

public plugin_init()
{
    
register_concmd("amx_godi1234","showmenu",ADMIN_RCON,"<create to enity block's menu>")
    
register_touch(Classname,"player","EntityTouch")
    
    
get_configsdir(g_fileName,255);
    
format(g_fileName,255,"%s/mapOrigins.ini",g_fileName);    
}
public 
plugin_precache() {
    
precache_model(blockmodel)
}
public 
showmenu(id)
{
    new 
menu menu_create("\r[Objects] \ySettings\r:","showhandler",0)
    
menu_additem(menu"\wCreate","1",0)
    
menu_additem(menu"\wDelete All","2",0)
    
menu_display(id,menu,0)
    
    return 
PLUGIN_HANDLED_MAIN
}
public 
showhandler(id,menu,item)
{
    if(
item != MENU_EXIT)
    {
        switch(
item)
        {
            case 
ITEM_CREATE:
            {
                if(!
is_user_alive(id))
                {
                    
Chat(id,"^3[Objects]^4You must be alive^1!")
                    return
                }
                
                
Chat(id,"^3[Objects]^4The object was created successfully^1!")
                
client_cmd(id,"spk buttons/bell1")
                
CreateBlock(id)
            }
            case 
ITEM_DELETE:
            {
                
Chat(id,"^3[Objects] ^4All Objects are deleted^1!")
                
client_cmd(id,"spk buttons/blip1")
                
remove_entity_name(Classname)
            }
        }
        
showmenu(id)
    }
    
menu_destroy(menu)
}
public 
CreateBlock(id)
{
    new 
Origin[3]
    
get_user_origin(id,Origin,3)
    
    new 
Entity create_entity("info_target")
    
    if(!
pev_valid(Entity)) 
        return 
PLUGIN_HANDLED
        
    
new Float:fOrigin[3]
    
IVecFVec(Origin,fOrigin)
    
    
set_pev(Entity,pev_origin,fOrigin)
    
set_pev(Entity,pev_classname,Classname)
    
set_pev(Entity,pev_solid,SOLID_BBOX)
    
set_pev(Entity,pev_movetype,MOVETYPE_NONE)
    
set_pev(Entity,pev_nextthink,get_gametime() +1.0)
    
    
engfunc(EngFunc_SetModel,Entity,blockmodel)
    
set_rendering(Entity,kRenderFxNone,255,255,255,kRenderTransTexture,255)
    
engfunc(EngFunc_SetSize,Entity,Float:{-78.5,-78.5,-6.7},Float:{78.5,78.5,6.7})
    
// ?? doCoord( Entity )
    
return PLUGIN_HANDLED
}
public 
EntityTouch(Entity,id)
{
    if(!
pev_valid(Entity)) 
        return 
FMRES_IGNORED
    
    
if(get_user_flags(id)&level)
        return 
FMRES_IGNORED
        
    ExecuteHamB
(Ham_CS_RoundRespawn,id)  
    
Chat(id,"^3(Box) ^1You stepped on the ^4 Object ^1^3!")
    return 
FMRES_IGNORED
}
public 
doCoord(id)
{
    new 
args[64]
    
read_argv(1,args,63)
            
    new 
origin[3],mapName[64],data[512]
    
get_user_origin(id,origin)
    
get_mapname(mapName,63)
            
    new 
file fopeng_fileName"a+" );
    if ( 
file )
    {
        
formatex(data,511,"%s    -   X: %i Y: %i Z: %i     -    %s^n",mapName,origin[0],origin[1],origin[2],args);
        
fprintf(file,"%s",data);
        
        
fclosefile );
    }
    else
    {
        
console_print(id,"[AMXX] Unable to open file...^n");
    }
}        
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1026\\ f0\\ fs16 \n\\ par }
*/ 
Thanks in advance!
iNvectus is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-02-2017 , 17:25   Re: Saving and Loading objects/entities
Reply With Quote #2

nVault?
__________________
edon1337 is offline
iNvectus
Member
Join Date: Sep 2014
Location: Bulgaria
Old 01-02-2017 , 17:45   Re: Saving and Loading objects/entities
Reply With Quote #3

Quote:
Originally Posted by edon1337 View Post
nVault?
I cant seem to get the idea how to save the object.Can you give me example?
iNvectus is offline
pupdebox
Senior Member
Join Date: Feb 2016
Location: Wakanda
Old 01-02-2017 , 21:19   Re: Saving and Loading objects/entities
Reply With Quote #4

This is literally what you need:

https://forums.alliedmods.net/showthread.php?p=504633
__________________
Quote:
Originally Posted by wickedd View Post
Make me or STFU boy
pupdebox is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-02-2017 , 21:24   Re: Saving and Loading objects/entities
Reply With Quote #5

You can save some data associated with your custom entity then recreate it when you load that data. What you can't do is save the entity itself in a file then magically load it into the game world.
klippy 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 14:14.


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