Raised This Month: $12 Target: $400
 3% 

Bear Trap


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sekac
Senior Member
Join Date: Nov 2016
Old 03-06-2019 , 15:20   Bear Trap
Reply With Quote #1

I need a plugin where you can place down a bear trap and when someone goes over it they get stuck. This is not for zombie plague. I also included a model with an open and close animation.

Maybe this will help: https://forums.alliedmods.net/showthread.php?t=253168
Attached Files
File Type: zip trap.zip (223.1 KB, 64 views)
sekac is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-06-2019 , 18:54   Re: Bear Trap
Reply With Quote #2

Cvars:

beartrap_self_trap - Should you trap yourself?
beartrap_trap_teammates - Your teammates maybe?
beartrap_print_owner - Print 'you trapped X' message to the owner of the trap?
beartrap_freedom_time - How many seconds to release the victim
beartrap_max_traps - Yup, you know that
beartrap_trap_delay - Same

Here ya go:

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <engine>
#include <fakemeta>
#include <xs>

#define PLUGIN                 "Bear Trap"
#define VERSION             "1.3"
#define AUTHOR                 "EFFEX"

#define TASK_FREEDOM            4383173
#define resetUserSpeed(%1)        ExecuteHamB(Ham_Player_ResetMaxSpeed, %1)

new const g_szTrapModel[] =         "models/beartrap.mdl"
new const g_szTrapClassName[] =         "beartrap"
new const g_szTrapSound[] =        "bearsound.wav"
new const g_szTrapHitSound[] =        "debris/metal6.wav"

const Float:g_fMaxDistance 150.0

new pCvarSelfTrappCvarMessageOwnerpCvarFreedomTimepCvarTrapTeammatespCvarMaxTraps,
pCvarTrapDelaypCvarBearTrapLife

new g_mMessageBarTime
new Ham:Ham_Player_ResetMaxSpeed Ham_Item_PreFrame

new bool:g_bGotTrapped[MAX_PLAYERS 1]
new 
g_iTrapNum[MAX_PLAYERS 1], g_iSysTime[MAX_PLAYERS 1], g_iTrapID[MAX_PLAYERS 1]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
pCvarSelfTrap register_cvar("beartrap_self_trap""0")
    
pCvarMessageOwner register_cvar("beartrap_print_owner""1")
    
pCvarTrapTeammates register_cvar("beartrap_trap_teammates""0")
    
pCvarFreedomTime register_cvar("beartrap_freedom_time""10")
    
pCvarMaxTraps register_cvar("beartrap_max_traps""3")
    
pCvarTrapDelay register_cvar("beartrap_trap_delay""10")
    
pCvarBearTrapLife register_cvar("beartrap_trap_life""800.0")
    
    
g_mMessageBarTime get_user_msgid("BarTime")

    
register_event("HLTV""event_NewRound""a""1=0""2=0")
    
    
RegisterHam(Ham_Player_Jump"player""ham_Player_Jump_Pre"0)
    
RegisterHam(Ham_Spawn"player""ham_PlayerSpawn_Post"1)
    
RegisterHam(Ham_Player_ResetMaxSpeed"player""Player_ResetMaxSpeed"1)
    
    
register_clcmd("say /placetrap""cmdPlaceTrap")
    
register_forward(FM_Touch"forward_BearTrapTouch")
}

public 
plugin_precache()
{
    
precache_model(g_szTrapModel)
    
precache_sound(g_szTrapSound)
    
precache_sound(g_szTrapHitSound)
}

public 
client_putinserver(id)
{
    
g_bGotTrapped[id] = false
    g_iTrapNum
[id] = 0
}

public 
event_NewRound()
{
    new 
iEnt = -1
    
while((iEnt find_ent_by_class(iEntg_szTrapClassName)))
    {
        
remove_entity(iEnt)
    }
}

public 
ham_PlayerSpawn_Post(id)
{
    
g_bGotTrapped[id] = false
    g_iTrapNum
[id] = g_iSysTime[id] = 0
    
    remove_task
(id TASK_FREEDOM)
}

public 
ham_Player_Jump_Pre(id)
{
    if(
g_bGotTrapped[id])
    {
        static 
iOldbuttonsiOldbuttons entity_get_int(idEV_INT_oldbuttons)
        if(!(
iOldbuttons IN_JUMP))
        {
            
entity_set_int(idEV_INT_oldbuttons, (iOldbuttons IN_JUMP))
            return 
HAM_HANDLED
        
}
        return 
HAM_SUPERCEDE
    
}
    return 
HAM_HANDLED
}

