#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.0.2"
public Plugin:myinfo =
{
name = "Following C4",
author = "Mitch",
description = "Aki letette a C4-et azt követni fogja ahova megy..",
version = PLUGIN_VERSION,
url = "http://snbx.info/"
};
new gLeaderOffset;
new C4Hostage;
new FollowingPlayer;
public OnPluginStart()
{
CreateConVar("sm_followingc4_version", PLUGIN_VERSION, "C4Model Version", FCVAR_DONTRECORD|FCVAR_NOTIFY);
gLeaderOffset = FindSendPropOffs("CHostage", "m_leader");
HookEvent("player_death", PlayerDeathEvent);
HookEvent("bomb_planted", BomPlanted_Event);
}
public OnPluginEnd()
{
if(IsHostage(C4Hostage))
{
AcceptEntityInput(C4Hostage, "Kill");
}
}
public OnClientDisconnect(client)
{
if(client==FollowingPlayer)
FindNewPlayer();
}
public PlayerDeathEvent(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = (GetClientOfUserId(GetEventInt(event, "userid")));
if(client==FollowingPlayer)
FindNewPlayer();
}
FindNewPlayer()
{
new Float:orig[3];
GetEntPropVector(C4Hostage, Prop_Send, "m_vecOrigin", orig);
decl Float:vecOrigin_edict[3];
new Float:distance = 0.0;
new closestEdict = INVALID_ENT_REFERENCE;
new Float:edict_distance = 0.0;
for (new edict=1; edict <= MaxClients; edict++) {
if (!IsValidEdict(edict))
continue;
if (edict == C4Hostage)
continue;
if (GetEntSendPropOffs(edict, "m_vecOrigin") == -1)
continue;
GetEntPropVector(edict, Prop_Send, "m_vecOrigin", vecOrigin_edict);
edict_distance = GetVectorDistance(orig, vecOrigin_edict);
if (edict_distance < distance || distance == 0.0)
{
distance = edict_distance;
closestEdict = edict;
}
}
FollowingPlayer = closestEdict;
if(FollowingPlayer > 0 && IsClientInGame(FollowingPlayer) && IsPlayerAlive(FollowingPlayer))
if(IsHostage(C4Hostage))
SetEntDataEnt2(C4Hostage, gLeaderOffset, FollowingPlayer);
}
public OnMapStart()
{
CreateTimer(5.0, Timer_OwnerRepeat, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public Action:Timer_OwnerRepeat(Handle:timer)
{
if(FollowingPlayer > 0 && IsClientInGame(FollowingPlayer) && IsPlayerAlive(FollowingPlayer))
{
if(IsHostage(C4Hostage))
{
SetEntDataEnt2(C4Hostage, gLeaderOffset, FollowingPlayer);
}
}
}
public Action:BomPlanted_Event(Handle:event, const String:name[], bool:dontBroadcast)
{
FollowingPlayer = GetClientOfUserId(GetEventInt(event, "userid"));
new c4 = -1;
c4 = FindEntityByClassname(c4, "planted_c4");
new Float:pos[3], Float:angles[3];
if(c4 != -1)
{
GetEntPropVector(FollowingPlayer, Prop_Data, "m_vecOrigin", pos);
GetEntPropVector(FollowingPlayer, Prop_Data, "m_angRotation", angles);
decl String:c4Model[128];
GetEntPropString(c4, Prop_Data, "m_ModelName", c4Model,sizeof(c4Model));
C4Hostage = CreateEntityByName("hostage_entity");
if((C4Hostage == -1) )
PrintToServer("Error making hostage!");
DispatchKeyValue(C4Hostage, "model", c4Model);
DispatchKeyValue(C4Hostage, "skin", "1");
DispatchKeyValue(C4Hostage, "solid", "0");
DispatchKeyValue(C4Hostage, "disableshadows", "1");
SetEntityModel(C4Hostage, c4Model);
DispatchSpawn(C4Hostage);
SetEntProp(C4Hostage, Prop_Data, "m_takedamage", 0);
SetEntityRenderColor(C4Hostage, 255, 255, 255, 0);
SetEntityRenderMode(C4Hostage, RENDER_TRANSALPHA);
TeleportEntity(C4Hostage, pos, angles, NULL_VECTOR);
SetEntProp(C4Hostage, Prop_Data, "m_CollisionGroup", 1);
SetEntData(C4Hostage, FindSendPropOffs("CHostage", "m_isRescued"), true, 4, true);
SetVariantString("!activator");
AcceptEntityInput(c4, "SetParent", C4Hostage, c4, 0);
}
return Plugin_Continue;
}
bool:IsHostage(Ent)
{
if(Ent != -1)
{
if(IsValidEdict(Ent) && IsValidEntity(Ent) && IsEntNetworkable(Ent))
{
decl String:ClassName[255];
GetEdictClassname(Ent, ClassName, 255);
if(StrEqual(ClassName, "hostage_entity"))
{
return true;
}
}
}
return false;
}