Throwable C4 0.6

A Config Script for Counter-Strike 1.6

Greetings! We are one of the oldest mod sites on the Interwebs. Sign up and maximize your browsing experience.

  • Subscribe: Get notified of new submissions like this.
  • Say Thanks: Show your appreciation by sending rj. points.
  • Post: Give rj. your thoughts on this Script.
  • Vote: Help rj. win the Monthly Awards.
  • Rate: Give this Script a rating out of 10.
  • Flag: Alert moderators and warn members of a problem with this Script.
  • Watch: Get notified when this Script is updated.
Mascot

Stop Lurking!

Sign up

Already a Bananite? Login

258 lines | 8 kb | Raw Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
        Copyleft 2014 @ HamletEagle
        Plugin Theard: https://forums.alliedmods.net/showthread.php?p=2203556

        Throwable C4 is free software;
        you can redistribute it and/or modify it under the terms of the
        GNU General Public License as published by the Free Software Foundation.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with Furiens; if not, write to the
        Free Software Foundation, Inc., 59 Temple Place - Suite 330,
        Boston, MA 02111-1307, USA.

        Changelog:
       
        V 0.1:  
        + Initial Release.  
        V 0.2:  
        + Fixed some think bugs.
        + Now using a more efficient method to get detect when player is using IN_ATTACK2 button
        + Fixed a bug when you can't plant the c4 as per usual.
        + Now the bomb hud icon is put back when you pickup the fake c4.
        + Now the boxs near the bombsite are destroyed.
        V 0.3:
        + Now the bomb is handled by the game so api removed.
        V 0.4:
        + Changed a lot of stuffs, can't write all of them here.
        V 0.5:
        + Major changes, Arkshine pocket is empty now, hopefuly.
        V 0.6:
        + Fixed plugin not working on linux
        + Changed variable names
*/


#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike>
#include <okapi>
#include <xs>
#if AMXX_VERSION_NUM  >= 183
#include <csx>
#endif

#define PLUGIN  "Throwable C4"
#define VERSION "0.6"
#define AUTHOR  "HamletEagle"

new HamHook: HookCBaseEntity_C4Idle
new HamHook: HookCBasePlayer_ItemHolster
new HamHook: HookCBasePlayer_ItemDeploy

const XO_WEAPON = 4
const MAPZONE_BIT_BOMB = 1 << 1
const m_bStartedArming = 320   
const m_bBombPlacedAnimation= 321
const m_fMapZone = 234

new g_iC4Id
new gmsgBombDrop

#if AMXX_VERSION_NUM < 183
const INT_BYTES = 4
const BYTE_BITS = 8

stock set_pdata_bool(ent, charbased_offset, _:value, intbase_linuxdiff = 5)
{
        value &= 0xFF
        new int_offset_value = get_pdata_int(ent, charbased_offset / INT_BYTES, intbase_linuxdiff)
        new bit_decal = (charbased_offset % INT_BYTES) * BYTE_BITS
        int_offset_value &= ~(0xFF<<bit_decal) // clear byte
        int_offset_value |= value<<bit_decal
        set_pdata_int(ent, charbased_offset / INT_BYTES, int_offset_value, intbase_linuxdiff)
}
#endif