public 
ham_trapTakeDamage(iVictimIDiInflictoriAttackerFloat:fDamage)
{
    if(!
pev_valid(iVictimID) || !is_user_connected(iAttacker))
        return 
FMRES_IGNORED

    
new iTrapVictimID pev(iVictimIDpev_iuser1)
    if(!
iTrapVictimID || !is_user_connected(iTrapVictimID))
    {
        
SetHamReturnInteger(0)
        return 
HAM_SUPERCEDE
    
}
    
    static 
Float:fOrigin[3]
    
pev(iVictimIDpev_originfOrigin)
    
fOrigin[2] += 3.0
    drawSparks
(fOrigin)
    
    if(
floatround(fDamage) >= pev(iVictimIDpev_health))
    {
        
unfreezePlayer(iTrapVictimID)
        
barTime(iTrapVictimID0)
        
remove_task(iTrapVictimID TASK_FREEDOM)
        
        
g_iTrapID[iTrapVictimID] = 0
    
}
    
    
emit_sound(iVictimIDCHAN_BODYg_szTrapHitSoundVOL_NORMATTN_NORM0PITCH_NORM)
    return 
HAM_IGNORED
}

public 
Player_ResetMaxSpeed(id)
{
    if(
is_user_alive(id) && g_bGotTrapped[id])
    {
        
set_pev(idpev_maxspeed, -1.0)
    }
}

public 
forward_BearTrapTouch(iTouchediToucher)
{    
    if(!
pev_valid(iTouched) || !is_user_connected(iToucher))
        return 
FMRES_IGNORED
    
    
if(g_bGotTrapped[iToucher])
        return 
FMRES_IGNORED
        
    
static szClassName[2][MAX_PLAYERS]
    
pev(iToucherpev_classnameszClassName[0], charsmax(szClassName[]))
    
pev(iTouchedpev_classnameszClassName[1], charsmax(szClassName[]))
    
    if(
equal(szClassName[1], g_szTrapClassName) && equal(szClassName[0], "player"))
    {
        static 
Float:fGameTime;fGameTime get_gametime()
        if((
fGameTime pev(iTouchedpev_fuser1)) < 1.0)
            return 
FMRES_IGNORED
            
        
new iOwner pev(iTouchedpev_iuser2)
        if((
iOwner == iToucher) && !get_pcvar_num(pCvarSelfTrap)
        || !(
iOwner == iToucher) && !get_pcvar_num(pCvarTrapTeammates) && (get_user_team(iOwner) == get_user_team(iToucher)))
            return 
FMRES_IGNORED
            
        setAnimation
((g_iTrapID[iToucher] = iTouched), 1)
        
        
emit_sound(iTouchedCHAN_BODYg_szTrapSoundVOL_NORMATTN_NORM0PITCH_NORM)
        
trapPlayer(iToucheriOwneriTouched)
    }
    return 
FMRES_IGNORED
}

