Raised This Month: $ Target: $400
 0% 

Removing grappling hook


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 03-25-2009 , 01:01   Removing grappling hook
Reply With Quote #1

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()

__________________
It's a mystery.
Mini_Midget is offline
--kml--
Senior Member
Join Date: Jan 2009
Old 04-01-2009 , 07:30   Re: Removing grappling hook
Reply With Quote #2

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")
--kml-- is offline
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 04-02-2009 , 01:35   Re: Removing grappling hook
Reply With Quote #3

...
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.
__________________
It's a mystery.
Mini_Midget is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-02-2009 , 13:47   Re: Removing grappling hook
Reply With Quote #4

Why not register_touch() the two players and use client_PreThink() to check if player touched or is too close.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 04-03-2009 , 01:06   Re: Removing grappling hook
Reply With Quote #5

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.
__________________
It's a mystery.
Mini_Midget is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-03-2009 , 01:18   Re: Removing grappling hook
Reply With Quote #6

As a side note, use register_impulse(100, "Your_Function") instead of client_impulse forward.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 04-03-2009 , 01:26   Re: Removing grappling hook
Reply With Quote #7

Hmm... Don't want to use regsiter_impulse because its from the Engine module.

http://www.amxmodx.org/funcwiki.php?go=func&id=462
__________________
It's a mystery.
Mini_Midget is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-03-2009 , 01:29   Re: Removing grappling hook
Reply With Quote #8

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
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 04-03-2009 , 05:19   Re: Removing grappling hook
Reply With Quote #9

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
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ
Dores is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-03-2009 , 13:50   Re: Removing grappling hook
Reply With Quote #10

Quote:
Originally Posted by Dores View Post
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.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Reply


Thread Tools
Display Modes

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 08:49.


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