AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [Tutorial] Creating brush entities (https://forums.alliedmods.net/showthread.php?t=129597)

blodia 06-14-2010 14:25

[Tutorial] Creating brush entities
 
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.

Afronanny 06-14-2010 15:50

Re: [Tutorial] Creating brush entities
 
I've been wondering how to do this for a while.

Thanks!
:crab::crab::crab:

Sammy-ROCK! 06-14-2010 22:42

Re: [Tutorial] Creating brush entities
 
Good job dude

How did you figure it out?

blodia 06-15-2010 12:56

Re: [Tutorial] Creating brush entities
 
thanks, over the years i've spent a lot of time in the source sdk and on valves wiki checking out different entities. i know from experience that if someone says something isn't possible not to take their word for it. it takes time and patience to get certain things working. also i prefer to mess with things people wouldn't bother with.

Sammy-ROCK! 06-15-2010 16:34

Re: [Tutorial] Creating brush entities
 
How did you find out about the m_vecMins and m_vecMaxs?

blodia 06-15-2010 16:53

Re: [Tutorial] Creating brush entities
 
i tested most netprops/dataprops over the years as i wanted to know what they did in case i ever needed them. the name gave some clue to what it did, you can use it to change the bounding box on any entity, be warned some entities will reset it r.g player bounding boxes are reset in one of the thinks, its resized depending on player movement e.g standing or crouching.

Sammy-ROCK! 06-15-2010 16:57

Re: [Tutorial] Creating brush entities
 
Always good to know that xD Also you can use SDKHooks' ThinkPost to change the bounding box on entitys like that.

strontiumdog 06-15-2010 21:29

Re: [Tutorial] Creating brush entities
 
Nice job, B!

CarlZalph 06-16-2010 12:40

Re: [Tutorial] Creating brush entities
 
Quote:

Originally Posted by Sammy-ROCK! (Post 1209831)
How did you find out about the m_vecMins and m_vecMaxs?

If I recall, the TF2 Engineer building builder has the vector bounds to create them.

Without 'em, collision is not there, or it errors.

henbus 06-20-2010 23:24

Re: [Tutorial] Creating brush entities
 
hi guys ive been trying to learn how to mod. ive been following the valve tutorials at developer.valvesoftware.com/wiki. But I am stuck on the section that teaches you how to author a brush entity http://developer.valvesoftware.com/w...a_Brush_Entity

Apparently I dont have the triggers.h and triggers.cpp files which are needed for functions that allow you to play with brush entities. So basically I can't program my brush entities. So i was wondering is this tutorial like an alternative to teaching us how to program brush entities?

blodia 06-21-2010 07:08

Re: [Tutorial] Creating brush entities
 
this section is for source pawn related tutorials and snippets, you're better off asking in the metamod:source section.

AtomicStryker 06-22-2010 11:39

Re: [Tutorial] Creating brush entities
 
Could one spawn working ladders?

blodia 06-22-2010 13:05

Re: [Tutorial] Creating brush entities
 
i haven't tried but i don't think you can, in the wiki it mentions "This is an internal entity. When the map is compiled by VBSP it is processed and then removed: it does not exist when the map is running." its the same with some other entities.

almcaeobtac 06-22-2010 15:29

Re: [Tutorial] Creating brush entities
 
Great work, this will be extremely useful!

berni 06-30-2010 19:31

Re: [Tutorial] Creating brush entities
 
This tutorial helped me allot. Thank you blodia !

Chrisber 07-01-2010 08:36

Re: [Tutorial] Creating brush entities
 
Wow! You've done an impossible thing. Nice!

flud 07-05-2010 06:31

Re: [Tutorial] Creating brush entities
 
anyone try trigger_teleport ?

PHP Code:

#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION    "2.0"

new String:model[PLATFORM_MAX_PATH] = "models/props_mall/mall_shopliftscanner.mdl";

public 
Plugin:myinfo = {
    
name "test",
    
author "FluD",
    
description "test device",
    
version PLUGIN_VERSION,
    
url "www.alliedmods.net"
}

public 
OnPluginStart(){

    
RegConsoleCmd("sm_test"cmd_test"");
}

public 
Action:cmd_test(client,args){

    new 
index CreateEntityByName("prop_dynamic");
    if (
index != -1){
        new 
Float:position[3];
        
GetCollisionPoint(clientposition);

        if (!
IsModelPrecached(model))
        {
            
PrecacheModel(model);
        }
        
DispatchKeyValue(index"model"model);
        
DispatchKeyValue(index"classname""prop_dynamic");
        
DispatchKeyValue(index"disableselfshadowing""1");
        
DispatchKeyValue(index"disablevertexlighting""1");
        
DispatchKeyValue(index"fademindist""-1");
        
DispatchKeyValue(index"fadescale""1");
        
DispatchKeyValue(index"renderamt""255");
        
DispatchKeyValue(index"rendercolor""255 0 0");
        
DispatchKeyValue(index"skin""0");
        
DispatchKeyValue(index"solid""0");
        
DispatchKeyValueVector(index"Origin"position);
        
DispatchSpawn(index);
    }

    new 
trigger CreateEntityByName("trigger_teleport");
    if (
trigger != -1){
        new 
Float:position[3];
        
GetCollisionPoint(clientposition);

        
DispatchKeyValueVector(trigger"origin"position );
        
DispatchKeyValue(trigger"classname""trigger_teleport");
        
DispatchKeyValue(trigger"spawnflags""15");
        
DispatchKeyValue(trigger"StartDisabled""0");
        
DispatchKeyValue(trigger"target""t_out");
        
DispatchSpawn(trigger);
        
ActivateEntity(trigger);
        
SetEntityModel(triggermodel);

        new 
Float:minbounds[3];
        
minbounds[0] = -100.0;
        
minbounds[1] = -100.0;
        
minbounds[2] = 0.0;

        new 
Float:maxbounds[3];
        
minbounds[0] = 100.0;
        
minbounds[1] = 100.0;
        
minbounds[2] = 200.0;

        
SetEntPropVector(triggerProp_Send"m_vecMins"minbounds);
        
SetEntPropVector(triggerProp_Send"m_vecMaxs"maxbounds);
        
        
SetEntProp(triggerProp_Send"m_nSolidType"2);

        new 
enteffects GetEntProp(triggerProp_Send"m_fEffects");
        
enteffects |= 32;
        
SetEntProp(triggerProp_Send"m_fEffects"enteffects);
    }

    new 
destination CreateEntityByName("info_teleport_destination");
    if (
destination != -1){
        new 
Float:position[3];
        
GetCollisionPoint(clientposition);
        
position[0] = (position[0] + 200);

        
DispatchKeyValueVector(destination"origin"position);
        
DispatchKeyValue(destination"angles""0 0 0");
        
DispatchKeyValue(destination"spawnflags""15");
        
DispatchKeyValue(destination"targetname""t_out");
        
DispatchKeyValue(destination"classname""info_teleport_destination");
        
DispatchSpawn(destination);
    }
    return 
Plugin_Continue;
}

stock GetCollisionPoint(clientFloat:pos[3]){

    
decl Float:vOrigin[3], Float:vAngles[3];

    
GetClientEyePosition(clientvOrigin);
    
GetClientEyeAngles(clientvAngles);

    new 
Handle:trace TR_TraceRayFilterEx(vOriginvAnglesMASK_SOLIDRayType_InfiniteTraceEntityFilterPlayer);

    if(
TR_DidHit(trace))
    {
        
TR_GetEndPosition(postrace);
        
CloseHandle(trace);

        return;
    }
    
CloseHandle(trace);
}

public 
bool:TraceEntityFilterPlayer(entitycontentsMask){
    return 
entity GetMaxClients() || !entity;


does not work :cry: I will be glad if someone can help

blodia 07-05-2010 07:02

Re: [Tutorial] Creating brush entities
 
i would try and test/fix it for you but unfortunately since the css update i haven't been able to get the steam srcds or the standalone working so i can't do anything until its fixed.

do you get any errors? have you tried TeleportEntity instead of setting the origin and angles keyvalue. you also don't need to set the classname keyvalue. although it shouldn't matter try creating the info_teleport_destination before the trigger_teleport

flud 07-05-2010 11:04

Re: [Tutorial] Creating brush entities
 
my bad it's work

PHP Code:

        new Float:minbounds[3]; 
        
minbounds[0] = -100.0
        
minbounds[1] = -100.0
        
minbounds[2] = 0.0

        new 
Float:maxbounds[3]; 
        
minbounds[0] = 100.0
        
minbounds[1] = 100.0
        
minbounds[2] = 200.0

change to
PHP Code:

        new Float:minbounds[3] = {-100.0, -100.00.0}; 
        new 
Float:maxbounds[3] = {100.0100.0200.0}; 

:oops:

flud 07-06-2010 02:50

Re: [Tutorial] Creating brush entities
 
Quote:

Originally Posted by blodia (Post 1208636)
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.

Snippets? :| how to

i try but nothing
PHP Code:

public OnPluginStart(){
HookEntityOutput("trigger_teleport""OnTouching"Entity_OnPlayerTouch);
}

public 
Entity_OnPlayerTouch(const String:output[], calleractivatorFloat:delay){
   
PrintToChatAll("TRIGGERED");


ops again my fault, all ok, just need know entity exist then hook

flud 07-08-2010 08:48

Re: [Tutorial] Creating brush entities
 
it again me :|

possible to set texture on brush ? or make it visible ?

blodia 07-08-2010 09:50

Re: [Tutorial] Creating brush entities
 
you can't do that as that requires bsp models. closest you can do it place a prop_dynamic as mentioned in the first post or maybe an env_sprite_oriented for each face of the brush.

L. Duke 07-12-2010 11:17

Re: [Tutorial] Creating brush entities
 
Nice work! I played around with this once, but I was trying to rely on the bounds for the model I was using and never thought to change the min/max stuff.

flud 07-12-2010 21:39

Re: [Tutorial] Creating brush entities
 
try that, spawn model and get
PHP Code:

GetEntPropVector(modelProp_Send"m_vecMins",minbounds);
GetEntPropVector(modelProp_Send"m_vecMaxs",maxbounds); 

for me it work

alinayg 08-18-2010 19:11

Re: [Tutorial] Creating brush entities
 
Hey guys, I'm not much of a coder, but I was wondering how I could go about putting a brush entity, func_nobuild into a map? If anyone would like to help It would be greatly appreciated.

Thrawn2 08-25-2010 09:41

Re: [Tutorial] Creating brush entities
 
hmm, how do i rotate a trigger_push brush? rotating the entity with teleportentity changes the direction you are being pushed, but not the area.

blodia 08-25-2010 16:55

Re: [Tutorial] Creating brush entities
 
alinayg edit the code snippet in the first post to make a func_nobuild instead of trigger_push and remove the keyvalues. then you just need a way to trigger the code, you could use it on map start or admin/server command.

Thrawn the engine probably handles rotation for entities using the bounding box, i'm guessing since brushes wouldn't normally be using the bounding box they're not updated when the entity is rotated.

Thrawn2 08-25-2010 17:35

Re: [Tutorial] Creating brush entities
 
1 Attachment(s)
so i'd have to adapt the bounding box manually.
i'm assuming the minVec and maxVec are vectors pointing at two opposites corners of the cube.
i need to rotate those. because i dont want rotation along the z axis, i can reduce the problem to 2d.

i thought this should do the trick (read about it here).
it's pretty basic maths, but it doesnt work the way expected.
PHP Code:

stock RotateVector(Float:vector[3], Float:rotation) {
    new 
Float:rVector[3];
    
rVector vector;
    
rVector[0] = vector[0] * Cosine(rotation) - vector[1] * Sine(rotation);
    
rVector[1] = vector[0] * Sine(rotation) + vector[1] * Cosine(rotation);
    
vector rVector;


the results are not what they should be, instead of a rotated square i get "random" rectangles.
or no area at all, i guess thats because sometimes the minvec values are larger than the maxvec values.
i dont know - i'm stuck. i attached the test-plugin i'm using to debug this. it draws on the floor how the square should look like.

blodia 08-25-2010 18:45

Re: [Tutorial] Creating brush entities
 
i've been looking into this more, it seems m_nSolidType 2 is an axis-aligned bounding box so it can't be rotated, its aligned to the world axis and will normally grow/shrink to fit the model.

m_nSolidType 3 is an orientated bounding box which is what you need but looking in const.h of the sdk files it seems its not implemented.

http://developer.valvesoftware.com/wiki/Bounding_volume
http://developer.valvesoftware.com/wiki/Bounding_box

Thrawn2 08-26-2010 01:39

Re: [Tutorial] Creating brush entities
 
huhm, thanks for those infos, makes sense now. :up:
it seems SOLID_OBB isnt implemented, but SOLID_OBB_YAW is. and since i only want to rotate it around the z-axis this could work for me. i'll have a try.

EDIT:
SOLID_OBB puts an aligned square around the actual rotated bounding box.
SOLID_BBOX does not rotate at all.
SOLID_OBB_YAW does not work at all :cry:
http://thrawn.einfachonline.net/imag...6_08_03_37.jpg

blodia 08-26-2010 16:11

Re: [Tutorial] Creating brush entities
 
sorry i don't know what else you could try, guess its another drawback of this method.

Monkeys 02-16-2011 18:13

Re: [Tutorial] Creating brush entities
 
What could cause a spawned brush to not show up at all, without any errors?

databomb 02-16-2011 22:39

Re: [Tutorial] Creating brush entities
 
Wow, I didn't think this was possible! Has anyone tried using a func_precipitation to see if it can rain/snow? Or is this something that isn't possible to spawn after the map starts?

Monkeys 02-16-2011 23:10

Re: [Tutorial] Creating brush entities
 
Quote:

Originally Posted by databomb (Post 1417080)
Wow, I didn't think this was possible! Has anyone tried using a func_precipitation to see if it can rain/snow? Or is this something that isn't possible to spawn after the map starts?

It should be possible. I believe some "theme" mods use it.

blodia 02-17-2011 14:35

Re: [Tutorial] Creating brush entities
 
Quote:

Originally Posted by Monkeys (Post 1416969)
What could cause a spawned brush to not show up at all, without any errors?

hhm not sure, what entity and what game?

Monkeys 02-18-2011 04:00

Re: [Tutorial] Creating brush entities
 
Quote:

Originally Posted by blodia (Post 1417616)
hhm not sure, what entity and what game?

func_respawnroomvisualizer in TF2.
I know there wouldn't be a texture (the noentry one) because you need to set it in Hammer, but it should at least block the people of a different team.

(I set the respawnroomname correctly, and enabled it, but no luck)

blodia 02-18-2011 08:08

Re: [Tutorial] Creating brush entities
 
have you set "solid_to_enemies" to 1 and "Solidity" to 1.

databomb 02-19-2011 10:40

Re: [Tutorial] Creating brush entities
 
blodia, if we wanted a larger area than 100x100x100, must we pick a model that covers that larger brush? Say 1000x1000x1000 for example, has issues. Also, has anyone experienced a problem where players become stuck inside of certain brush entities that aren't drawn and aren't solid (e.g. func_precipitation.)

blodia 02-19-2011 11:39

Re: [Tutorial] Creating brush entities
 
it shouldn't matter which model you use and you should be able to use any size brush.

Monkeys 02-20-2011 10:35

Re: [Tutorial] Creating brush entities
 
I did set solid_to_enemies, but I didn't touch Solidity, as I assumed SolidType already dealt with that.

But this being limited to being parallel to the axes, I can't really use it anymore :/


All times are GMT -4. The time now is 02:31.

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