Thread: [Solved] L4D2 Admin Only
View Single Post
Author Message
ricksfishin
Senior Member
Join Date: Oct 2017
Old 04-25-2018 , 09:49   L4D2 Admin Only
Reply With Quote #1

Help to make this plugin admin only.
PHP Code:
/* Plugin Template generated by Pawn Studio */

#include <sourcemod>
#include <sdktools>
#include <sdktools_functions> 
 
#define SOUND_GRAB        "UI/helpful_event_1.wav"
new g_iVelocity ;
public 
Plugin:myinfo 
{
    
name "Push And Drag",
    
author "Pan Xiaohai",
    
description "<- Description ->",
    
version "1.1",
    
url "<- URL ->"
}

public 
OnPluginStart()
{    
    
g_iVelocity FindSendPropOffs("CBasePlayer""m_vecVelocity[0]");
}
new 
Float:lasttime;
new 
Float:ShoveTime[MAXPLAYERS+1];
new 
KeyBuffer[MAXPLAYERS+1];
new 
KeyState[MAXPLAYERS+1];
new 
GrabedEnt[MAXPLAYERS+1];
new 
Float:GrabEnerge[MAXPLAYERS+1];
new 
Float:KeyTime[MAXPLAYERS+1];
new 
Float:HoldDistance[MAXPLAYERS+1];
public 
OnMapStart()
{
    
PrecacheSound(SOUND_GRABtrue);
}
public 
OnGameFrame()
{
    new 
Float:currenttime=GetEngineTime();
    new 
Float:duration=currenttime-lasttime;
    if(
duration<0.0 || duration>1.0)duration=0.0;
      for(new 
client 1client <= MaxClientsclient++)
    {
        if(
IsClientInGame(client) && IsPlayerAlive(client) && !IsFakeClient(client))
        {
            if(
GetClientTeam(client)==&& IsPlayerGhost(client))
            {
                
GrabedEnt[client]=0;
            }
            else 
            {
                Do(
clientcurrenttimeduration);
            }
        }
        else
        {
            
GrabedEnt[client]=0;
        }
    }
    
lasttime=currenttime;
}
Do(
client Float:ctimeFloat:duration)
{
    
    new 
button=GetClientButtons(client);
    new 
bool:startgrab=false;
     if(
KeyState[client]==0)
    {
        if((
button IN_USE) && !(KeyBuffer[client] & IN_USE))
        {         
            
KeyState[client]=1;
            
KeyTime[client]=ctime;
            
//PrintToChat(client, "state 1"); 
        
}
    } 
    if(
KeyState[client]==1)
    {
        if(
ctime-KeyTime[client]<0.3)
        {
            if(!(
button IN_USE) && (KeyBuffer[client] & IN_USE))
            {
                
KeyState[client]=2;
                
//PrintToChat(client, "state 2");
            
}
        }
        else
        {
            
KeyState[client]=0;
        }
         
    } 
    if(
KeyState[client]==2)
    {
        if(
ctime-KeyTime[client]<0.3)
        {
            if((
button IN_USE) && !(KeyBuffer[client] & IN_USE))
            {                
                
KeyState[client]=3;
                
startgrab=true;
                 
//PrintToChat(client, "state 3");
            
}
        }
        else
        {
            
KeyState[client]=0;
        }
    }
    if(
KeyState[client]==&& !(button IN_USE))
    {
        
KeyState[client]=0;
        
//PrintToChat(client, "state 0");
    
}
    new 
bool:grabed=false;
    if(
GrabedEnt[client]>&& IsValidEdict(GrabedEnt[client]))grabed=true;
    if(
KeyState[client]==&& grabed )
    {    
        if((
button IN_ATTACK2))ThrowEnt(clientGrabedEnt[client], ctime2000.0);
        else 
ThrowEnt(clientGrabedEnt[client], ctime100.0);
        
KeyState[client]=0;
        
GrabedEnt[client]=0;
        
grabed=false;
    }
     
    
KeyBuffer[client]=button;
 
    if (
startgrab
    {
        
GrabedEnt[client]=GetEnt(clientctime);
        if(
GrabedEnt[client]>0)
        {
            
grabed=true;
            
decl Float:vOrigin[3];
            
GetClientEyePosition(client,vOrigin);
            
EmitSoundToAll(SOUND_GRAB0SNDCHAN_WEAPONSNDLEVEL_TRAFFICSND_NOFLAGSSNDVOL_NORMAL100_vOriginNULL_VECTORfalse0.0);    
        }
    }
    if(
grabed)
    {
        new 
bool:throw=false;
        if(
button IN_ATTACK)
        {
            throw=
true;
        }
        
        if(throw)
        {    
            
ThrowEnt(clientGrabedEnt[client], ctime2000.0);
            
GrabedEnt[client]=0;
        }
        else
        {
            
GrabEnt(clientGrabedEnt[client], duration);
            if(
GrabEnerge[client]<ctime)
            {
                
GrabedEnt[client]=0;
            }
        }
    }
    else
    {
        
GrabedEnt[client]=0;
    }
      
}
GrabEnt(cliententFloat:duration)
{
    
decl Float:vAngles[3];
    
decl Float:vOrigin[3];
    
decl Float:pos[3];
    
decl Float:velocity[3];
    
    
GetClientEyePosition(client,vOrigin);
    
GetClientEyeAngles(clientvAngles);
    
GetEntPropVector(entProp_Send"m_vecOrigin"pos);
    
GetEntDataVector(clientg_iVelocityvelocity);
    
    
ScaleVector(velocityduration*4.0);
    
AddVectors(vOriginvelocity ,vOrigin);

    
GetAngleVectors(vAnglesvAnglesNULL_VECTORNULL_VECTOR);
    
NormalizeVector(vAnglesvAngles);
    
ScaleVector(vAnglesHoldDistance[client]);
    
AddVectors(vOriginvAnglesvOrigin);
    new 
Float:dis=GetVectorDistance(vOriginpos);
    new 
Float:force=0.0;        
    if(
dis>100.0)dis=100.0;
    
force=0.2*dis*dis;
    
//PrintToChatAll("%f, %f", dis, force);
    
SubtractVectors(vOriginposvelocity);
    
NormalizeVector(velocityvelocity);
    
ScaleVector(velocityforce);
    
TeleportEntity(entNULL_VECTORNULL_VECTORvelocity);

}
ThrowEnt(cliententFloat:ctimeFloat:force)
{    
    
//PrintToChat(client, "throw");
    
decl Float:vAngles[3];
    
decl Float:vOrigin[3];
    
decl Float:pos[3];
    
GetClientEyePosition(client,vOrigin);
    
GetClientEyeAngles(clientvAngles);
    
GetEntPropVector(entProp_Send"m_vecOrigin"pos);
    
    new 
Float:dis=GetVectorDistance(vOriginpos);
    if(
dis>1000.0)dis=1000.0;
    
force=force*(1000.0-dis)/1000.0+200.0;
    
//PrintToChatAll("%f %f",dis, force);
    
decl Float:volicity[3];
    
SubtractVectors(posvOriginvolicity);
    
NormalizeVector(volicityvolicity);
    
ScaleVector(volicityforce);
    
TeleportEntity(entNULL_VECTORNULL_VECTORvolicity);
    
    
decl String:classname[64];
    
GetEdictClassname(entclassname64);        
    if(
StrContains(classname"prop_")!=-1)
    {
        
SetEntPropEnt(entProp_Data"m_hPhysicsAttacker"client);
        
SetEntPropFloat(entProp_Data"m_flLastPhysicsInfluenceTime"ctime);
    }
}
GetEnt(clientFloat:ctime)
{
    new 
ent=0;
    
    
decl Float:vAngles[3];
    
decl Float:vOrigin[3];
    
decl Float:pos[3];

    
GetClientEyePosition(client,vOrigin);
    
GetClientEyeAngles(clientvAngles);

    new 
Handle:trace TR_TraceRayFilterEx(vOriginvAnglesMASK_SOLIDRayType_InfiniteTraceRayDontHitSelfclient);

    if(
TR_DidHit(trace))
    {
        
TR_GetEndPosition(postrace);
        
ent=TR_GetEntityIndex(trace);
        if(
ent>0)
        {
            new 
Float:dis=GetVectorDistance(vOriginpos);
            
            if(
dis<1000.0)
            {
                
decl String:classname[64];
                
GetEdictClassname(entclassname64);        
                if(
StrContains(classname"ladder")!=-1){ent=0;}
                else if(
StrContains(classname"door")!=-1){ent=0;}
                else if(
StrContains(classname"infected")!=-1){ent=0;}
                else 
                {             
                    
HoldDistance[client]=100.0;
                    
GrabEnerge[client]=ctime+10.0;
                    if(
StrContains(classname"prop_")!=-1)
                    {
                        
SetEntPropEnt(entProp_Data"m_hPhysicsAttacker"client);
                        
SetEntPropFloat(entProp_Data"m_flLastPhysicsInfluenceTime"ctime);
                        
//PrintToChatAll("You grabbed a prop");
                        
HoldDistance[client]=120.0;
                        
GrabEnerge[client]=ctime+15.0;                        
                    }
                    if(
StrContains(classname"car")!=-1)
                    {
                        
HoldDistance[client]=200.0;
                        
GrabEnerge[client]=ctime+10.0;        
                        
//PrintToChatAll("You grabbed a car");
                    
}
                    if(
StrContains(classname"weapon_")!=-1)
                    {
                        
HoldDistance[client]=50.0;
                        
GrabEnerge[client]=ctime+30.0;
                        
//PrintToChatAll("You grabbed a weapon");
                    
}
                    if(
StrContains(classname"player")!=-1)
                    {
                        
HoldDistance[client]=70.0;
                        
GrabEnerge[client]=ctime+15.0;
                        
//PrintToChatAll("You grabbed a player");
                    
}

                    if(
ent<=MaxClients)    
                    {
                        if(
GetClientTeam(client)==GetClientTeam(ent))
                        {
                            
PrintHintText(client"You grabbed %N"ent);
                            
PrintHintText(ent"%N grabbed you"client);                            
                        }
                        else
                        {
                            
PrintHintText(client"You can not grab emney!");
                            
ent=0;
                        }
                    }
                    else
                    {
                        
PrintHintText(client"You grabbed something!");
                    }
                    
                }
            }
            else
            {
                
ent=0;
                
PrintHintText(client"It is too far");
            }
        }
        else
        {
            
PrintHintText(client"You grabbed nothing!");
        }
    }
    
CloseHandle(trace)
    
    return 
ent;
}
bool:IsPlayerGhost (client)
{
    if (
GetEntData(clientFindSendPropInfo("CTerrorPlayer""m_isGhost"), 1))
        return 
true;
    return 
false;
}
public 
bool:TraceRayDontHitSelf(entitymaskany:data)
{
    if(
entity == data
    {
        return 
false
    }
    return 
true;


Last edited by ricksfishin; 04-26-2018 at 09:10.
ricksfishin is offline