#include <sourcemod>
#include <sdktools>
#define MODEL_PILLS "models/w_models/weapons/w_eq_painpills.mdl"
#define MODEL_ADRENALINE "models/w_models/weapons/w_eq_adrenaline.mdl"
#define MODEL_FIRST_AID_KIT "models/w_models/weapons/w_eq_Medkit.mdl"
#define MODEL_BOX "models/props_junk/wood_crate001a.mdl"
public OnPluginStart()
{
RegAdminCmd("sm_box", box_spawn, ADMFLAG_ROOT);
}
public OnMapStart()
{
PrecacheModel("models/w_models/weapons/w_eq_painpills.mdl", true);
PrecacheModel("models/w_models/weapons/w_eq_adrenaline.mdl", true);
PrecacheModel("models/w_models/weapons/w_eq_Medkit.mdl", true);
PrecacheModel("models/props_junk/wood_crate001a.mdl", true);
}
public Action:box_spawn(client, args)
{
float Look[3];
GetLookPos(client, Look);
new karobka = CreateEntityByName("prop_physics");
if (karobka > MaxClients)
{
DispatchKeyValueVector(karobka, "origin", Look);
DispatchKeyValue(karobka, "health", "10");
SetEntityModel(karobka, MODEL_BOX);
DispatchSpawn(karobka);
}
}
public OnEntityDestroyed(entity)
{
new String:model_name[256];
GetEntPropString(entity, Prop_Data, "m_ModelName", model_name, sizeof(model_name));
if (StrContains(model_name, "models/props_junk/wood_crate001a.mdl", false) != -1)
{
float ent_pos[3];
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", ent_pos)
switch(GetRandomInt(1, 6))
{
case 1, 2:
{
new adrenaline = CreateEntityByName("weapon_adrenaline");
PrintHintTextToAll("Была сломана коробка из которой выпал адреналин");
DispatchSpawn(adrenaline);
SetEntityModel(adrenaline, MODEL_ADRENALINE);
TeleportEntity(adrenaline, ent_pos, NULL_VECTOR, NULL_VECTOR);
}
case 3:
{
new first_aid_kit = CreateEntityByName("weapon_first_aid_kit");
PrintHintTextToAll("Была сломана коробка из которой выпала аптечка");
DispatchSpawn(first_aid_kit);
SetEntityModel(first_aid_kit, MODEL_FIRST_AID_KIT);
TeleportEntity(first_aid_kit, ent_pos, NULL_VECTOR, NULL_VECTOR);
}
case 4,6:
{
new pills = CreateEntityByName("weapon_pain_pills");
PrintHintTextToAll("Была сломана коробка из которой выпали таблетки");
DispatchSpawn(pills);
SetEntityModel(pills, MODEL_PILLS);
TeleportEntity(pills, ent_pos, NULL_VECTOR, NULL_VECTOR);
}
}
}
}
stock GetLookPos(client, Float:v[3])
{
decl Float:EyePosition[3], Float:EyeAngles[3], Handle:h_trace;
GetClientEyePosition(client, EyePosition);
GetClientEyeAngles(client, EyeAngles);
h_trace = TR_TraceRayFilterEx(EyePosition, EyeAngles, MASK_SOLID, RayType_Infinite, GetLookPos_Filter, client);
TR_GetEndPosition(v, h_trace);
CloseHandle(h_trace);
}
public bool:GetLookPos_Filter(ent, mask, any:client)
{
return client != ent;
}