public 
cmdPlaceTrap(id)
{
    new 
Float:fEndPosition[3], iTargetFloat:fMaxAimDistanceCheck 30.0
    getAimEndPosition
(idfEndPosition)
    if((
iTarget checkEntitiesAround(idfMaxAimDistanceCheckfEndPosition)))
    {
        if(
pev(iTargetpev_iuser2) == id)
        {
            if(
pev(iTargetpev_iuser1) > 0)
            {
                
client_print(idprint_chat"[BearTrap]: There a player stuck on your trap, you can not take it back.")
                return 
PLUGIN_HANDLED
            
}
            
client_print(idprint_chat"[BearTrap]: You got back your bear trap!")
            
            
g_iTrapNum[id]--
            
remove_entity(iTarget)
        }
        else
        {
            
client_print(idprint_chat"[BearTrap]: This is not your bear trap, get outta here!")
        }
        return 
PLUGIN_HANDLED
    
}
    
    if(
g_iTrapNum[id] >= get_pcvar_num(pCvarMaxTraps))
    {
        
client_print(idprint_chat"[BearTrap]: You cannot make bear traps anymore!")
        return 
PLUGIN_HANDLED
    
}
    
    new 
iSysTime get_systime(), iPcvarValue get_pcvar_num(pCvarTrapDelay)
    new 
iDelay = (iSysTime g_iSysTime[id]), iCountDown = (iPcvarValue iDelay)
    if(
iDelay iPcvarValue)
    {
        
client_print(idprint_chat"[BearTrap]: You must wait %d second%s to place another trap!"iCountDown, (iCountDown 1) ? "s" "")
        return 
PLUGIN_HANDLED
    
}
    
    new 
iBearTrapEntity create_entity("info_target")
    if(
pev_valid(iBearTrapEntity))
    {
        
g_iTrapNum[id]++
        
g_iSysTime[id] = iSysTime
    
        engfunc
(EngFunc_SetOriginiBearTrapEntityfEndPosition)
        
engfunc(EngFunc_SetModeliBearTrapEntityg_szTrapModel)
        
set_pev(iBearTrapEntitypev_movetypeMOVETYPE_NOCLIP)
        
set_pev(iBearTrapEntitypev_solidSOLID_SLIDEBOX)
        
engfunc(EngFunc_SetSizeiBearTrapEntityFloat:{-5.78, -10.0, -0.44}, Float:{5.786.05.05})
        
        
set_pev(iBearTrapEntitypev_iuser2id)
        
set_pev(iBearTrapEntitypev_classnameg_szTrapClassName)
        
drop_to_floor(iBearTrapEntity)
    }
    return 
PLUGIN_HANDLED
}

checkEntitiesAround(playerFloat:fRadiusFloat:fOrigin[3])
{
    static 
szClassName[MAX_PLAYERS], Float:fEntOrigin[3], Float:fPlayerOrigin[3]
    
pev(playerpev_originfPlayerOrigin)
    for(new 
iWbox; (iWbox find_ent_in_sphere(iWboxfOriginfRadius)) != 0;)
    {
        
pev(iWboxpev_originfEntOrigin)
        if(
get_distance_f(fEntOriginfPlayerOrigin) > g_fMaxDistance)
            continue
            
        
entity_get_string(iWboxEV_SZ_classnameszClassNamecharsmax(szClassName))
        if(
equal(szClassNameg_szTrapClassName))
        {
            return 
iWbox
        
}
    }
    return 
0
}

