Raised This Month: $ Target: $400
 0% 

Creating a zone box


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 06-25-2007 , 19:29   Creating a zone box
Reply With Quote #1

I saw this posted by VEN in another thread to make a zone box...

Quote:
new box_min[3] = {1, 1, 1}
new box_max[3] = {100, 100, 100}
Now here are my questions:
1) How exactly would I know how to place one of these boxes in a certain location?
2) Is there a way to visually see the box that is created?
3) How would I detect when a player goes into one of the zones?
hlstriker is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 06-25-2007 , 20:13   Re: Creating a zone box
Reply With Quote #2

Code:
1) #include <amxmodx> #include <fakemeta> //... new Float:origin[3] pev(entid, pev_origin, origin) new Float:mins[3], Float:maxs[3] mins[0] = origin[0] - 1.0 mins[1] = origin[1] - 1.0 mins[2] = origin[2] - 1.0 maxs[0] = origin[0] + 100.0 maxs[1] = origin[1] + 100.0 maxs[2] = origin[2] + 100.0 set_pev(entid, pev_absmin, mins) //or set_pev(entid, pev_mins, mins) set_pev(entid, pev_absmax, maxs) //or set_pev(entid, pev_maxs, maxs) 2) //... //from message_const.inc //#define TE_BOX                      31 // write_byte(TE_BOX) // write_coord(boxmins.x) // write_coord(boxmins.y) // write_coord(boxmins.z) // write_coord(boxmaxs.x) // write_coord(boxmaxs.y) // write_coord(boxmaxs.z) // write_short(life in 0.1 s) // write_byte(red) // write_byte(green) // write_byte(blue) 3) //... public plugin_init() {     register_forward(FM_Touch, "forward_Touch", 0) } public forward_Touch(ptr, ptd) {     new classname[32]     pev(ptd, pev_classname, classname, 31)         if(equal(classname, "class_name"))     {         //...     } }

That's the best I can do, I'm not sure if everything is actually correct. Hopefully someone can correct me or confirm that I'm right.
stupok is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 06-25-2007 , 20:38   Re: Creating a zone box
Reply With Quote #3

Thanks for the reply, stupok69. Do I have to create an entity in the middle of the box? It looks like I do.
hlstriker is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 06-25-2007 , 22:28   Re: Creating a zone box
Reply With Quote #4

Well you generally assign a box to entities so you can collide with them. I think tying the box to an entity is the only way you'll be later to detect if something touches the box. The origin of the entity doesn't actually matter, but generally the entity is in the center of the box, that's why I added your mins and maxs to the ent's origin.
stupok is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 06-26-2007 , 00:48   Re: Creating a zone box
Reply With Quote #5

Ok thanks stupok69. I understand how this works now.

I am having a problem though. I can see the box outlined in TE_BOX, but some reason it's not blocking my player. I have the solid type set to BBOX so the whole box I created should block the player.

The line...
"entity_set_size(ent, mins, maxs);"
should set the size to be blocked correct? Some reason it isn't working

btw I use engine as you can see : /

PHP Code:
    ent create_entity("info_target");
    
entity_set_string(entEV_SZ_classname"safebox_blue");
    
entity_set_int(entEV_INT_solidSOLID_BBOX);
    
entity_set_int(entEV_INT_movetypeMOVETYPE_FLY);
    
origin[0] = float(1663);
    
origin[1] = float(3411);
    
origin[2] = float(679);
    
entity_set_origin(entorigin);
    
    
mins[0] = origin[0] - float(255);
    
mins[1] = origin[1] - float(115);
    
mins[2] = origin[2] - float(71);
    
    
maxs[0] = origin[0] + float(255);
    
maxs[1] = origin[1] + float(115);
    
maxs[2] = origin[2] + float(71);
    
    
entity_set_size(entminsmaxs); // This sets the blocking size?
    
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY);
    
write_byte(31); // TE_BOX
    
write_coord(floatround(mins[0])); // boxmins
    
write_coord(floatround(mins[1]));
    
write_coord(floatround(mins[2]));
    
write_coord(floatround(maxs[0])); // boxmaxs
    
write_coord(floatround(maxs[1]));
    
write_coord(floatround(maxs[2]));
    
write_short(999999); // life in 0.1 s
    
write_byte(255); // r
    
write_byte(0); // g
    
write_byte(0); // b
    
message_end(); 