public plugin_init()
{
        register_plugin
        (
                .plugin_name = PLUGIN,
                .version = VERSION,
                .author = AUTHOR
        )
       
        //FM_CmdStart is not a good way, so here is the alternative
        HookCBasePlayer_ItemDeploy  = RegisterHam(Ham_Item_Deploy, "weapon_c4", "CBasePlayer_ItemDeploy", false)
        HookCBasePlayer_ItemHolster = RegisterHam(Ham_Item_Holster, "weapon_c4", "CBasePlayer_ItemHolster", false)
        HookCBaseEntity_C4Idle      = RegisterHam(Ham_Weapon_WeaponIdle, "weapon_c4", "CBaseEntity_C4Idle", true)
        DisableHamForward(HookCBaseEntity_C4Idle) //disable it for now
       
        #if AMXX_VERSION_NUM < 183
        if(!find_ent_by_class(-1 , "func_bomb_target") && !find_ent_by_class(-1 , "info_bomb_target"))
        {
                set_fail_state("Not a bomb map, plugin paused")
        }
        #else
        if(!(get_map_objectives( ) & MapObjective_Bomb))
        {
                set_fail_state("Not a bomb map, plugin paused")
        }
        #endif
       
        //Hook CGrenade::ShootSatchelCharge
        new const ShootSatchelChargeSignature  [ ] = { 0x83, 0xDEF, 0xDEF, 0x53, 0x56, 0x57, 0xFF, 0xDEF, 0xDEF, 0xDEF, 0xDEF, 0xDEF, 0x33 }
        new const ShootSatchelChargeSymbol     [ ] = "_ZN8CGrenade18ShootSatchelChargeEP9entvars_s6VectorS2_"
       
        new funcShootSatchelChage
       
        if
        (
                (funcShootSatchelChage = okapi_mod_get_symbol_ptr(ShootSatchelChargeSymbol)) ||
                (funcShootSatchelChage = okapi_mod_find_sig(ShootSatchelChargeSignature, sizeof ShootSatchelChargeSignature))
        )
        {
                okapi_add_hook(okapi_build_function(funcShootSatchelChage, arg_cbase, arg_entvars, arg_vec, arg_vec), "OnShootSatchelCharge", .post = 1)
        }

        else
        {
                set_fail_state("CGrenade::ShootSatchelCharge function could not be found.")
        }
        gmsgBombDrop = get_user_msgid("BombDrop")
}


public CBasePlayer_ItemDeploy(iEnt)
{
        EnableHamForward(HookCBaseEntity_C4Idle)
}

public CBasePlayer_ItemHolster(iEnt)
{
        DisableHamForward(HookCBaseEntity_C4Idle)
}

