Raised This Month: $32 Target: $400
 8% 

Hostage Distance Follow


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kriax
Senior Member
Join Date: Apr 2012
Old 06-13-2015 , 11:42   Hostage Distance Follow
Reply With Quote #1

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);
}
Kriax is offline
Oshizu
Veteran Member
Join Date: Nov 2012
Location: Warsaw
Old 06-14-2015 , 08:45   Re: Hostage Distance Follow
Reply With Quote #2

Hi,

Sadly the actual cause of this is a part of CHostage::UpdateFollowing function's code

Presented below part of code seems to check if leader of hostage's (player) is within range 2000 hammer units?
If he is not or he does not meets other specific conditions then hostage won't follow him.
PHP Code:
        // if our rescuer is too far away, give up
        
const float giveUpRange 2000.0f;
        const 
float maxPathLength 4000.0f;
        
Vector toLeader leader->GetAbsOrigin() - GetAbsOrigin();
        if (
toLeader.IsLengthGreaterThangiveUpRange ) || (m_path.IsValid() && m_path.GetLength() > maxPathLength))
        {
            if ( 
hostage_debug.GetInt() < )
            {
                
Idle(); // Set m_leader to NULL.
            
}
            return; 
// Prevent further executing of our UpdateFollowing
        

I've attempted to patch that part of function but sadly failed for now.
You could try setting hostage_debug convar to 2 as a test i suppose
__________________
...

Last edited by Oshizu; 06-14-2015 at 08:57.
Oshizu is offline
Kriax
Senior Member
Join Date: Apr 2012
Old 06-14-2015 , 11:03   Re: Hostage Distance Follow
Reply With Quote #3

Hello,
I knew it .. thank you for having cleared me on the subject.
I hope to find a solution to the problem
Kriax is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:05.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode