sm-plugins/_CTimer/scripting/ctimer/zones.sp

151 lines
3.6 KiB
SourcePawn
Raw Normal View History

2019-06-19 20:54:56 +02:00
public void CreateTrigger(int zone)
{
if ((g_fStartOrigins[zone][0] == 0.0) && (g_fStartOrigins[zone][1] == 0.0) && (g_fStartOrigins[zone][2] == 0.0) && (g_fEndOrigins[zone][0] == 0.0) && (g_fEndOrigins[zone][1] == 0.0) && (g_fEndOrigins[zone][2] == 0.0))
return;
if (g_iTriggerEnt[zone] > -1)
{
if (IsValidEntity(g_iTriggerEnt[zone]))
{
AcceptEntityInput(g_iTriggerEnt[zone], "Kill");
}
g_iTriggerEnt[zone] = -1;
}
float max[3];
float min[3];
min = g_fStartOrigins[zone];
max = g_fEndOrigins[zone];
char name[12];
if (zone == 0)
Format(name, sizeof name, "start");
if (zone == 1)
Format(name, sizeof name, "end");
float mid[3] = 0.0;
max[2]+=100;
GetMiddleOfABox(max, min, mid);
min[0] = min[0] - mid[0];
if(min[0] > 0.0)
min[0] *= -1.0;
min[1] = min[1] - mid[1];
if(min[1] > 0.0)
min[1] *= -1.0;
min[2] = min[2] - mid[2];
if(min[2] > 0.0)
min[2] *= -1.0;
max[0] = max[0] - mid[0];
if(max[0] < 0.0)
max[0] *= -1.0;
max[1] = max[1] - mid[1];
if(max[1] < 0.0)
max[1] *= -1.0;
max[2] = max[2] - mid[2];
if(max[2] < 0.0)
max[2] *= -1.0;
g_iTriggerEnt[zone] = CreateEntityByName("trigger_multiple");
DispatchKeyValue(g_iTriggerEnt[zone], "spawnflags", "1");
DispatchKeyValue(g_iTriggerEnt[zone], "targetname", name);
DispatchKeyValue(g_iTriggerEnt[zone], "wait", "0");
DispatchSpawn(g_iTriggerEnt[zone]);
ActivateEntity(g_iTriggerEnt[zone]);
//PrintToServer("Dispatched and activated %s", name);
TeleportEntity(g_iTriggerEnt[zone], mid, NULL_VECTOR, NULL_VECTOR);
SetEntityModel(g_iTriggerEnt[zone], "models/error.mdl");
//PrintToServer("Teleported and set model %s", name);
SetEntPropVector(g_iTriggerEnt[zone], Prop_Send, "m_vecMins", min);
SetEntPropVector(g_iTriggerEnt[zone], Prop_Send, "m_vecMaxs", max);
SetEntProp(g_iTriggerEnt[zone], Prop_Send, "m_nSolidType", 2);
//PrintToServer("Set vecs and solidtype %s", name);
int iEffects = GetEntProp(g_iTriggerEnt[zone], Prop_Send, "m_fEffects");
iEffects |= 0x020;
SetEntProp(g_iTriggerEnt[zone], Prop_Send, "m_fEffects", iEffects);
//PrintToServer("Set effects %s", name);
SDKHook(g_iTriggerEnt[zone], SDKHook_StartTouch, zoneStartTouch);
SDKHook(g_iTriggerEnt[zone], SDKHook_EndTouch, zoneEndTouch);
//PrintToServer("Hooks Hooked %s", name);
}
public Action zoneEndTouch (int caller, int client)
{
if (!isValidClient(client) || client == g_iEditor || !g_bActive)
return;
char trigName[16];
GetEntPropString(caller, Prop_Data, "m_iName", trigName, sizeof trigName);
//Player is Exiting Start Zone
if (StrEqual(trigName, "start"))
{
//Player is on starzone state, start run
if (g_iActivity[client] == 1)
{
CheckSpeed(client);
g_iActivity[client] = 0;
g_fStartTime[client] = GetEngineTime();
g_arrayRun[client].Clear();
}
}
//Player is Exiting End Zone
if (StrEqual(trigName, "end"))
{
//Set Player Inactive
g_iActivity[client] = -1;
//EndZoneRoutine(client);
}
}
public Action zoneStartTouch (int caller, int client)
{
if (!isValidClient(client) || client == g_iEditor || !g_bActive)
return;
char trigName[16];
GetEntPropString(caller, Prop_Data, "m_iName", trigName, sizeof trigName);
//Player is Entering Start Zone
if (StrEqual(trigName, "start"))
{
//Player teleported from endzone, exec endzoneroutine before reset
if (g_iActivity[client] == 2)
{
//EndZoneRoutine(client);
}
//TODO: Reset record array;
g_iActivity[client] = 1;
}
if (StrEqual(trigName, "end"))
{
if (g_iActivity[client] == 0)
{
ProcessFinish(client);
g_iActivity[client] = 2;
}
}
}
/*public void EndZoneRoutine(int client)
{
//TODO: Save Bot if needed
}*/