#pragma semicolon 1
#include <sdktools>
#include <cstrike>
#include <sdkhooks>
#pragma newdecls required
ConVar
cvTimeSpawn,
cvTimeDiapazon,
cvCountBoxRound;
ArrayList arCoords;
Handle hSpawn;
int iCount;
int iLaser[2];
float fSpawn;
float fInterval;
public void OnPluginStart(){
cvTimeSpawn = CreateConVar("ad_time_spawn", "0.0");
cvTimeDiapazon = CreateConVar("ad_time_range", "0.0");
cvCountBoxRound = CreateConVar("ad_airdrops_on_round", "1");
HookEvent("round_start", OnRoundStart);
RegConsoleCmd("sm_pos", cmd_pos);
RegConsoleCmd("test", test);
}
public Action test(int client, int args){
float pos[3]; GetClientAbsOrigin(client, pos);
TR_TraceRayFilter(pos, view_as<float>({-90.0, 0.0, 0.0}), MASK_SOLID, RayType_Infinite, filter);
if(TR_DidHit())
{
float end[3]; TR_GetEndPosition(end);
float ang[3]; ang[2] = ang[0] = 0.0; ang[1] += GetRandomFloat(-180.0, 180.0);
int drop = CreateEntityByName("prop_physics_multiplayer");
if(drop > 0)
{
DispatchKeyValue(drop, "model", "models/props/cs_militia/crate_extrasmallmill.mdl");
DispatchKeyValueVector(drop, "origin", end);
DispatchKeyValueVector(drop, "angles", ang);
DispatchKeyValue(drop, "massScale", "100.0");
DispatchSpawn(drop);
SetEntProp(drop, Prop_Data, "m_CollisionGroup", 0);
SetEntProp(drop, Prop_Send, "m_nSolidType", 0);
//TE_SetupBeamPoints(pos, end, iLaser[0], iLaser[1], 1, 1, 10.0, 3.0, 10.0, 1, 1.0, {255, 0, 0, 255}, 1);
//TE_SendToAll();
int parachute = CreateEntityByName("prop_physics_override");
if(parachute > 0)
{
DispatchKeyValue(parachute, "model", "models/parachute/parachute_ark.mdl");
end[1] -= 7.0; end[2] -= 20.0;
DispatchKeyValueVector(parachute, "origin", end);
DispatchKeyValueVector(parachute, "angles", ang);
DispatchSpawn(parachute);
SetEntProp(parachute, Prop_Data, "m_CollisionGroup", 0);
SetEntProp(parachute, Prop_Send, "m_nSolidType", 0);
SetEntPropEnt(drop, Prop_Data, "m_hOwnerEntity", parachute);
SetVariantString("!activator");
AcceptEntityInput(parachute, "SetParent", drop);
CreateTimer(0.1, CheckHight, drop, TIMER_REPEAT);
}
}
}
}
public Action cmd_pos(int client, int args){
if(client)
{
float pos[3]; GetClientAbsOrigin(client, pos);
PrintToChat(client, "%.1f %.1f %.1f", pos[0], pos[1], pos[2]);
}
}
public void OnMapStart(){
iLaser[0] = PrecacheModel("sprites/laserbeam.vmt");
iLaser[1] = PrecacheModel("materials/sprites/halo.vmt");
Download();
char cBuff[128];
KeyValues hKV = new KeyValues("AirDrop");
BuildPath(Path_SM, cBuff, sizeof(cBuff), "configs/HungerGames/AirDrop.ini");
if(hKV.ImportFromFile(cBuff))
{
char cGetMap[64]; GetCurrentMap(cGetMap, sizeof(cGetMap));
if(hKV.JumpToKey(cGetMap, false))
{
arCoords = new ArrayList(ByteCountToCells(32));
float temp[3];
if(hKV.GotoFirstSubKey(false))
{
do
{
hKV.GetVector(NULL_STRING, temp);
arCoords.PushArray(temp);
}
while(hKV.GotoNextKey(false));
}
// PrintToServer("%s", cGetMap);
// for(int x; x < arCoords.Length; x++){
// arCoords.GetArray(x, temp);
// PrintToServer("[%d:%d] %.1f %.1f %.1f", x, arCoords.Length, temp[0], temp[1], temp[2]);
// }
}
}
delete hKV;
}
public Action OnRoundStart(Event event, const char[] name, bool db){
delete hSpawn;
if(arCoords)
{
fSpawn = cvTimeSpawn.FloatValue;
fInterval = cvTimeDiapazon.FloatValue;
if(cvCountBoxRound.IntValue > 0 && fSpawn > 0.0 && fInterval >= 0.0)
{
hSpawn = CreateTimer(fSpawn + GetRandomFloat(0.0, fInterval), SpawnAirDrop, _, TIMER_FLAG_NO_MAPCHANGE);
}
}
}
public Action SpawnAirDrop(Handle timer){
float pos[3]; arCoords.GetArray(GetRandomInt(0, arCoords.Length-1), pos);
TR_TraceRayFilter(pos, view_as<float>({-90.0, 0.0, 0.0}), MASK_SOLID, RayType_Infinite, filter);
if(TR_DidHit())
{
float end[3]; TR_GetEndPosition(end);
float ang[3]; ang[1] += GetRandomFloat(-180.0, 180.0);
int drop = CreateEntityByName("prop_physics_multiplayer");
if(drop > 0)
{
DispatchKeyValue(drop, "model", "models/props/cs_militia/crate_extrasmallmill.mdl");
DispatchKeyValueVector(drop, "origin", end);
DispatchKeyValueVector(drop, "angles", ang);
DispatchKeyValue(drop, "massScale", "100.0");
DispatchSpawn(drop);
SetEntProp(drop, Prop_Data, "m_CollisionGroup", 0);
SetEntProp(drop, Prop_Send, "m_nSolidType", 0);
//TE_SetupBeamPoints(pos, end, iLaser[0], iLaser[1], 1, 1, 10.0, 3.0, 10.0, 1, 1.0, {255, 0, 0, 255}, 1);
//TE_SendToAll();
int parachute = CreateEntityByName("prop_physics_override");
if(parachute > 0)
{
DispatchKeyValue(parachute, "model", "models/parachute/parachute_ark.mdl");
end[2] -= 20.0;
DispatchKeyValueVector(parachute, "origin", end);
DispatchKeyValueVector(parachute, "angles", ang);
DispatchSpawn(parachute);
SetEntProp(parachute, Prop_Data, "m_CollisionGroup", 0);
SetEntProp(parachute, Prop_Send, "m_nSolidType", 0);
SetEntPropEnt(drop, Prop_Data, "m_hOwnerEntity", parachute);
SetVariantString("!activator");
AcceptEntityInput(parachute, "SetParent", drop);
CreateTimer(0.1, CheckHight, drop, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
iCount++;
}
}
}
hSpawn = null;
}
public Action CheckHight(Handle timer, int drop){
if(IsValidEntity(drop))
{
int parachute = GetEntPropEnt(drop, Prop_Data, "m_hOwnerEntity");
if(IsValidEntity(parachute))
{
float pos[3]; GetEntPropVector(drop, Prop_Data, "m_vecOrigin", pos);
float speed[3] = {0.0, 0.0, -50.0};
TeleportEntity(drop, NULL_VECTOR, NULL_VECTOR, speed);
TR_TraceRayFilter(pos, view_as<float>({90.0, 0.0, 0.0}), MASK_SOLID, RayType_Infinite, filter);
if(TR_DidHit())
{
float end[3]; TR_GetEndPosition(end);
if(GetVectorDistance(pos, end) <= 300.0){
SetEntProp(drop, Prop_Data, "m_CollisionGroup", 9);
SetEntProp(drop, Prop_Send, "m_nSolidType", 6);
//SetEntProp(drop, Prop_Data, "m_usSolidFlags", 1);
RemoveEntity(parachute);
if(iCount < cvCountBoxRound.IntValue)
hSpawn = CreateTimer(fSpawn + GetRandomFloat(0.0, fInterval), SpawnAirDrop, _, TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
return Plugin_Continue;
}
}
}
return Plugin_Stop;
}
public bool filter(int entity, int mask){
return entity >= 0;
}
void Download(){
PrecacheModel("models/parachute/parachute_ark.mdl", false);
AddFileToDownloadsTable("models/parachute/parachute_ark.dx80.vtx");
AddFileToDownloadsTable("models/parachute/parachute_ark.dx90.vtx");
AddFileToDownloadsTable("models/parachute/parachute_ark.mdl");
AddFileToDownloadsTable("models/parachute/parachute_ark.sw.vtx");
AddFileToDownloadsTable("models/parachute/parachute_ark.vvd");
AddFileToDownloadsTable("models/parachute/parachute_ark.xbox.vtx");
PrecacheDecal("materials/models/parachute/parachute_ark.vmt", false);
AddFileToDownloadsTable("materials/models/parachute/parachute_ark.vmt");
AddFileToDownloadsTable("materials/models/parachute/parachute_ark.vtf");
PrecacheDecal("materials/models/parachute/parachute_ark_backpack.vmt", false);
AddFileToDownloadsTable("materials/models/parachute/parachute_ark_backpack.vmt");
AddFileToDownloadsTable("materials/models/parachute/parachute_ark_backpack.vtf");
PrecacheModel("models/props/cs_militia/crate_extrasmallmill.mdl", false);
}