getAimEndPosition(idFloat:fOrigin[3]) 
{
    new 
Float:fStart[3], Float:fViewOfs[3]
    
pev(idpev_originfStart)
    
pev(idpev_view_ofsfViewOfs)
    
xs_vec_add(fStartfViewOfsfStart)

    new 
Float:fDest[3]
    
pev(idpev_v_anglefDest)
    
engfunc(EngFunc_MakeVectorsfDest)
    
global_get(glb_v_forwardfDest)
    
xs_vec_mul_scalar(fDestg_fMaxDistancefDest)
    
xs_vec_add(fStartfDestfDest)

    
engfunc(EngFunc_TraceLinefStartfDest0id0)
    
get_tr2(0TR_vecEndPosfOrigin)


trapPlayer(iVictimiKilleriTrapID)
{
    
g_bGotTrapped[iVictim] = true
    set_pev
(iVictimpev_maxspeed, -1.0)
    
    if(
get_pcvar_num(pCvarMessageOwner))
    {
        new 
szVictimName[MAX_PLAYERS]
        
get_user_name(iVictimszVictimNamecharsmax(szVictimName))
        
client_print(iKillerprint_chat"[BearTrap]: %s got trapped by your bear trap!"szVictimName)
    }

    
set_pev(iTrapIDpev_healthget_pcvar_float(_:pCvarBearTrapLife))
    
set_pev(iTrapIDpev_takedamageDAMAGE_AIM)
    
RegisterHamFromEntity(Ham_TakeDamageiTrapID"ham_trapTakeDamage")
    
set_pev(iTrapIDpev_nextthinkget_gametime() + 1.0)
    
    new 
Float:fDelayTime float(get_pcvar_num(pCvarFreedomTime))
    
set_pev(iTrapIDpev_iuser1iVictim)
    
set_pev(iTrapIDpev_fuser1get_gametime() + (fDelayTime 2.0))
    
set_task(fDelayTime"giveFreedom"iVictim TASK_FREEDOM)

    
barTime(iVictimfloatround(fDelayTime))
}

public 
giveFreedom(id)
{
    
id -= TASK_FREEDOM
    
    
if(is_user_connected(id))
    {
        
setAnimation(g_iTrapID[id], 0)
        
set_pev(g_iTrapID[id], pev_iuser10)
        
unfreezePlayer(id)
        
        
g_iTrapID[id] = 0
    
}
    else 
g_iTrapID[id] = 0
}

setAnimation(iEntityiAnim)
{
    
entity_set_float(iEntityEV_FL_animtime0.0)
    
entity_set_float(iEntityEV_FL_framerate0.4)
    
entity_set_int(iEntityEV_INT_sequenceiAnim)
    
entity_set_int(iEntityEV_INT_gaitsequence1)
    
entity_set_float(iEntityEV_FL_frame0.0)
}

unfreezePlayer(iVictim)
{
    
g_bGotTrapped[iVictim] = false
    resetUserSpeed
(iVictim)
}

barTime(idiTime)
{
    if(
is_user_connected(id))
    {
        
message_begin(MSG_ONEg_mMessageBarTime, .player id)
        
write_short(iTime)
        
message_end()  
    }
}

drawSparks(Float:fOrigin[3])
{
    
message_begin(MSG_ALLSVC_TEMPENTITY)
    
write_byte(TE_SPARKS)
    
engfunc(EngFunc_WriteCoordfOrigin[0])
    
engfunc(EngFunc_WriteCoordfOrigin[1])
    
engfunc(EngFunc_WriteCoordfOrigin[2])
    
message_end()    

You can use a sound, just download it and name as 'beartrap' ^^.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 03-13-2019 at 08:10.
EFFx is offline
sekac
Senior Member
Join Date: Nov 2016
Old 03-07-2019 , 02:47   Re: Bear Trap
Reply With Quote #3

Ok so here are some changes that would be nice:
1. Add a cooldown to placing traps so you can't spam them and add a maximum of 3 traps per player.
2. The traps should be placed where you are aiming, but only on the ground and in a certain distance.
3. If you aim at a trap and you say /placetrap you should get that trap back.
4. Play the close animation after someone steps in the trap.
5. Instead of using FL_FROZEN use set_user_maxspeed so the player is still able to attack.

Last edited by sekac; 03-07-2019 at 02:55.
sekac is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-07-2019 , 17:40   Re: Bear Trap
Reply With Quote #4

Updated the code, take a look.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
sekac
Senior Member
Join Date: Nov 2016
Old 03-07-2019 , 17:44   Re: Bear Trap
Reply With Quote #5

Quote:
Originally Posted by EFFx View Post
Updated the code, take a look.
I will do it in the morning, I'm really tired right now
sekac is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 03-07-2019 , 21:56   Re: Bear Trap
Reply With Quote #6

@EFFx whats the difference between your getAimEndPosition and get_user_origin 2 ?
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-07-2019 , 22:41   Re: Bear Trap
Reply With Quote #7

I got that code from here - https://forums.alliedmods.net/showthread.php?t=91122
Take a look at #5 reply by Arkshine.

Besides it being more accurate (not that big difference, but still better), I can easily use the max distance and still spawning the entity correctly (even if the end position is too far away), thing that get_user_origin with 2/3 value being the third parameter will not be able to do.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 03-07-2019 at 22:47.
EFFx is offline
sekac
Senior Member
Join Date: Nov 2016
Old 03-08-2019 , 03:23   Re: Bear Trap
Reply With Quote #8

This is really nice man! I will be testing it more later. If you have time try adding that every time you press e you reduce the time you are in the trap (by like 0.05 seconds). It would be nice to have the defuse progress bar for this as well.
sekac is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-08-2019 , 07:27   Re: Bear Trap
Reply With Quote #9

You can make the trap breakable so damaging the trap to destroy it bether than presting e to defuse or whatever...

I used to see nice traps when I was playing TTT it was pretty much fun.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 03-08-2019 at 07:30.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
sekac
Senior Member
Join Date: Nov 2016
Old 03-08-2019 , 09:29   Re: Bear Trap
Reply With Quote #10

Quote:
Originally Posted by Natsheh View Post
You can make the trap breakable so damaging the trap to destroy it bether than presting e to defuse or whatever...

I used to see nice traps when I was playing TTT it was pretty much fun.
That's fine too. The defuse bar would just show how long you will be in the trap.
sekac 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 21:08.


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