Raised This Month: $ Target: $400
 0% 

fakemeta - create breakable entity ( light creature )


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-19-2010 , 18:34   fakemeta - create breakable entity ( light creature )
Reply With Quote #1

Hi guys( and gels )!

I've searched the site around here for answer without luck, so I am posting this here question to you all:

How can I create a breakable entity? Or create an entity and add properties like being breakable, adding gib model and most important: setting material type.

I am experimenting with creating simple creatures, which cannot be even called bots or ai-s. I would like to create a "light" creature, or a "tree" from the Half Life's Xen world. They would be breakable( material would be flesh ), and would break apart to alien gibs( agibs.mdl ). The code so far is this:
PHP Code:
//some consts
#define light_hiding_time 5.0
new const Float:light_collision_radius 15.0;

#define TASK_LIGHT 750

//models of the light
new const light_models[][] = { "models/light.mdl","models/lightt.mdl" }
new const 
alien_gibs[] = "models/agibs.mdl"

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

public plugin_init(){
    
register_plugin("Creatures","1.0","Lulu the hero");
    
    
register_clcmd("say light","test");
    
    
//precache the...
    
new modelnum;
    
    
//light models
    
for(modelnum=0;modelnum<sizeof light_models;modelnum++)
        
engfunc(EngFunc_PrecacheModel,light_models[modelnum]);
        
    
engfunc(EngFunc_PrecacheModel,alien_gibs);

    
RegisterHam(Ham_Touch,"info_target","touched_light");
}

public 
test(id){
    new 
team get_user_team(id);
    
    if(
is_user_alive(id)&&is_user_connected(id)&&((team==1)||(team==2))){
    
        new 
origin[3],Float:f_origin[3];
        new 
tempid,Float:size1[3],Float:size2[3];
        
        
get_user_origin(id,origin,3);
        
f_origin[0] = float(origin[0]);
        
f_origin[1] = float(origin[1]);
        
f_origin[2] = float(origin[2]);
        
        
tempid engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"));
        
        if(
pev_valid(tempid)){
            
set_pev(tempid,pev_classname,"creature_light");
            
engfunc(EngFunc_SetModel,tempid,light_models[0]);
            
            
size1[0] = 0.0-light_collision_radius;
            
size1[1] = 0.0-light_collision_radius;
            
size1[2] = 0.0;
            
            
size2[0] = light_collision_radius;
            
size2[1] = light_collision_radius;
            
size2[2] = light_collision_radius;
            
            
set_pev(tempid,pev_solid,SOLID_BBOX);
            
            
engfunc(EngFunc_SetSize,tempid,size1,size2);
            
            
set_pev(tempid,pev_movetype,MOVETYPE_NONE);
            
            
set_pev(tempid,pev_sequence,0);
            
set_pev(tempid,pev_gaitsequence,0);
            
set_pev(tempid,pev_frame,0);
            
set_pev(tempid,pev_framerate,1.0);
            
            
set_pev(tempid,pev_euser1,3);
            
            
//lighting(f_origin,200,200,100,1);
            
            
engfunc(EngFunc_SetOrigin,tempid,f_origin);
        }
    }
    return 
PLUGIN_HANDLED;
}

public 
touched_light(ent,other){
    new 
classname[32];
    
pev(ent,pev_classname,classname,31);
    if(!
equal(classname,"creature_light")) return HAM_IGNORED;

    new 
team get_user_team(other);
    if(
is_user_alive(other)&&is_user_connected(other)&&((team==1)||(team==2))){
        new 
st pev(ent,pev_euser1);
        new 
params[1];
        
params[0] = ent;
        if(
st>=2){
            
withdraw_light(params);
        }else if(
st==0){
            
remove_task(TASK_LIGHT+ent);
            
set_task(light_hiding_time,"deploy_light",TASK_LIGHT+ent,params,1);
        }
    }
    return 
HAM_HANDLED;
}

public 
withdraw_light(params[]){
    new 
ent params[0];
    
set_pev(ent,pev_euser1,1);
    
    
set_pev(ent,pev_sequence,1);
    
set_pev(ent,pev_frame,0);
    
set_pev(ent,pev_framerate,1.0);
    
    
set_pev(ent,pev_gaitsequence,1);
    
set_pev(ent,pev_animtime,0.3);
    
    
remove_task(TASK_LIGHT+ent);
    
set_task(0.3,"hidden_light",TASK_LIGHT+ent,params,1);
}

