View Single Post
Author Message
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 06-14-2010 , 14:25   [Tutorial] Creating brush entities
Reply With Quote #1

1st i'd like to thank foxmulder for reminding me about entity outputs otherwise i never would have bothered trying to get brushes to work.

i've only tested this in css but it should work for any game, most brush entities can be found here http://developer.valvesoftware.com/w...Brush_Entities. not all brush entities will work for different games.

please note any brush entities that are created will be invisible as only bsp brush models can be used with brush entities. only box shaped brushes work.

heres part of a snippet i used

PHP Code:
new Float:playerpos[3];
GetEntPropVector(clientProp_Send"m_vecOrigin"playerpos);

new 
entindex CreateEntityByName("trigger_push");
if (
entindex != -1)
{
    
DispatchKeyValue(entindex"pushdir""0 90 0");
    
DispatchKeyValue(entindex"speed""500");
    
DispatchKeyValue(entindex"spawnflags""64");
}

DispatchSpawn(entindex);
ActivateEntity(entindex);

TeleportEntity(entindexplayerposNULL_VECTORNULL_VECTOR);

SetEntityModel(entindex"models/props/cs_office/vending_machine.mdl");

new 
Float:minbounds[3] = {-100.0, -100.00.0};
new 
Float:maxbounds[3] = {100.0100.0200.0};
SetEntPropVector(entindexProp_Send"m_vecMins"minbounds);
SetEntPropVector(entindexProp_Send"m_vecMaxs"maxbounds);
    
SetEntProp(entindexProp_Send"m_nSolidType"2);

new 
enteffects GetEntProp(entindexProp_Send"m_fEffects");
enteffects |= 32;
SetEntProp(entindexProp_Send"m_fEffects"enteffects); 
you must set solid type to 2 (bounding box) and must set a model on the entity, it doesn't matter which as it won't be visible (remember to precache). by default the entity will try to get the solid type from the bsp which will obviously not work, also the entity will normally have a model/texture applied in hammer so it won't work if there is no model on it. when you set the model you will get an error message in the server console, its harmless. just warning you that you're trying to set a non brush model to the entity.

m_vecMins and m_vecMaxs set the dimensions of the bounding box, they are local coordinates of the entity e.g 0,0,0 will be the entities origin i.e world coordinates of the entity. in my above snippet the box is 200 by 200 by 200.

you must set the m_fEffects prop to have the ef_nodraw flag or clients will be spammed with errors in the conole every gameframe for each entity you create that doesn't have the flag.

in css i've tested func_buyzone, trigger_hurt, trigger_push and func_conveyor, certain entities might not work you'll have to try for yourself. you can addoutputs to the entities and hook the output so you can call a function whenever the output is fired. e.g you could have a trigger_once/trigger_multiple thats fires a blank output that is hooked, this will allow you to run code on whoever triggered the output.

some brush entities would require some kind of visual so you know its there like func_conveyor, since you can't apply models to the brushes you could spawn a prop_dynamic, make it non solid(depending on what brush entity you're using) and parent it to the brush and set the brush bounds to the same as the model. this way you can spawn working doors, switches, moving platforms and rotating props.

that should be useful for sandbox mods and fun stuff, in css you could create a bomb zone anywhere allowing players to plant c4 where ever they want.

Last edited by blodia; 02-09-2011 at 14:53.
blodia is offline