AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Removing grappling hook (https://forums.alliedmods.net/showthread.php?t=88456)

Mini_Midget 03-25-2009 01:01

Removing grappling hook
 
I've made my own grappling hook which pulls people towards me. I'm just having problems removing the hook once the person is right next to me or touches me when they are still hooked...

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <cstrike>

new model[] =  "models/crossbow_bolt.mdl"
new sprite
new boolg_hooked[33]

public 
plugin_init() 
{
    
register_plugin("Hook grab","1.0","Mazza")
    
    
register_forward(FM_Touch"fw_Touch")
}

public 
client_putinserver(id)
{
    
g_hooked[id] = false
}

public 
plugin_precache()
{
    
engfunc(EngFunc_PrecacheModelmodel);
    
sprite precache_model("sprites/zbeam4.spr");
}

public 
client_impulse(idimpulse)
{        
    if(
impulse == 100)
    {
        
create_hook(id)
        return 
PLUGIN_HANDLED_MAIN
    
}

    return 
PLUGIN_CONTINUE
}

public 
create_hook(id)
{
    if (!
is_user_alive(id))
        return

    static 
FloatOrigin[3], FloatVelocity[3], MinBox[3], MaxBox[3]
    
pev(idpev_originOrigin)
    
pev(idpev_velocityVelocity)

    static 
ent ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"))
        
    
set_pev(entpev_classname"ent")
    
engfunc(EngFunc_SetModelentmodel)
    
MinBox = { -1.900000, -0.140000, -1.910000 }
    
MaxBox = { 1.90000025.0000001.910000 }
    
    
engfunc(EngFunc_SetSizeentMinBoxMaxBox)
    
engfunc(EngFunc_SetOriginentOrigin)
    
set_pev(entpev_movetypeMOVETYPE_FLY)
    
set_pev(entpev_solidSOLID_TRIGGER)
    
set_pev(entpev_ownerid)
    
    
velocity_by_aim(id1500Velocity)
    
set_pev(entpev_velocityVelocity)
    
    
// Create a beam between two entities
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
    
write_byte(TE_BEAMENTS)
    
write_short(id 0x1000)
    
write_short(ent)
    
write_short(sprite)    // sprite index
    
write_byte(0)        // start frame
    
write_byte(0)        // framerate
    
write_byte(200)    // life
    
write_byte(7)        // width
    
write_byte(1)        // noise
    
write_byte(50)    // r, g, b
    
write_byte(50)    // r, g, b
    
write_byte(50)        // r, g, b
    
write_byte(100)    // brightness
    
write_byte(10)        // speed
    
message_end()
}

public 
fw_Touch(pToucherpTouched)
{
    if ( 
pev_valid(pToucher))
    {
        static 
className[32], className2[32], attacker
        pev
(pToucherpev_classnameclassName31)
        if ( 
pev_valid(pTouched)) pev(pTouchedpev_classnameclassName231)
        
attacker pev(pToucherpev_owner)
        
        if ( 
equal(className"ent"))
        {            
            if ( 
pev_valid(pTouched))
            {
                if ( 
equal(className2"player") && is_user_connected(pTouched))
                {
                    static 
Float:fl_Velocity[3]
                    static 
attacker_origin[3], victim_origin[3]
                    
get_user_origin(attackerattacker_origin)
                    
get_user_origin(pTouchedvictim_origin)
                    
                    static 
CsTeams:team[2]
                    
team[0] = cs_get_user_team(pTouched), team[1] = cs_get_user_team(attacker)
                    
                    if (
attacker == pTouched)
                        return 
FMRES_SUPERCEDE
                    
                    
if (!get_cvar_num("mp_friendlyfire") && team[0] == team[1]) 
                        return 
FMRES_SUPERCEDE
                        
                    set_pev
(pToucherpev_aimentpTouched)
                    
set_pev(pToucherpev_movetypeMOVETYPE_FOLLOW)
                    
                    
g_hooked[pTouched] = true
                        
                    
static distance 
                    distance 
get_distance(attacker_originvictim_origin)

                    if ( 
distance 
                    {
                        new 
Float:fl_Time distance 2000.0

                        fl_Velocity
[0] = (attacker_origin[0] - victim_origin[0]) / fl_Time
                        fl_Velocity
[1] = (attacker_origin[1] - victim_origin[1]) / fl_Time
                        fl_Velocity
[2] = (attacker_origin[2] - victim_origin[2]) / fl_Time
                    
}
                    else 
                    {
                        
fl_Velocity[0] = 0.0
                        fl_Velocity
[1] = 0.0
                        fl_Velocity
[2] = 0.0
                    
}

                    
set_pev(pTouchedpev_velocityfl_Velocity)
                }
                else
                    
remove_hook(pToucher)
            }
            else
                
remove_hook(pToucher)
        }
        
    }
    
    return 
FMRES_IGNORED
}  

remove_hook(index)
{
    
engfunc(EngFunc_RemoveEntityindex)
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
    
write_byte(TE_KILLBEAM)    
    
write_short(index)
    
message_end()



--kml-- 04-01-2009 07:30

Re: Removing grappling hook
 
Quote:

removing the hook once the person is right next to me or touches me when they are still hooked...
this can help?
register_concmd("+hook","hook_on")
register_concmd("-hook","hook_off")

Mini_Midget 04-02-2009 01:35

Re: Removing grappling hook
 
...
If you have read the script... I didn't even register a console command... So the above example won't help me at all. And I also don't want to make a custom bind for the hook. I want to change a halflife default key to it and I'm just using the flashlight key for a quick test for it.

Exolent[jNr] 04-02-2009 13:47

Re: Removing grappling hook
 
Why not register_touch() the two players and use client_PreThink() to check if player touched or is too close.

Mini_Midget 04-03-2009 01:06

Re: Removing grappling hook
 
I did exactly what you said above before I posted this but didn't seem to work for me. I just decided to take it out and just post what I had from the start.

I'm just afraid that cycling through with client_prethink is a lot of work for this anyway so I scrapped that idea.

ConnorMcLeod 04-03-2009 01:18

Re: Removing grappling hook
 
As a side note, use register_impulse(100, "Your_Function") instead of client_impulse forward.

Mini_Midget 04-03-2009 01:26

Re: Removing grappling hook
 
Hmm... Don't want to use regsiter_impulse because its from the Engine module.

http://www.amxmodx.org/funcwiki.php?go=func&id=462

ConnorMcLeod 04-03-2009 01:29

Re: Removing grappling hook
 
Same for client_impulse, the only reason your plugin compiles is that it is a forward.
http://www.amxmodx.org/funcwiki.php?...ulse&go=search

This forward is fired every frame, with register_impulse, the function will be called only when impulse = 100

Dores 04-03-2009 05:19

Re: Removing grappling hook
 
Also, Engine has been proven to be a lot more efficient rather than Fakemeta.

Oh and why do you get the player's velocity twice without even using it the first time..?

PHP Code:

pev(idpev_velocityVelocity)

// and...

velocity_by_aim(id1500Velocity


Exolent[jNr] 04-03-2009 13:50

Re: Removing grappling hook
 
Quote:

Originally Posted by Dores (Post 796064)
Also, Engine has been proven to be a lot more efficient rather than Fakemeta.

You shouldn't say things like this. The stocks such as fakemeta_util that recreate the engine module are slower than the engine module itself, but the fakemeta and engine module are still good. You just need to know that it's better to use the module-specific natives, rather than recreating them with another module.

@Mini_Midget
Take a look in the Code Snippets/Tutorials section about a thread for Module Efficiency. It should be near the top.


All times are GMT -4. The time now is 08:49.

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