AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Some script help (https://forums.alliedmods.net/showthread.php?t=6816)

ancient1 10-15-2004 06:00

Some script help
 
Hello guys, I'm trying to modify a plugin origonally written by AsskicR for CS to work on a TFC server, I have removed the CS specific code from the plugin and kept just what I want, but I am having a few probs...

Here's the code I have got so far,

Code:

/**************************************************************************************************
TFC admin all in one commands
Shamelessly stolen code from AsskicR KZ plugin [Hope you dont mind mate ;)]

**** CVARS (OTHER) ****
grabforce = Grabforce for JediGrab

**** ADMIN COMMANDS ****

ADMIN_LEVEL_A (flag="m")
Setting Noclip      = amx_noclip <authid, nick, @team, @all or #userid> <on/off>
Setting Godmode    = amx_godmode <authid, nick, @team, @all or #userid> <on/off>
Setting Glow            = amx_glow <authid, nick, @team, @all or #userid> <red> <green> <blue> <alpha>


ADMIN_LEVEL_D (flag="p")
Jedi Force Grab by Spacedude (slightly modified)
Grabbing a person  = +grab
Releasing grabbed  = -grab
Toggle Command      = grab_toggle

ADMIN_LEVEL_E (flag="q")
Ninja Rope by Spacedude (slightly modified) & Hook thingy
Attaching Rope      = +rope
Deattaching Rope    = -rope
Attaching Hook      = +hook
Deattaching Hook    = -hook

**************************************************************************************************/
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <engine>


#define MOVEACCELERATION 150        // units per second^2
#define REELSPEED 300                        // units per second

#define IN_JUMP                        (1 << 1)
#define IN_DUCK                        (1 << 2)
#define IN_FORWARD                (1 << 3)
#define IN_BACK                        (1 << 4)
#define IN_MOVELEFT                (1 << 9)
#define IN_MOVERIGHT        (1 << 10)

#define        SOLID_NOT                0                /* no interaction with other objects */
#define        SOLID_BBOX                2                /* touch on edge, block */

/* Hook Stuff */
new gHookLocation[33][3]
new gHookLenght[33]
new bool:gIsHooked[33]
new Float:gBeamIsCreated[33]
new global_gravity
new beam


/************************************************************************************************************************/
public plugin_init() //Called on plugin start
{
        // Plugin Info
        register_plugin("Adminallinone","1.0","Ancient")
        //CVARS
       
        register_cvar("grabforce","8")
       
                //ADMIN CMDS
                register_clcmd("+rope", "hook_on",ADMIN_LEVEL_E)
                register_clcmd("-rope", "hook_off",ADMIN_LEVEL_E)
                register_clcmd("+hook", "hook_on",ADMIN_LEVEL_E)
                register_clcmd("-hook", "hook_off",ADMIN_LEVEL_E)
                register_clcmd("grab_toggle","grab_toggle",ADMIN_LEVEL_D,"press once to grab and again to release")
                register_clcmd("+grab","grab",ADMIN_LEVEL_D,"bind a key to +grab")
                register_clcmd("-grab","release",ADMIN_LEVEL_D)
                register_concmd("amx_noclip","AdminNoclip",ADMIN_LEVEL_A,"<authid, nick, @team, @all or #userid> <on/off>")
                register_concmd("amx_godmode","AdminGodMode",ADMIN_LEVEL_A,"<authid, nick, @team, @all or #userid> <on/off>")
                register_concmd("amx_glow","AdminGlow",ADMIN_LEVEL_A,"<authid, nick, @team or #userid> <red> <green> <blue> <alpha>")       


}
/************************************************************************************************************************/
/**************************************************** ADMIN COMMANDS ****************************************************/
/************************************************************************************************************************/




public AdminNoclip(id,level,cid)
{
        if ( !cmd_access(id,level,cid,3) )
          return PLUGIN_HANDLED

        new arg1[32],arg2[32]
        read_argv(1,arg1,31)
        read_argv(2,arg2,31)
        new onoff = str_to_num(arg2)

        if ( equali(arg1,"@all") )
        {
          new plist[32],pnum
          get_players(plist,pnum,"a")
          if (pnum==0)
          {
                console_print(id,"[AMXX] There are no clients")
                return PLUGIN_HANDLED
          }
          for (new i=0; i<pnum; i++)
          {
                        set_user_noclip(plist[i],onoff)
                        CheatDetect(plist[i],"NoClip")
          }

          console_print(id,"[AMXX] Set Noclip on everyone")
        }
        else if ( arg1[0]=='@' )
        {
          new plist[32],pnum
          get_players(plist,pnum,"ae",arg1[1])
          if ( pnum==0 )
          {
                console_print(id,"[AMXX] No clients in such team")
                return PLUGIN_HANDLED
          }
          for (new i=0; i<pnum; i++)
          {
                        set_user_noclip(plist[i],onoff)
                        CheatDetect(plist[i],"NoClip")
          }
          console_print(id,"[AMXX] Set noclip on all %ss",arg1[1])
        }
        else
        {
          new pName[32]
          new player = cmd_target(id,arg1,6)
          if (!player) return PLUGIN_HANDLED
          set_user_noclip(player,onoff)
          CheatDetect(player,"NoClip")
          get_user_name(player,pName,31)
          console_print(id,"[AMXX] Set noclip on ^"%s^"",pName)
        }

        return PLUGIN_HANDLED
}



public AdminGodMode(id,level,cid)
{
        if ( !cmd_access(id,level,cid,3) )
          return PLUGIN_HANDLED

        new arg1[32],arg2[32]
        read_argv(1,arg1,31)
        read_argv(2,arg2,31)
        new onoff = str_to_num(arg2)

        if ( equali(arg1,"@all") )
        {
          new plist[32],pnum
          get_players(plist,pnum,"a")
          if (pnum==0)
          {
                console_print(id,"[AMXX] There are no clients")
                return PLUGIN_HANDLED
          }
          for (new i=0; i<pnum; i++)
                        set_user_godmode(plist[i],onoff)

          console_print(id,"[AMXX] Set Godmode on everyone")
        }
        else if ( arg1[0]=='@' )
        {
          new plist[32],pnum
          get_players(plist,pnum,"ae",arg1[1])
          if ( pnum==0 )
          {
                console_print(id,"[AMXX] No clients in such team")
                return PLUGIN_HANDLED
          }
          for (new i=0; i<pnum; i++)
                        set_user_godmode(plist[i],onoff)
          console_print(id,"[AMXX] Set Godmode on all %ss",arg1[1])
        }
        else
        {
          new pName[32]
          new player = cmd_target(id,arg1,6)
          if (!player) return PLUGIN_HANDLED
          set_user_godmode(player,onoff)
          get_user_name(player,pName,31)
          console_print(id,"[AMXX] Set Godmode on ^"%s^"",pName)
        }

        return PLUGIN_HANDLED
}

public AdminGlow(id,level,cid)
{
        if ( !cmd_access(id,level,cid,5) )
          return PLUGIN_HANDLED

        new arg1[32], sred[8], sgreen[8], sblue[8], salpha[8], name2[32]
        get_user_name(id,name2,31)
        read_argv(1,arg1,31)
        read_argv(2,sred,7)
        read_argv(3,sgreen,7)       
        read_argv(4,sblue,7)       
        read_argv(5,salpha,7)       
        new ired = str_to_num(sred)
        new igreen = str_to_num(sgreen)
        new iblue = str_to_num(sblue)
        new ialpha = str_to_num(salpha) 
        if ( equali(arg1,"@all") )
        {
          new plist[32],pnum
          get_players(plist,pnum,"a")
          if (pnum==0)
          {
                console_print(id,"[AMXX] There are no clients")
                return PLUGIN_HANDLED
          }
          for (new i=0; i<pnum; i++)
                        set_user_rendering(plist[i],kRenderFxGlowShell,ired,igreen,iblue,kRenderTransAlpha,ialpha)

          console_print(id,"[AMXX] Set Glow on everyone")
        }
        else if ( arg1[0]=='@' )
        {
          new plist[32],pnum
          get_players(plist,pnum,"ae",arg1[1])
          if ( pnum==0 )
          {
                console_print(id,"[AMXX] No clients in such team")
                return PLUGIN_HANDLED
          }
          for (new i=0; i<pnum; i++)
          set_user_rendering(plist[i],kRenderFxGlowShell,ired,igreen,iblue,kRenderTransAlpha,ialpha)
          console_print(id,"[AMXX] Set Glow on all %ss",arg1[1])
        }
        else
        {
          new pName[32]
          new player = cmd_target(id,arg1,6)
          if (!player) return PLUGIN_HANDLED
          set_user_rendering(player,kRenderFxGlowShell,ired,igreen,iblue,kRenderTransAlpha,ialpha)
          get_user_name(player,pName,31)
          console_print(id,"[AMXX] Set Glow on ^"%s^"",pName)
        }

        return PLUGIN_HANDLED
}



/************************************************************************************************************************/
/******************************************************* JEDIGRAB *******************************************************/
/************************************************************************************************************************/
new grabbed[33]
new grablength[33]
new bool:grabmodeon[33]
new velocity_multiplier

public grabtask(parm[])
{
        new id = parm[0]
        new targetid, body
        if (!grabbed[id])
        {
                get_user_aiming(id, targetid, body)
                if (targetid)
                {
                        set_grabbed(id, targetid)
                }
        }
        if (grabbed[id])
        {
                new origin[3], look[3], direction[3], moveto[3], grabbedorigin[3], velocity[3], length

                if (!is_user_alive(grabbed[id]))
                {
                        release(id)
                        return
                }

                get_user_origin(id, origin, 1)
                get_user_origin(id, look, 3)
                get_user_origin(grabbed[id], grabbedorigin)

                direction[0]=look[0]-origin[0]
                direction[1]=look[1]-origin[1]
                direction[2]=look[2]-origin[2]
                length = get_distance(look,origin)
                if (!length) length=1                                // avoid division by 0

                moveto[0]=origin[0]+direction[0]*grablength[id]/length
                moveto[1]=origin[1]+direction[1]*grablength[id]/length
                moveto[2]=origin[2]+direction[2]*grablength[id]/length

                velocity[0]=(moveto[0]-grabbedorigin[0])*velocity_multiplier
                velocity[1]=(moveto[1]-grabbedorigin[1])*velocity_multiplier
                velocity[2]=(moveto[2]-grabbedorigin[2])*velocity_multiplier

                set_user_velocity(grabbed[id], velocity)
        }
}

public grab_toggle(id)
{
        if (grabmodeon[id])
                release(id)
        else
                grab(id)
        return PLUGIN_HANDLED
}

public grab(id)
{
        if (!(get_user_flags(id)&ADMIN_LEVEL_D))
        {
                client_print(id,print_chat,"[AMXX] You have no access to that command")
                return PLUGIN_HANDLED
        }
        if (!grabmodeon[id])
        {
                new targetid, body
                new parm[1]
                parm[0] = id
                velocity_multiplier = get_cvar_num("grabforce")
                grabmodeon[id]=true
                set_task(0.1, "grabtask", 100+id, parm, 1, "b")
                get_user_aiming(id, targetid, body)
                if (targetid)
                {
                        set_grabbed(id, targetid)
                }
                else
                {
                        client_print(id,print_chat,"[AMXX] Searching for a target")
                }
        }
        return PLUGIN_HANDLED
}

public release(id)
{
        if (!(get_user_flags(id)&ADMIN_LEVEL_D))
        {
                client_print(id,print_chat,"[AMXX] You have no access to that command")
                return PLUGIN_HANDLED
        }
        if (grabmodeon[id])
        {
                grabmodeon[id]=false
                if (grabbed[id])
                {
                        new targname[32]
                        set_user_gravity(grabbed[id])
                        set_user_rendering(grabbed[id])
                        get_user_name(grabbed[id],targname,31)
                        client_print(id,print_chat,"[AMXX] You have released %s", targname)
                }
                else
                {
                        client_print(id,print_chat,"[AMXX] No target found")
                }
                grabbed[id]=0
                remove_task(100+id)
        }
        return PLUGIN_HANDLED
}

public spec_event(id)
{
        new targetid = read_data(2)

        if (targetid < 1 || targetid > 32)
                return PLUGIN_CONTINUE

        if (grabmodeon[id] && !grabbed[id])
        {
                set_grabbed(id, targetid)
        }
        return PLUGIN_CONTINUE
}

public set_grabbed(id, targetid)
{
        new origin1[3], origin2[3], targname[32]
        get_user_origin(id, origin1)
        get_user_origin(targetid, origin2)
        grabbed[id]=targetid
        grablength[id]=get_distance(origin1,origin2)
        set_user_gravity(targetid,0.001)
        set_user_rendering(targetid,kRenderFxGlowShell,50,0,0, kRenderNormal, 16)
        get_user_name(targetid,targname,31)
        client_print(id,print_chat,"[AMXX] You have grabbed onto %s", targname)
}

/************************************************************************************************************************/
/****************************************************** NINJAROPE *******************************************************/
/************************************************************************************************************************/

public ropetask(parm[])
{
        new id = parm[0]
        new user_origin[3], user_look[3], user_direction[3], move_direction[3]
        new A[3], D[3], buttonadjust[3]
        new acceleration, velocity_towards_A, desired_velocity_towards_A
        new velocity[3], null[3]

        if (!is_user_alive(id))
        {
                RopeRelease(id)
                return
        }

        if (gBeamIsCreated[id] + BEAMLIFE/10 <= get_gametime())
        {
                beamentpoint(id)
        }

        null[0] = 0
        null[1] = 0
        null[2] = 0

        get_user_origin(id, user_origin)
        get_user_origin(id, user_look,2)
        get_user_velocity(id, velocity)

        buttonadjust[0]=0
        buttonadjust[1]=0

        if (get_user_button(id)&IN_FORWARD)                buttonadjust[0]+=1
        if (get_user_button(id)&IN_BACK)                buttonadjust[0]-=1
        if (get_user_button(id)&IN_MOVERIGHT)        buttonadjust[1]+=1
        if (get_user_button(id)&IN_MOVELEFT)        buttonadjust[1]-=1
        if (get_user_button(id)&IN_JUMP)                buttonadjust[2]+=1
        if (get_user_button(id)&IN_DUCK)                buttonadjust[2]-=1

        if (buttonadjust[0] || buttonadjust[1])
        {
                user_direction[0] = user_look[0] - user_origin[0]
                user_direction[1] = user_look[1] - user_origin[1]

                move_direction[0] = buttonadjust[0]*user_direction[0] + user_direction[1]*buttonadjust[1]
                move_direction[1] = buttonadjust[0]*user_direction[1] - user_direction[0]*buttonadjust[1]
                move_direction[2] = 0

                velocity[0] += floatround(move_direction[0] * MOVEACCELERATION * DELTA_T / get_distance(null,move_direction))
                velocity[1] += floatround(move_direction[1] * MOVEACCELERATION * DELTA_T / get_distance(null,move_direction))
        }

        if (buttonadjust[2])        gHookLenght[id] -= floatround(buttonadjust[2] * REELSPEED * DELTA_T)
        if (gHookLenght[id] < 100) gHookLenght[id] = 100

        A[0] = gHookLocation[id][0] - user_origin[0]
        A[1] = gHookLocation[id][1] - user_origin[1]
        A[2] = gHookLocation[id][2] - user_origin[2]

        D[0] = A[0]*A[2] / get_distance(null,A)
        D[1] = A[1]*A[2] / get_distance(null,A)
        D[2] = -(A[1]*A[1] + A[0]*A[0]) / get_distance(null,A)

        acceleration = - global_gravity * D[2] / get_distance(null,D)

        velocity_towards_A = (velocity[0] * A[0] + velocity[1] * A[1] + velocity[2] * A[2]) / get_distance(null,A)
        desired_velocity_towards_A = (get_distance(user_origin,gHookLocation[id]) - gHookLenght[id] /*- 10*/) * 4

        if (get_distance(null,D)>10)
        {
                velocity[0] += floatround((acceleration * DELTA_T * D[0]) / get_distance(null,D))
                velocity[1] += floatround((acceleration * DELTA_T * D[1]) / get_distance(null,D))
                velocity[2] += floatround((acceleration * DELTA_T * D[2]) / get_distance(null,D))
        }

        velocity[0] += ((desired_velocity_towards_A - velocity_towards_A) * A[0]) / get_distance(null,A)
        velocity[1] += ((desired_velocity_towards_A - velocity_towards_A) * A[1]) / get_distance(null,A)
        velocity[2] += ((desired_velocity_towards_A - velocity_towards_A) * A[2]) / get_distance(null,A)

        set_user_velocity(id, velocity)
}

public hooktask(parm[])
{
        new id = parm[0]
        new velocity[3]

        if ( !gIsHooked[id] ) return
       
        new user_origin[3],oldvelocity[3]
        parm[0] = id

        if (!is_user_alive(id))
        {
                RopeRelease(id)
                return
        }

        if (gBeamIsCreated[id] + BEAMLIFE/10 <= get_gametime())
        {
                beamentpoint(id)
        }

        get_user_origin(id, user_origin)
        get_user_velocity(id, oldvelocity)
        new distance=get_distance( gHookLocation[id], user_origin )
        if ( distance > 10 )
        {
                velocity[0] = floatround( (gHookLocation[id][0] - user_origin[0]) * ( 2.0 * REELSPEED / distance ) )
                velocity[1] = floatround( (gHookLocation[id][1] - user_origin[1]) * ( 2.0 * REELSPEED / distance ) )
                velocity[2] = floatround( (gHookLocation[id][2] - user_origin[2]) * ( 2.0 * REELSPEED / distance ) )
        }
        else
        {
                velocity[0]=0
                velocity[1]=0
                velocity[2]=0
        }

        set_user_velocity(id, velocity)
       
}

public hook_on(id)
{
        if (!(get_user_flags(id)&ADMIN_LEVEL_E))
        {
                client_print(id,print_chat,"[AMXX] You have no access to that command")
                return PLUGIN_HANDLED
        }
        if (!gIsHooked[id] && is_user_alive(id))
        {
                new cmd[32]
                read_argv(0,cmd,31)
                if(equal(cmd,"+rope")) RopeAttach(id,0)
                if(equal(cmd,"+hook")) RopeAttach(id,1)
        }
        return PLUGIN_HANDLED
}

public hook_off(id)
{
        if (!(get_user_flags(id)&ADMIN_LEVEL_E))
        {
                client_print(id,print_chat,"[AMXX] You have no access to that command")
                return PLUGIN_HANDLED
        }
        if (gIsHooked[id])
        {
                RopeRelease(id)
        }
        return PLUGIN_HANDLED
}

public RopeAttach(id,hook)
{
        CheatDetect(id,"Hook/Rope")
        new parm[1], user_origin[3]
        parm[0] = id
        gIsHooked[id] = true
        get_user_origin(id,user_origin)
        get_user_origin(id,gHookLocation[id], 3)
        gHookLenght[id] = get_distance(gHookLocation[id],user_origin)
        global_gravity = get_cvar_num("sv_gravity")
        set_user_gravity(id,0.001)
        beamentpoint(id)
        emit_sound(id, CHAN_STATIC, "weapons/xbow_hit2.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
        if (hook) set_task(DELTA_T, "hooktask", 200+id, parm, 1, "b")
        else set_task(DELTA_T, "ropetask", 200+id, parm, 1, "b")
}

public RopeRelease(id)
{
        gIsHooked[id] = false
        killbeam(id)
        set_user_gravity(id)
        remove_task(200+id)
}

It is not compiling correctly, I have probably done something stupid or removed a important function, but I am muddling on :?

Any help is greatly appreciated, thankyou :)

Ancient

Da Bishop 10-15-2004 06:10

Is there an include to this because there is a lot of undefined variables... would kinda help just a little if i had the include.

ancient1 10-15-2004 08:00

There is nothing in the download, the origonal code can be found HERE


I'm a relative total nub, but I can understand the code and how it works, I just don't follow the syntax very well, thanks :)

Ancient

twistedeuphoria 10-15-2004 12:06

Me thinks you deleted too much...here this one compiles...(without cstrike of course)

ancient1 10-15-2004 13:24

Thanks Twisted, but there is still loads of code in it thats not of use.

I only wanted the Godmode/noclip/grab and ninja rope functionality

All the other cvars are still registered etc, so using one will crash the server wont it??

Ancient

twistedeuphoria 10-15-2004 13:40

Quote:

All the other cvars are still registered etc, so using one will crash the server wont it??
Huh?

Quote:

I only wanted the Godmode/noclip/grab and ninja rope functionality
:P Then why did you start with this plugin and not an admin all in one one?


All times are GMT -4. The time now is 17:21.

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