public CBaseEntity_C4Idle(iEnt)
{
        new id = pev(iEnt, pev_owner)
        if((pev(id, pev_button) & IN_ATTACK2) && pev_valid(iEnt)) //did player pressed IN_ATTACK2 button ?
        {
                if(get_pdata_int(id, m_fMapZone) & MAPZONE_BIT_BOMB) //in bomb zone ?
                {
                        // Below here is some boring math: https://github.com/Arkshine/CSSDK/blob/ ... renade.cpp
                        // Basically, I'm applying somekegrenade throw on a c4 so I won't explain, it's obvious
                        // Calculate how hard to throw the grenade based on the aim angle
                        new Float: playerVelocity [ 3 ]; pev(id, pev_velocity, playerVelocity)
                        new Float: playerOrigin   [ 3 ]; pev(id, pev_origin, playerOrigin)
                        new Float: vViewAngle     [ 3 ]; pev(id, pev_v_angle, vViewAngle)
                        new Float: vPunchAngle    [ 3 ]; pev(id, pev_punchangle, vPunchAngle)
                        new Float: playerViewOfs  [ 3 ]; pev(id, pev_view_ofs,  playerViewOfs)
                        new Float: vAngleThrow    [ 3 ]; new Float: fDirection[ 3 ]
                       
                        //By adding them, we get an origin at the "points" of the gun
                        xs_vec_add(playerVelocity, playerViewOfs, fDirection)
                        xs_vec_add(vViewAngle, vPunchAngle, vAngleThrow)
                       
                        if(vAngleThrow[ 0 ] < 0)
                        {
                                vAngleThrow[ 0 ] = -10 + vAngleThrow[ 0 ] * ((90 - 10) / 90.0)
                        }
                        else
                        {
                                vAngleThrow[ 0 ] = -10 + vAngleThrow[ 0 ] * ((90 + 10) / 90.0)
                        }
                       
                        //Let the game do the job for us
                        engfunc(EngFunc_MakeVectors, vAngleThrow)
                        global_get(glb_v_forward, fDirection)
                       
                        playerOrigin[ 0 ] = playerOrigin[ 0 ] + (16.0 * fDirection[ 0 ])
                        playerOrigin[ 1 ] = playerOrigin[ 1 ] + (16.0 * fDirection[ 1 ])
                        playerOrigin[ 2 ] = playerOrigin[ 2 ] + (16.0 * fDirection[ 2 ])
               
                        new Float: fMulty = floatmin((90 - vAngleThrow[ 0 ]) * 6.0, 750.0)
                        playerVelocity[ 0 ] = playerVelocity[ 0 ] + (fMulty * fDirection[ 0 ])
                        playerVelocity[ 1 ] = playerVelocity[ 1 ] + (fMulty * fDirection[ 1 ])
                        playerVelocity[ 2 ] = playerVelocity[ 2 ] + (fMulty * fDirection[ 2 ])
                       
                        //We already have the entid, otherwise we would need
                        //to retrive it from 372 offset( m_rgpPlayerItems )
                        //By setting m_bStartedArming and m_bBombPlacedAnimation we fake the c4 plant
                        //We set the mapzone so the game will think you are in a bombsite.
                        //We set user flags on ground, just to make sure
                       
                        set_pdata_bool(iEnt, m_bStartedArming, true, XO_WEAPON)
                        set_pdata_bool(iEnt, m_bBombPlacedAnimation, true, XO_WEAPON)
                        set_pev(id, pev_flags, pev(id, pev_flags) | FL_ONGROUND)
                       
                        new msgBlockType = get_msg_block(gmsgBombDrop)
                        set_msg_block(gmsgBombDrop, BLOCK_ONCE)
                       
                        //Now, execute primary attack on the weapon_c4 entity, this will create the grenade_entity
                        ExecuteHamB(Ham_Weapon_PrimaryAttack, iEnt)
                       
                        if(!pev_valid(g_iC4Id))
                        {
                                return
                        }
                       
                        //Set the origin in the "middle" zone of the player
                        //So the c4 throw will be like a grenade one
                        set_pev(g_iC4Id, pev_origin, playerOrigin)
                        set_pev(g_iC4Id, pev_velocity, playerVelocity)
                       
                        new iTrace = create_tr2()
                        engfunc(EngFunc_TraceToss, g_iC4Id, IGNORE_MONSTERS, iTrace)
                        new Float: fEndOrigin[ 3 ]; get_tr2(iTrace, TR_vecEndPos, fEndOrigin)
                       
                        emessage_begin(MSG_ALL, gmsgBombDrop)
                        {
                                engfunc(EngFunc_WriteCoord, fEndOrigin[ 0 ])
                                engfunc(EngFunc_WriteCoord, fEndOrigin[ 1 ])
                                engfunc(EngFunc_WriteCoord, fEndOrigin[ 2 ])
                                ewrite_byte(1)
                                emessage_end()
                        }
                       
                        free_tr2(iTrace)
                        set_msg_block(gmsgBombDrop, msgBlockType)
                }  
                else
                {
                        #if AMXX_VERSION_NUM < 183
                        engclient_cmd( id, "drop", "weapon_c4" )       
                        #else
                        amxclient_cmd( id, "drop", "weapon_c4" )
                        #endif
                }
               
        }
}

public OnShootSatchelCharge(iOwner, iEnt, Float: fOrigin[ ], Float: fAngles[ ])
{
        //Get c4 ent id
        g_iC4Id = okapi_get_orig_return( )
}

public plugin_pause()
{
        DisableHamForward(HookCBaseEntity_C4Idle)
        DisableHamForward(HookCBasePlayer_ItemDeploy)
        DisableHamForward(HookCBasePlayer_ItemHolster)
}

public plugin_unpause()
{
        EnableHamForward(HookCBaseEntity_C4Idle)
        EnableHamForward(HookCBasePlayer_ItemDeploy)
        EnableHamForward(HookCBasePlayer_ItemHolster)
}
Throwable C4 0.6
Release: 25.09.2014 | Last Update: 28.11.2014

