Raised This Month: $51 Target: $400
 12% 

Solved Grab wtf?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Javierko
AlliedModders Donor
Join Date: Sep 2017
Location: Czech republic
Old 11-27-2017 , 09:20   Grab wtf?
Reply With Quote #1

Hey coders,

i am using Hook grab rope plugin on our servers and i want to make it works after death (admins can grab after they die)...

In code was IsPlayerAlive, sure if i remove it, grab works in death cam, but when death admin grab something or somebody and drop bind button, he has still item or player in grab and admin must reconnect...

Here is my edited code:

PHP Code:
public Action_Grab(client)
{
    if(
g_cvarEnable[Grab] && g_Frozen[Grab])
    {
        if( 
client &&
            
client <= MaxClients &&
            !
g_Status[client][Grab] &&
            !
g_Grabbed[client])
        {
            if(
HasAccess(clientGrab))
            {
                
g_Status[client][Grab] = true// Tell plugin the seeker is grabbing a player
                
                // Call grab search forward
                
new ret;
                
Call_StartForward(FwdClientGrabSearch);
                
Call_PushCell(client);
                
Call_Finish(ret);
                if(
ret)
                {
                    
g_Status[client][Grab] = false;
                    return;
                }
                
                
// Start grab search timer
                
CreateTimer(0.1GrabSearchclientTIMER_REPEAT); // Start a timer that searches for a client to grab
            
}
            else
                
PrintToChat(client,"\x01\x0B\x04[HGR]\x01 %t\x04 grab.""No Permission");
        }
    }
    else
        
PrintToChat(client"\x01\x0B\x04[HGR] Grab\x01 %t""Disabled");
}

public 
Action:GrabSearch(Handle:timerany:client)
{
    
PrintCenterText(client"%t""Searching"); // Tell client the plugin is searching for a target
    
if( client &&
        
IsClientInGame(client) &&
        
g_Status[client][Grab] &&
        !
g_Grabbed[client])
    {
        
// Init variables
        
new Float:clientloc[3], Float:clientang[3];
        
GetClientEyePosition(clientclientloc);
        
GetClientEyeAngles(clientclientang);
        
        
// Grab search traceray
        
TR_TraceRayFilter(clientlocclientangMASK_ALLRayType_InfiniteTraceRayGrabEnt); // Create a ray that tells where the player is looking
        
g_Targetindex[client][Grab] = TR_GetEntityIndex(); // Set the seekers targetindex to the person he picked up
        
        // Found a player or object
        
if(g_Targetindex[client][Grab] > && IsValidEntity(g_Targetindex[client][Grab]))
        {
            
// Init variables
            
new Float:targetloc[3];
            
GetEntityOrigin(g_Targetindex[client][Grab], targetloc); // Find the target's xyz coordinate
            
g_Distance[client][1] = GetVectorDistance(targetlocclientloc); // Tell plugin the distance between the two to maintain
            
if( g_Targetindex[client][Grab] > &&
                
g_Targetindex[client][Grab] <= MaxClients &&
                
IsClientInGame(g_Targetindex[client][Grab]))
            {
                
g_MaxSpeed[client] = GetEntPropFloat(clientProp_Send"m_flMaxspeed");
                
g_Grabbed[g_Targetindex[client][Grab]] = true// If target is a player, tell plugin player is being grabbed
                
SetEntPropFloat(g_Targetindex[client][Grab], Prop_Send"m_flMaxspeed"0.01); // Slow grab target
            
}
            
            
// Call grab forward
            
new ret;
            
Call_StartForward(FwdClientGrab);
            
Call_PushCell(client);
            
Call_Finish(ret);
            if(
ret)
            {
                
Action_Drop(client);
                return 
Plugin_Stop;
            }
            
            
// Finish grabbing
            
EmitSoundFromOrigin(g_cvarSound[Grab], targetloc); // Emit sound from the entity being grabbed
            
CreateTimer(0.05GrabbingclientTIMER_REPEAT); // Start a repeating timer that will reposition the target in the grabber's crosshairs
            
return Plugin_Stop// Stop the search timer
        
}
    }
    else
    {
        
Action_Drop(client);
        return 
Plugin_Stop// Stop the timer
    
}
    return 
Plugin_Continue;
}