public 
deploy_light(params[]){
    new 
ent params[0];
    
set_pev(ent,pev_euser1,2);
    
    
set_pev(ent,pev_sequence,2);
    
set_pev(ent,pev_frame,0);
    
set_pev(ent,pev_framerate,1.0);
    
    
set_pev(ent,pev_gaitsequence,2);
    
set_pev(ent,pev_animtime,1.3);
    
    
remove_task(TASK_LIGHT+ent);
    
set_task(1.3,"normal_light",TASK_LIGHT+ent,params,1);
}

public 
normal_light(params[]){
    new 
ent params[0];
    
set_pev(ent,pev_euser1,3);
    
    
set_pev(ent,pev_sequence,0);
    
set_pev(ent,pev_frame,0);
    
set_pev(ent,pev_framerate,1.0);
    
    
set_pev(ent,pev_gaitsequence,0);
}

public 
hidden_light(params[]){
    new 
ent params[0];
    
set_pev(ent,pev_euser1,0);
    
    
set_pev(ent,pev_sequence,3);
    
set_pev(ent,pev_frame,0);
    
set_pev(ent,pev_framerate,1.0);
    
    
set_pev(ent,pev_gaitsequence,3);
    
    
remove_task(TASK_LIGHT+ent);
    
set_task(light_hiding_time,"deploy_light",TASK_LIGHT+ent,params,1);

The code above does this:
If you say "light", then it puts a light creature at aim. If you touch the creature, it hides back( ANIMATION PROBLEM AT WITHDRAW AND DEPLOY! HOW CAN I CORRECT THAT??? ). After a few seconds if left alone, the creature comes back.

So how could I set the entity to breakable, set material type to flesh, and add a gib model?

My researches so far led me to these answers( according to the Valve Hammer Editor's datas ):
- I need to add keyvalues, such as material=3( for flesh, I think )
- To add a keyvalue, I should use something like the engfunc_setkeyvalue.
- I could create a temporary entity for the gibs, like:
PHP Code:
//create an explosion of tech gibs
stock create_infoboom(Float:origin[3],Float:life=2.5,count=10){
    static 
_life;
    
_life=floatround(life*10,floatround_floor);
    
engfunc(EngFunc_MessageBegin,MSG_PVS,SVC_TEMPENTITY,origin,0);
    
write_byte(TE_BREAKMODEL);
    
engfunc(EngFunc_WriteCoordorigin[0]);
    
engfunc(EngFunc_WriteCoordorigin[1]);
    
engfunc(EngFunc_WriteCoordorigin[2]);
    
write_coord(16);
    
write_coord(16);
    
write_coord(16);
    
write_coord(random_num(-50,50));
    
write_coord(random_num(-50,50));
    
write_coord(25);
    
write_byte(10);
    
write_short(infogibs);
    
write_byte(count);
    
write_byte(_life);
    
write_byte(7);
    
message_end();

And one more question, how can I make my creature glow/ emit light( my light creature would be rather useless without light, don't you think? )?
I've tried adding the code below, but it is rather useless, cause I do not know when will a collition happen, thus how long does the light need to be there...
PHP Code:
//Got to mention, I've extracted this code from the zombi plague's flare grenade
public lighting(Float:originF[3],r,g,b,duration){
    
engfunc(EngFunc_MessageBeginMSG_PASSVC_TEMPENTITYoriginF0)
    
write_byte(TE_DLIGHT// TE id
    
engfunc(EngFunc_WriteCoordoriginF[0]) // x
    
engfunc(EngFunc_WriteCoordoriginF[1]) // y
    
engfunc(EngFunc_WriteCoordoriginF[2]) // z
    
write_byte(floatround(light_collision_radius,floatround_floor)) // radius
    
    
write_byte(r// r
    
write_byte(g// g
    
write_byte(b// b
    
write_byte(51//life
    
write_byte((duration 2) ? 0//decay rate
    
message_end()

Thank you, everyone, for your answers in advance.:bow:<-bowing smily missing
Lulu the hero is offline
 



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 07:16.


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