Raised This Month: $ Target: $400
 0% 

Making a public pluging admin only..


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lancir
Member
Join Date: Feb 2010
Old 10-20-2010 , 11:57   Making a public pluging admin only..
Reply With Quote #1

I am trying to take the Grabber:SM plugin and make it so it is admin only but i am having some trouble doing so. I am a noob to scripting and this is my first attempt at trying.


PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.0.0.3"

#define MAX_PLAYERS 64


// globals
new gObj[MAXPLAYERS+1];         // how many tripmines player has this spawn
new Float:gThrow[MAXPLAYERS+1]; // throw charge state 
new Handle:gTimer;       
new 
String:gSound[256];

// convars
new Handle:cvSpeed INVALID_HANDLE;
new 
Handle:cvDistance INVALID_HANDLE
new 
Handle:cvTeamRestrict INVALID_HANDLE;
new 
Handle:cvSound INVALID_HANDLE;
new 
Handle:cvGround INVALID_HANDLE;
new 
Handle:cvThrowTime INVALID_HANDLE;
new 
Handle:cvThrowSpeed INVALID_HANDLE;
new 
Handle:cvMaxDistance INVALID_HANDLE;
new 
Handle:cvSteal INVALID_HANDLE;
new 
Handle:cvDropOnJump INVALID_HANDLE;


public 
Plugin:myinfo = {
    
name "Grabber:SM",
    
author "L. Duke Edited by LaNcIr",
    
description "grabber (gravgun)",
    
version PLUGIN_VERSION,
    
url "http://www.lduke.com/"
};


public 
OnPluginStart() 
{
    
// events
    
HookEvent("player_death"PlayerDeath);
    
HookEvent("player_spawn",PlayerSpawn);
    
    
// convars
    
CreateConVar("sm_grabber_version"PLUGIN_VERSION"Grabber:SM Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
cvSpeed CreateConVar("sm_grabber_speed""10.0");
    
cvDistance CreateConVar("sm_grabber_distance""64.0");
    
cvTeamRestrict CreateConVar("sm_grabber_team_restrict""0""team restriction (0=all use, 2 or 3 to restrict that team");
    
cvSound CreateConVar("sm_grabber_sound""weapons/physcannon/hold_loop.wav""sound to play, change takes effect on map change");
    
cvGround CreateConVar("sm_grabber_groundmode""0""ground mode (soccer) 0=off 1=on");
    
cvThrowTime CreateConVar("sm_grabber_throwtime""2.0""time to charge up to full throw speed");
    
cvThrowSpeed CreateConVar("sm_grabber_throwspeed""1000.0""speed at which an object is thrown");
    
cvMaxDistance CreateConVar("sm_grabber_maxdistance""512.0""maximum distance from which you can grab an object");
    
cvSteal CreateConVar("sm_grabber_steal""1""can objects be 'stolen' from other players (0=no 1=yes)");
    
cvDropOnJump CreateConVar("sm_grabber_droponjump""1""drop objects when jumping (prevents player from flying around level on large objects) (0=no 1=yes)");
    
    
// commands
    
RegadminCmd("+grab"Command_Grab ADMFLAG_CUSTOM6);
    
RegadminCmd("-grab"Command_UnGrab2 ADMFLAG_CUSTOM6);
    
RegAdminCmd("+throw"Command_Throw ADMFLAG_CUSTOM6);
    
RegAdminCmd("-throw"Command_UnThrow ADMFLAG_CUSTOM6);
}

public 
OnEventShutdown(){
    
UnhookEvent("player_death"PlayerDeath);
    
UnhookEvent("player_spawn",PlayerSpawn);
}

public 
OnMapStart()

    
// reset object list
    
new i;
    for (
i=0i<=MAX_PLAYERSi++)
    {
        
gObj[i]=-1;
        
gThrow[i]=0.0;
    }
    
    
// start timer
    
gTimer CreateTimer(0.1UpdateObjectsINVALID_HANDLETIMER_REPEAT);
    
    
// precache sounds
    
GetConVarString(cvSoundgSoundsizeof(gSound));
    
PrecacheSound(gSoundtrue);
}

public 
OnMapEnd()
{
    
CloseHandle(gTimer);
}

// When a new client is put in the server we reset their status
public OnClientPutInServer(client){
    if(
client && !IsFakeClient(client))
    {
        
gThrow[client]=0.0;
        
gObj[client] = -1;
    }
}

public 
OnClientDisconnect(client)
{
    if (
gObj[client]>0)
        
Command_UnGrab(client0);
}

public 
Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client;
    
client GetClientOfUserId(GetEventInt(event"userid"));
    
// reset object held
    
gThrow[client]=0.0;
    
gObj[client] = -1;
    
