Raised This Month: $ Target: $400
 0% 

fakemeta - create breakable entity ( light creature )


Post New Thread Reply   
 
Thread Tools Display Modes
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
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-19-2010 , 18:46   Re: fakemeta - create breakable entity ( light creature )
Reply With Quote #2

use func_breakable entity.
__________________
Arkshine is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-19-2010 , 19:25   Re: fakemeta - create breakable entity ( light creature )
Reply With Quote #3

Nice, but how do you set parameters, like material?
Lulu the hero is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-20-2010 , 09:26   Re: fakemeta - create breakable entity ( light creature )
Reply With Quote #4

Use DispatchKeyvalue.
__________________
Arkshine is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-20-2010 , 13:06   Re: fakemeta - create breakable entity ( light creature )
Reply With Quote #5

That's in the engine module. By the way, I've already tried that with a line similar to this:

DispatchKeyValue(tempid,"material","3"); //tempid is the entity id, 3 means flesh( I think )

I've also set the entity type to func_breakable,but it is simply not working. Can you show me a small, working code, which creates a breakable something?
Lulu the hero is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-20-2010 , 13:09   Re: fakemeta - create breakable entity ( light creature )
Reply With Quote #6

Set the health and health and explodemagnitude I guess. Don't forget to spawn the entity.

Don't forget to precache resources :


precache_model( "models/fleshgibs.mdl" );

precache_sound( "debris/bustflesh1.wav" );
precache_sound( "debris/bustflesh2.wav" );

precache_sound( "debris/flesh1.wav" );
precache_sound( "debris/flesh2.wav" );
precache_sound( "debris/flesh3.wav" );
precache_sound( "debris/flesh5.wav" );
precache_sound( "debris/flesh6.wav" );
precache_sound( "debris/flesh7.wav" );
__________________
Arkshine is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-20-2010 , 13:47   Re: fakemeta - create breakable entity ( light creature )
Reply With Quote #7

precached the above mentioned, edited the test function:

PHP Code:
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,"func_breakable"));
        
        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);
            
DispatchKeyValue(tempid,"material","3");
            
            
set_pev(tempid,pev_health,100.0);
            
            
engfunc(EngFunc_SetOrigin,tempid,f_origin);
            
DispatchSpawn(tempid);
        }
    }
    return 
PLUGIN_HANDLED;

but as I expected, nothing changed. Oh, one thing changed! After adding the pev_health line, now I can walk through the object...

So what is basicly needed for an entity? All entities need spawning?( dispatch spawn )
Lulu the hero is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-20-2010 , 13:52   Re: fakemeta - create breakable entity ( light creature )
Reply With Quote #8

Nothing changed ? You mean when you fire you seen nothing ? and what about "explodemagnitude", set a value too.
__________________
Arkshine is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-20-2010 , 15:03   Re: fakemeta - create breakable entity ( light creature )
Reply With Quote #9

I see the entity, I can walk through it... Nothings working, gonna expreriment with this. Do I really need to spawn it?
Lulu the hero is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-20-2010 , 16:16   Re: fakemeta - create breakable entity ( light creature )
Reply With Quote #10

Fastly redone an old code, it should work when you shoot.
Use /test in game.

PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <xs>

public plugin_precache()
{
    
precache_model"models/fleshgibs.mdl" );

    
precache_sound"debris/bustflesh1.wav" );
    
precache_sound"debris/bustflesh2.wav" );

    
precache_sound"debris/flesh1.wav" );
    
precache_sound"debris/flesh2.wav" );
    
precache_sound"debris/flesh3.wav" );
    
precache_sound"debris/flesh5.wav" );
    
precache_sound"debris/flesh6.wav" );
    
precache_sound"debris/flesh7.wav" );
}   

public 
plugin_init ()
{
    
register_plugin"func_breakable test""1.0.0""Arkshine" );
    
register_clcmd"say /test""ClientCommand_Test" );
}

public 
ClientCommand_Test ( const client )
{
    new 
Float:origin];
    new 
breakable;
    
    
GetAimOriginclientorigin, .distance 150.0 );

    
FX_Breakable
    
(
        .
entity    breakable,
        .
classname "test-breakable",
        .
model     "models/player.mdl",
        .
source    origin,
        .
mins      Float:{ -16.0, -16.0, -36.0 },
        .
maxs      Float:{  16.0,  16.0,  36.0 },
        .
material  "3",
        .
health    "50"
    
);
    
    return 
PLUGIN_HANDLED;
}

FX_Breakable ( &entity, const classname[], const model[], const Float:source], const Float:mins], const Float:maxs], const material[], const health[] )
{
    
entity create_entity"func_breakable" );

    
set_peventitypev_classnameclassname );
    
set_peventitypev_modelmodel );
    
set_peventitypev_healthhealth );
    
    
DispatchKeyValueentity"material"material );
    
DispatchKeyValueentity"health"health );
    
    
DispatchSpawnentity );
    
    
engfuncEngFunc_SetSizeentityminsmaxs );
    
engfuncEngFunc_SetOriginentitysource );
}
            
stock GetAimOriginindexFloat:origin[3], Float:distance 50.0 
{  
    new 
Float:start];
    new 
Float:view_ofs];
    
    
pevindexpev_originstart );
    
pevindexpev_view_ofsview_ofs );
    
    
xs_vec_addstartview_ofsstart );

    new 
Float:dest];
    
pevindexpev_v_angledest );
    
    
engfuncEngFunc_MakeVectorsdest );
    
global_getglb_v_forwarddest );
    
    
xs_vec_mul_scalardestdistancedest );
    
xs_vec_addstartdestorigin );

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


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