AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Creating a zone box (https://forums.alliedmods.net/showthread.php?t=56983)

hlstriker 06-25-2007 19:29

Creating a zone box
 
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?

stupok 06-25-2007 20:13

Re: Creating a zone box
 
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.

hlstriker 06-25-2007 20:38

Re: Creating a zone box
 
Thanks for the reply, stupok69. Do I have to create an entity in the middle of the box? It looks like I do.

stupok 06-25-2007 22:28

Re: Creating a zone box
 
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.

hlstriker 06-26-2007 00:48

Re: Creating a zone box
 
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(); 


stupok 06-26-2007 00:56

Re: Creating a zone box
 
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.

hlstriker 06-26-2007 01:06

Re: Creating a zone box
 
Alright I'm really confused now lol.

What do you mean by with respect to?

stupok 06-26-2007 01:23

Re: Creating a zone box
 
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 :wink:

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.

hlstriker 06-26-2007 01:30

Re: Creating a zone box
 
Ooo now I see what you meant lol.

Thanks a ton +karma :)


All times are GMT -4. The time now is 21:35.

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