Hello,
I forced the hostages follow a bot, but from a certain distance the hostages stop following this bot.
So I think "refresh" the m_leadeur with a little phrase that verifies this leadeur.
-> The m_leadeur is always present.
I want to know how to disable this distance and if it is not possible for a small solution that does not cease held hostage to follow the bot.
I think the teleport held hostage once it moves away too but this is not the way I want.
Code:
#include <sourcemod>
#include <sdktools>
new g_LeaderOffset;
public OnPluginStart()
{
g_LeaderOffset = FindSendPropOffs("CHostage", "m_leader");
RegConsoleCmd("sm_test", Command_Test);
HookEvent("hostage_follows", Event_HostageFollows, EventHookMode_Pre);
HookEvent("hostage_stops_following", Event_HostageFollows, EventHookMode_Pre);
}
public Action:Event_HostageFollows(Handle:event, const String:name[], bool:dontBroadcast)
{
new Hotage = GetEventInt(event, "hostage");
for(new i = 1; i <= MaxClients; i++)
if(IsClientConnected(i) && IsClientInGame(i) && IsFakeClient(i))
SetEntDataEnt2(Hotage, g_LeaderOffset, i);
return Plugin_Changed;
}
public Action:Command_Test(client, args)
{
new Float:fOrigin[3];
GetPlayerEye(client, fOrigin);
SpawnHotage(fOrigin);
CreateTimer(5.0, Timer_RefreshLeader, _, TIMER_REPEAT);
}
public SpawnHotage(Float:origin[3])
{
new Hotage = CreateEntityByName("hostage_entity");
DispatchKeyValueVector(Hotage, "Origin", origin);
DispatchSpawn(Hotage);
SetEntProp(Hotage, Prop_Data, "m_takedamage", 0);
for(new i = 1; i <= MaxClients; i++)
if(IsClientConnected(i) && IsClientInGame(i) && IsFakeClient(i))
SetEntDataEnt2(Hotage, g_LeaderOffset, i);
SetEntProp(Hotage, Prop_Send, "m_isRescued", 0);
}
public Action:Timer_RefreshLeader(Handle:timer)
{
new entity =-1;
while ((entity = FindEntityByClassname(entity, "hostage_entity")) != -1)
{
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i) && IsClientInGame(i) && IsFakeClient(i))
{
SetEntDataEnt2(entity, g_LeaderOffset, i);
PrintToChatAll("%i - %N", entity, i);
}
}
}
}
stock bool:GetPlayerEye(client, Float:pos[3])
{
new Float:vAngles[3], Float:vOrigin[3];
GetClientEyePosition(client, vOrigin);
GetClientEyeAngles(client, vAngles);
new Handle:trace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SHOT, RayType_Infinite, TraceEntityFilterPlayer);
if(TR_DidHit(trace))
{
TR_GetEndPosition(pos, trace);
CloseHandle(trace);
return (true);
}
CloseHandle(trace);
return (false);
}
public bool:TraceEntityFilterPlayer(entity, contentsMask)
{
return (entity > GetMaxClients() || !entity);
}