public 
Action:Grabbing(Handle:timerany:client)
{
    
PrintCenterText(client"%t""Found");
    if( 
IsClientInGame(client) &&
        
g_Status[client][Grab] &&
        !
g_Grabbed[client] &&
        
IsValidEntity(g_Targetindex[client][Grab]))
    {
        if( 
g_Targetindex[client][Grab] > MaxClients ||
            
g_Targetindex[client][Grab] > &&
            
g_Targetindex[client][Grab] <= MaxClients &&
            
IsClientInGame(g_Targetindex[client][Grab]))
        {
            
// Init variables
            
new Float:clientloc[3], Float:clientang[3], Float:targetloc[3], Float:velocity[3];
            
GetClientEyePosition(clientclientloc);
            
GetClientEyeAngles(clientclientang);
            
GetEntityOrigin(g_Targetindex[client][Grab], targetloc);

            
// Grab traceray
            
g_TRIgnore[client] = true;
            
TR_TraceRayFilter(clientlocclientangMASK_ALLRayType_InfiniteTraceRayTryToHit); // Find where the player is aiming
            
TR_GetEndPosition(velocity); // Get the end position of the trace ray
            
g_TRIgnore[client] = false;
            
            
// Calculate velocity vector
            
SubtractVectors(velocityclientlocvelocity);
            
NormalizeVector(velocityvelocity);
            if(
g_Attracting[client][0])
                
g_Distance[client][1] += g_cvarSpeed[1] * 10.0;
            else if(
g_Attracting[client][1])
            {
                
g_Distance[client][1] -= g_cvarSpeed[1] * 10.0;
                if(
g_Distance[client][1] <= 30.0)
                    
g_Distance[client][1] = 30.0;
            }
            
ScaleVector(velocityg_Distance[client][1]);
            
AddVectors(velocityclientlocvelocity);
            
SubtractVectors(velocitytargetlocvelocity);
            
ScaleVector(velocityg_cvarSpeed[1] * 5);
            
            
// Move grab target
            
TeleportEntity(g_Targetindex[client][Grab], NULL_VECTORNULL_VECTORvelocity);
            
            
// Make a beam from grabber to grabbed
            
new color[4];
            if(
g_Targetindex[client][Grab] <= MaxClients)
                
targetloc[2] += 45;
            
clientloc[2] -= 5;
            
GetBeamColor(clientGrabcolor);
            
BeamEffect(clientloctargetloc0.2g_cvarInitWidth[1], g_cvarEndWidth[1], colorg_cvarAmplitude[1], 0);
        }
        else
        {
            
Action_Drop(client);
            return 
Plugin_Stop// Stop the timer
        
}
    }
    else
    {
        
Action_Drop(client);
        return 
Plugin_Stop// Stop the timer
    
}
    return 
Plugin_Continue;
}

public 
Action_Drop(client)
{
    if( 
IsClientInGame(client) &&
        
g_Status[client][Grab] )
    {
        
g_Status[client][Grab] = false// Tell plugin the grabber has dropped his target
        
if(g_Targetindex[client][Grab] > 0)
        {
            
PrintCenterText(client"%t""Dropped");
            if( 
g_Targetindex[client][Grab] > &&
                
g_Targetindex[client][Grab] <= MaxClients &&
                
IsClientInGame(g_Targetindex[client][Grab]))
            {
                
g_Grabbed[g_Targetindex[client][Grab]] = false// Tell plugin the target is no longer being grabbed
                
SetEntPropFloat(g_Targetindex[client][Grab], Prop_Send"m_flMaxspeed"g_MaxSpeed[client]); // Set speed back to normal
            
}
            
g_Targetindex[client][Grab] = -1;
        }
        else
            
PrintCenterText(client"%t""Not Found");
    }

If you know how to make it works, like when admin is in death cam, he will grab somebody and when he drop bind button, player will drop too, or grab will be removed.
I will be happy if you help me with this, thanks.
Attached Files
File Type: sp Get Plugin or Get Source (hookgrabrope.sp - 121 views - 71.7 KB)

Last edited by Javierko; 12-03-2017 at 07:29. Reason: solved
Javierko is offline
Reiko1231
Member
Join Date: Apr 2013
Location: Russia
Old 12-01-2017 , 11:55   Re: Grab wtf?
Reply With Quote #2

Grab command is working as "press\release" because it has two commands with "+" and "-" before command name. When you press binded key, server execute "+command". When you release key, server execute "-command". Based on attached file, you've removed IsPlayerAlive check in "+command", but forgot to remove from "-command".
Code:
public Action:DropCmd(client, args)
{
	if(IsPlayerAlive(client)) // this check is failed for dead player so he can't release grab.
		Action_Drop(client);
	return Plugin_Handled;
}
Reiko1231 is offline
Javierko
AlliedModders Donor
Join Date: Sep 2017
Location: Czech republic
Old 12-03-2017 , 07:28   Re: Grab wtf?
Reply With Quote #3

Thanks, solved..
Javierko 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 17:04.


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