PHP Code:
public void CreateZoneEntity(int zoneIndex)
{
float fMiddle[3], fMins[3], fMaxs[3];
char sZoneName[64];
Array_Copy(g_mapZones[zoneIndex][PointA], fMins, 3); // fMins - PointA
Array_Copy(g_mapZones[zoneIndex][PointB], fMaxs, 3); // fMaxs - PointB
Format(sZoneName, sizeof(sZoneName), "%s", g_mapZones[zoneIndex][zoneName]);
int iEnt = CreateEntityByName("trigger_multiple");
if (iEnt > 0 && IsValidEntity(iEnt)) {
SetEntityModel(iEnt, ZONE_MODEL); // "models/props/de_train/barrel.mdl"
// Spawnflags: 1 - only a player can trigger this by touch, makes it so a NPC cannot fire a trigger_multiple
// 2 - Won't fire unless triggering ent's view angles are within 45 degrees of trigger's angles (in addition to any other conditions), so if you want the player to only be able to fire the entity at a 90 degree angle you would do ",angles,0 90 0," into your spawnstring.
// 4 - Won't fire unless player is in it and pressing use button (in addition to any other conditions), you must make a bounding box,(max\mins) for this to work.
// 8 - Won't fire unless player/NPC is in it and pressing fire button, you must make a bounding box,(max\mins) for this to work.
// 16 - only non-player NPCs can trigger this by touch
// 128 - Start off, has to be activated by a target_activate to be touchable/usable
// 256 - multiple players can trigger the entity at the same time
DispatchKeyValue(iEnt, "spawnflags", "257");
DispatchKeyValue(iEnt, "StartDisabled", "0");
Format(sZoneName, sizeof(sZoneName), "sm_ckZone %i", zoneIndex);
DispatchKeyValue(iEnt, "targetname", sZoneName);
DispatchKeyValue(iEnt, "wait", "0");
if (DispatchSpawn(iEnt))
{
ActivateEntity(iEnt);
GetMiddleOfABox(fMins, fMaxs, fMiddle);
TeleportEntity(iEnt, fMiddle, NULL_VECTOR, NULL_VECTOR);
// Have the mins always be negative
for(int i = 0; i < 3; i++){
fMins[i] = fMins[i] - fMiddle[i];
if(fMins[i] > 0.0)
fMins[i] *= -1.0;
}
// And the maxs always be positive
for(int i = 0; i < 3; i++){
fMaxs[i] = fMaxs[i] - fMiddle[i];
if(fMaxs[i] < 0.0)
fMaxs[i] *= -1.0;
}
SetEntPropVector(iEnt, Prop_Send, "m_vecMins", fMins);
SetEntPropVector(iEnt, Prop_Send, "m_vecMaxs", fMaxs);
SetEntProp(iEnt, Prop_Send, "m_nSolidType", 2);
int iEffects = GetEntProp(iEnt, Prop_Send, "m_fEffects");
iEffects |= 0x020;
SetEntProp(iEnt, Prop_Send, "m_fEffects", iEffects);
SDKHook(iEnt, SDKHook_StartTouch, StartTouchTrigger);
SDKHook(iEnt, SDKHook_EndTouch, EndTouchTrigger);
}
else
{
LogError("Not able to dispatchspawn for Entity %i in SpawnTrigger", iEnt);
}
}
}
stock void GetMiddleOfABox(const float vec1[3], const float vec2[3], float buffer[3])
{
float mid[3];
MakeVectorFromPoints(vec1, vec2, mid);
mid[0] = mid[0] / 2.0;
mid[1] = mid[1] / 2.0;
mid[2] = mid[2] / 2.0;
AddVectors(vec1, mid, buffer);
}
you can use this code to create an entity and check if the player inside by hooking StartTouch and EndTouch.