StopSound(clientSNDCHAN_AUTOgSound);
    return 
Plugin_Continue;
}

public 
Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast){
    new 
client;
    
client GetClientOfUserId(GetEventInt(event"userid"));
    
// reset object held
    
gThrow[client]=0.0;
    
gObj[client] = -1;
    
StopSound(clientSNDCHAN_AUTOgSound);
    return 
Plugin_Continue;
}

public 
Action:Command_Grab(clientargs)
{  
    
    
// if an object is being held, go to UnGrab
    
if (gObj[client]>0)
        return 
Command_UnGrab(clientargs);
    
    
// make sure client is not spectating
    
if (!IsPlayerAlive(client))
        return 
Plugin_Handled;
    
    
// check team restrictions
    
new restrict GetConVarInt(cvTeamRestrict);
    if (
restrict>0)
    {
        if (
restrict==GetClientTeam(client))
        {
            return 
Plugin_Handled;
        }
    }
    
    
// find entity
    
new ent TraceToEntity(client);
    if (
ent==-1)
        return 
Plugin_Handled;
    
    
// only grab physics entities
    
new String:edictname[128];
    
GetEdictClassname(entedictname128);
    if (
strncmp("prop_"edictname5false)==0)
    {
        
// check if another player is holding it
        
new j;
        for (
j=1j<=MAX_PLAYERSj++)
        {
            if (
gObj[j]==ent)
            {
                if (
GetConVarInt(cvSteal)==1)
                {
                    
// steal from other player
                    
Command_UnGrab(jargs);
                }
                else
                {
                    
// already being held - stealing not allowed
                    
return Plugin_Handled;
                }
            }
        }
        
        
// grab entity
        
gObj[client] = ent;
        
gThrow[client] = 0.0;
        if (
GetConVarInt(cvGround)!=1)
        {
            
EmitSoundToAll(gSoundclient);   // no sound in ground mode
        
}
    }
    
    return 
Plugin_Handled;
}

public 
Action:Command_UnGrab(clientargs)
{  
    
// make sure client is not spectating
    
if (!IsPlayerAlive(client))
        return 
Plugin_Handled;
    
    if (
GetConVarInt(cvGround)!=1)
    {
        
StopSound(clientSNDCHAN_AUTOgSound);  // no sound in ground mode
    
}
    
    if (
gThrow[client]>0.0)
        
PrintHintText(client"");
    
    
gThrow[client] = 0.0;
    
gObj[client] = -1;
    
    return 
Plugin_Handled;
}

public 
Action:Command_Throw(clientargs)
{
    
// make sure client is not spectating
    
if (!IsPlayerAlive(client))
        return 
Plugin_Handled;
    
// has an object?
    
if (gObj[client]<1)
        return 
Plugin_Handled;
    
    
// start throw timer
    
gThrow[client] = GetEngineTime();
    
    return 
Plugin_Handled;
}

public 
Action:Command_UnGrab2(clientargs)
{
    
// changed so Commmand_Ungrab is called from Command_Grab if an object is already held
    // so we need to handle -grab with this function
    
return Plugin_Handled;
}

public 
Action:Command_UnThrow(clientargs)
{
    
// make sure client is not spectating
    
if (!IsPlayerAlive(client))
        return 
Plugin_Handled;
    
// has an object?
    
if (gObj[client]<1)
        return 
Plugin_Handled;
    
    
    
// throw object
    
new Float:throwtime GetConVarFloat(cvThrowTime);
    new 
Float:throwspeed GetConVarFloat(cvThrowSpeed);
    new 
Float:time GetEngineTime();
    new 
Float:percent;
    
    
time=time-gThrow[client];
    if (
time>throwtime)
    {
        
percent 1.0;
    }
    else
    {
        
percent time/throwtime;
    }
    
throwspeed*=percent;
    
    new 
Float:start[3];
    
GetClientEyePosition(clientstart);
    new 
Float:angle[3];
    new 
Float:speed[3];
    
GetClientEyeAngles(clientangle);
    
GetAngleVectors(anglespeedNULL_VECTORNULL_VECTOR);
    
speed[0]*=throwspeedspeed[1]*=throwspeedspeed[2]*=throwspeed;
    
    
TeleportEntity(gObj[client], NULL_VECTORNULL_VECTORspeed);
    
    
// cleanup
    
Command_UnGrab(clientargs);
    
PrintHintText(client"");  
    
    return 
Plugin_Handled;
}


public 
Action:UpdateObjects(Handle:timer)

