Hello!
I had made a plugin that makes some places on the map as special zones where you can do some things. The problem is that when you create such an zone, you have to be careful to make it so that it can't touch other entities because it will disappear when that entity will move.
Here is my code:
PHP Code:
#define MAX_NETS 10
#define TASK_LASTTOUCH 3300
#define TASK_SHOWNET 1000
#define REFRESH_TIME 2.0
#define CHANGE_TIME 5.0
new _szType[][32]=
{
"CTZONE",
"CANTEEN",
"CELLS",
"WORKOUT"
}
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
register_forward(FM_PlayerPreThink, "PlayerPreThink", 0)
for(new i = 0; i < typeZn; i ++)
{
register_touch(_szType[i], "player", "FwdTouch");
}
for(new i = 1; i < 33; i ++)
{
g_LastTouch[i] = -1;
g_MenuType[i] = 0;
}
}
CreateNet(szType[32], Float:firstPoint[3], Float:lastPoint[3])
{
new ent
new Float:fCenter[3], Float:fSize[3]
new Float:fMins[3], Float:fMaxs[3]
for ( new i = 0; i < 3; i++ )
{
fCenter[i] = (firstPoint[i] + lastPoint[i]) / 2.0
fSize[i] = get_float_difference(firstPoint[i], lastPoint[i])
fMins[i] = fSize[i] / -2.0
fMaxs[i] = fSize[i] / 2.0
}
ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
if (ent) {
engfunc(EngFunc_SetOrigin, ent, fCenter)
set_pev(ent, pev_classname, szType)
dllfunc(DLLFunc_Spawn, ent)
set_pev(ent, pev_movetype, MOVETYPE_FLY)
set_pev(ent, pev_solid, SOLID_TRIGGER)
engfunc(EngFunc_SetSize, ent, fMins, fMaxs)
}
}
public getZonesType (Classname[32])
{
for(new i = 0; i <typeZn; i++)
{
if(equal(Classname,_szType[i]))
{
return i
}
}
return -1
}
public FwdTouch(ent, id)
{
if(is_user_alive(id))
{
static szNameEnt[32]
pev(ent,pev_classname, szNameEnt,sizeof szNameEnt - 1)
static Float:fGameTime
fGameTime = get_gametime()
if((fGameTime - g_fLastTouch[id]) > REFRESH_TIME)
{
set_hudmessage(255, 20, 20, -1.0, 0.4, 1, 1.0, 1.5, 0.1, 0.1, 2)
show_hudmessage(id, "** You are in %s ! **",szNameEnt)
g_fLastTouch[id] = fGameTime
g_LastTouch[id] = getZonesType(szNameEnt)
remove_task(TASK_LASTTOUCH + id)
set_task(CHANGE_TIME,"resetLastTouch",TASK_LASTTOUCH + id)
}
}
}
The net thing was taken from a kickball plugin.
Thanks in advance