Table of Contents

Description top

This plugin brings a new concept into the game, now you can throw the bomb. All you have to do is find a bomb site, go into it and press right click. The bomb will be thrown with a certain speed and a certain direction and will plant where it lands, no matter if it is no longer in bomb site.

Features:
  1. If you are in a bomb site the bomb will be throwed and will get planted.
  2. If you are outside bomb site and you press right click, the bomb will be just dropped.
  3. If you are not running a bomb map the plugin will be auto paused, so it won't use memory for nothing.
Requirements top

You need the fallowing things to get this working:
  • Okapi module.
  • An updated server without dproto.
    It may work into your outdated server with dproto, but if it doesn't, I won't help you.
Installation top

To install the plugin:
  1. Download the resources from this post. You need to get the source and compile it locally.
  2. Put throwable_c4.amxx in addons/amxmodx/plugins
  3. Open addons/amxmodx/configs/plugins.ini and add at the end of this file throwable_c4.amxx
  4. You can put the sma file into addons/amxmodx/sources but this is not mandatory.
  5. Restart the server/change map.

To install okapi:
  1. Download okapi_bin.zip and extrat the arhive.
  2. Copy okapi_amxx.dll/okapi_amxx_i386.so depending on your operation system into addons/amxmodx/modules
  3. The module will be auto-loaded, you don't need to add it into modules.ini

To compile locally:
  • First way:
    1. Download AMX Mod X for windows/linux from main site
    2. Extract somewhere the arhive and remember the folder!
    3. Copy the content from include folder from the okapi arhive into addons/amxmodx/scripting/include( in the folder created in the step 2 ).
    4. Download the source of the plugin( throwable_c4.sma) from this post and drag it over the compile.exe(scripting folder from the arhive created at step 2)
    5. It will create a new folder called compiled. Open it and you will find your compiled plugin( throwable_c4.amxx )
  • Second way:
    1. Go to http://spider.limetech.org/
    2. Copy/paste the code from the .sma file into the website.
    3. Under the big blue Compile button you see a box which Drop .inc files here
    4. Then press Compile and Download
Credits top
  • BackStabNoob: base ideea
  • Arkshine: a lot of useful explanation.
ChangeLog top
  • V 0.1:
    • Initial release
  • V 0.2:
    • Fixed some think bugs.
      Now using a more efficient method to get detect when player is using IN_ATTACK2 button
      Fixed a bug when you can't plant the c4 as per usual.
      Now the bomb hud icon is put back when you pickup the fake c4.
      Now the boxs near the bombsite are destroyed.
  • V 0.3:
    • Now the bomb is handled by the game so api removed..
  • V 0.4:
    • Changed a lot of stuffs, can't write all of them here.
  • V 0.5:
    • Major changes, Arkshine pocket is empty now, hopefuly.
  • V 0.6:
    • Fixed plugin not working on linux
    • Changed variable names
Downloads top
  • V 0.1 + V 0.2:25 downloads
  • V 0.3+0.5: 110 downloads

Posts

None found

Embed

Share banner
Image URL:
HTML embed code:
BB embed code:
Markdown embed code:

Credits

Key Authors
BackStabNoob
Idea
Arkshine
A lot of useful explanation
Original Authors
HamletEagle
Amxx script

Submitter

rj. avatar
rj. PAUSE
Member Joined 1y
507 points Ranked 8853rd
38 medals 4 legendary 10 rare
  • Submitted 15 Tools Medal icon
  • Submitted 50 Gamefiles Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
  • Thanked 500 submitters Medal icon
  • 2nd Place - Game Poetry Contest Medal icon
  • Submitted 5 Tools Medal icon

rj.
Redistributor
Are you the owner? Request Ownership
Sign up to access this!
Sign up to access this!
Sign up to access this!
Sign up to access this!

Category

Stats

Posts
0
Views
699
Date Added
9mo
bcp.crwdcntrl.net tracking pixel