{
    new 
Float:vecDir[3], Float:vecPos[3], Float:vecVel[3];      // vectors
    
new Float:viewang[3];                                       // angles
    
new i;
    new 
Float:speed GetConVarFloat(cvSpeed);
    new 
Float:distance GetConVarFloat(cvDistance);
    new 
groundmode GetConVarInt(cvGround);
    new 
Float:throwtime GetConVarFloat(cvThrowTime);
    new 
Float:time GetEngineTime();
    new 
bool:DropInJump false;
    for (
i=0i<=MAX_PLAYERSi++)
    {
        if (
gObj[i]>0)
        {
            if (
GetConVarBool(cvDropOnJump))
            {
                
DropInJump GetClientButtons(i) & IN_JUMP true false;
            }
            if (
IsValidEdict(gObj[i]) && IsValidEntity(gObj[i]) && !DropInJump )
            {
                
// get client info
                
GetClientEyeAngles(iviewang);
                
GetAngleVectors(viewangvecDirNULL_VECTORNULL_VECTOR);
                if (
groundmode==1)
                {
                    
GetClientAbsOrigin(ivecPos);
                }
                else
                {
                    
GetClientEyePosition(ivecPos);
                }
                
                
// update object 
                
vecPos[0]+=vecDir[0]*distance;
                
vecPos[1]+=vecDir[1]*distance;
                if (
groundmode!=1)
                {
                    
vecPos[2]+=vecDir[2]*distance;    // don't change up/down in ground mode
                
}
                
                
GetEntPropVector(gObj[i], Prop_Send"m_vecOrigin"vecDir);
                
                
SubtractVectors(vecPosvecDirvecVel);
                
                
ScaleVector(vecVelspeed);
                if (
groundmode==1)
                {
                    
vecVel[2]=0.0;
                }
                
TeleportEntity(gObj[i], NULL_VECTORNULL_VECTORvecVel);
                
                
// update throw time
                
if (gThrow[i]>0.0)
                {
                    
ShowBar(itime-gThrow[i], throwtime);
                }
                
            }
            else
            {
                
gObj[i]=-1;
            }
            
        }
    }
    
    return 
Plugin_Continue;
}















public 
TraceToEntity(client)
{
    new 
Float:vecClientEyePos[3], Float:vecClientEyeAng[3];
    
GetClientEyePosition(clientvecClientEyePos); // Get the position of the player's eyes
    
GetClientEyeAngles(clientvecClientEyeAng); // Get the angle the player is looking    
    
    //Check for colliding entities
    
TR_TraceRayFilter(vecClientEyePosvecClientEyeAngMASK_SOLIDRayType_InfiniteTraceRayDontHitSelfclient);
    
    if (
TR_DidHit(INVALID_HANDLE))
    {
        new 
TRIndex TR_GetEntityIndex(INVALID_HANDLE);
        
        
// check max distance
        
new Float:pos[3];
        
GetEntPropVector(TRIndexProp_Send"m_vecOrigin"pos);
        if (
GetVectorDistance(vecClientEyePospos)>GetConVarFloat(cvMaxDistance))
        {
            return -
1;
        }
        else
        {
            return 
TRIndex;
        }
    }
    
    return -
1;
}

public 
bool:TraceRayDontHitSelf(entitymaskany:data)
{
    if(
entity == data// Check if the TraceRay hit the itself.
    
{
        return 
false// Don't let the entity be hit
    
}
    return 
true// It didn't hit itself
}


// show a progres bar via hint text
ShowBar(clientFloat:curTimeFloat:totTime)
{
    new 
i;
    new 
String:output[128];
    
    if (
curTime>totTime)
    {
        
Format(outputsizeof(output), "[XXXXXXXXXXXXXXXXXXXX]");
    }
    else
    {
        new 
Float:fl 1.0;
        
output[0]='[';
        for (
i=1;i<21;i++)
        {
            if (
fl/20.0 curTime/totTime)
            {
                
output[i]='-';
            }
            else
            {
                
output[i]='X';
            }
            
fl+=1.0;
        }
        
output[21]=']';
        
output[22]='\0';
    }
    
    
PrintHintText(clientoutput);

PHP Code:
SourcePawn Compiler 1.3.5
Copyright 
(c1997-2006ITB CompuPhase, (C)2004-2008 AlliedModdersLLC

/groups/sourcemod/upload_tmp/textfuwJMT.sp(59) : error 017undefined symbol "RegadminCmd"
/groups/sourcemod/upload_tmp/textfuwJMT.sp(60) : error 017undefined symbol "RegadminCmd"

2 Errors
EDIT:sorry for the mispelled title and i just realized i might of posted this in the wrong section...im sorry if i did.
lancir is offline
nnajko
Senior Member
Join Date: May 2009
Location: Sweden
Old 10-20-2010 , 11:59   Re: Making a public pluging admin only..
Reply With Quote #2

Wrong forum, go to source mod
nnajko 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 10:23.


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