Last edited by hlstriker; 06-26-2007 at 00:51.
hlstriker is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 06-26-2007 , 00:56   Re: Creating a zone box
Reply With Quote #6

You're using engine, so it's a little bit different than my example. Originally I didn't understand the difference between pev_absmin and pev_mins but now I think I do.

pev_absmin contains the coordinates with respect to (0.0, 0.0, 0.0)
pev_mins contains the coordinates with respect to the entity's origin


When you are doing this:
Code:
entity_set_size(ent, mins, maxs)
It's equivalent to using fakemeta like this:
Code:
set_pev(ent, pev_mins, mins)
set_pev(ent, pev_maxs, maxs)
So you should use coordinates with respect to the entity's origin when you set its size with entity_set_size(). However, you should use coordinates with respect to (0.0, 0.0, 0.0) when you are drawing the box with write_byte(31); // TE_BOX.

By the way, you should use "TE_BOX" instead of "31", it should be defined already. It's always better to avoid hard-coding when you can.
stupok is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 06-26-2007 , 01:06   Re: Creating a zone box
Reply With Quote #7

Alright I'm really confused now lol.

What do you mean by with respect to?
hlstriker is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 06-26-2007 , 01:23   Re: Creating a zone box
Reply With Quote #8

Lets say that the X coordinate of pev_mins is 100 units to the left of the entity. That means that it is -100 with respect to the entity's X coordinate. That means the pev_mins X coordinate is -100 and the pev_absmin X coordinate is ent_x_coord - 100.

Here ya go

Code:
//ENGINE ent = create_entity("info_target"); entity_set_string(ent, EV_SZ_classname, "safebox_blue"); entity_set_int(ent, EV_INT_solid, SOLID_BBOX); entity_set_int(ent, EV_INT_movetype, MOVETYPE_FLY); origin = {1663.0, 3411.0, 679.0} entity_set_origin(ent, origin); mins = {-255.0, -115.0, -71.0} maxs = {255.0, 115.0, 71.0} entity_set_size(ent, mins, maxs); // This sets the blocking size? mins[0] = origin[0] - 255.0; mins[1] = origin[1] - 115.0; mins[2] = origin[2] - 71.0; maxs[0] = origin[0] + 255.0; maxs[1] = origin[1] + 115.0; maxs[2] = origin[2] + 71.0; message_begin(MSG_BROADCAST, SVC_TEMPENTITY); write_byte(TE_BOX); write_coord(floatround(mins[0])); // boxmins write_coord(floatround(mins[1])); write_coord(floatround(mins[2])); write_coord(floatround(maxs[0])); // boxmaxs write_coord(floatround(maxs[1])); write_coord(floatround(maxs[2])); write_short(999999); // life in 0.1 s write_byte(255); // r write_byte(0); // g write_byte(0); // b message_end(); //FAKEMETA ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target")); set_pev(ent, pev_classname, "safebox_blue"); set_pev(ent, pev_solid, SOLID_BBOX); set_pev(ent, pev_movetype, MOVETYPE_FLY); origin = {1663.0, 3411.0, 679.0}; engfunc(EngFunc_SetOrigin, ent, origin); mins[0] = origin[0] - 255.0; mins[1] = origin[1] - 115.0; mins[2] = origin[2] - 71.0; maxs[0] = origin[0] + 255.0; maxs[1] = origin[1] + 115.0; maxs[2] = origin[2] + 71.0; set_pev(ent, pev_absmin, mins); set_pev(ent, pev_absmax, maxs); message_begin(MSG_BROADCAST, SVC_TEMPENTITY); write_byte(TE_BOX); engfunc(EngFunc_WriteCoord, mins[0]); engfunc(EngFunc_WriteCoord, mins[1]); engfunc(EngFunc_WriteCoord, mins[2]); engfunc(EngFunc_WriteCoord, maxs[0]); engfunc(EngFunc_WriteCoord, maxs[1]); engfunc(EngFunc_WriteCoord, maxs[2]); write_short(999999); // life in 0.1 s write_byte(255); // r write_byte(0); // g write_byte(0); // b message_end();

I can't guarantee that either one will work for sure, but I feel confident about both of them.

Last edited by stupok; 06-26-2007 at 01:26.
stupok is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 06-26-2007 , 01:30   Re: Creating a zone box
Reply With Quote #9

Ooo now I see what you meant lol.

Thanks a ton +karma
hlstriker 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 21:35.


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