AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [FAQ/Tutorial] CS Bomb Scripting (https://forums.alliedmods.net/showthread.php?t=40164)

HamletEagle 12-26-2014 13:53

Re: [FAQ/Tutorial] CS Bomb Scripting
 
Another way for checking if a player has c4 is:
PHP Code:

new const m_rgpPlayerItems_CBasePlayer[6] = {367 368 , ...}
const 
XO_PLAYER 5

if(get_pdata_cbase(idm_rgpPlayerItems_CBasePlayer[5], XO_PLAYER) !=-1

To get the C4 entity index(weapon_c4) it's not needed to keep searching for the bomb with find_ent_by_class, you can hook Ham_Item_AddToPlayer with weapon_c4 as classname. The only checks are to see if the item is valid and if the player is alive. Here you can save it into a global variable and use it later.

To get the planted C4 entity index(grenade) a direct way would be to hook CGrenade::ShootSatchelCharge with okapi(orpheu can't hook it because it doesn't support vector class).

PHP Code:

new const ShootSatchelChargeSignature[] = {0x830xDEF0xDEF0x530x560x570xFF0xDEF0xDEF0xDEF0xDEF0xDEF0x33}
    new const 
ShootSatchelChargeSymbol[] = "_ZN8CGrenade18ShootSatchelChargeEP9entvars_s6VectorS2_"

    
new ShootSatchelChargeFunc 
    
    
if
    ( 
    (
ShootSatchelChargeFunc okapi_mod_get_symbol_ptr(ShootSatchelChargeSymbol)) || 
    (
ShootSatchelChargeFunc okapi_mod_find_sig(ShootSatchelChargeSignaturesizeof ShootSatchelChargeSignature)) 
    ) 
    { 
        
okapi_add_hook(okapi_build_function(ShootSatchelChargeFuncarg_cbasearg_entvarsarg_vecarg_vec), "OnShootSatchelCharge", .post 1


public 
OnShootSatchelCharge(OwnerEntFloat:Origin[], Float:Angles[])
{
    new 
C4EntityIndex okapi_get_orig_return()


In order to give c4 to a player the best way is:

PHP Code:

give_item(id"weapon_c4")
cs_set_user_plant(id11

To remove the c4 weaponbox hook Ham_Touch with "weaponbox" as classname, check if it's a c4 weaponbox and call think on it.

If you want to detect when a user stop planting, you need to register BarTime event but also Ham_Item_Holster to prevent it being innacurate due to weapon switch.

Arkshine 12-26-2014 15:11

Re: [FAQ/Tutorial] CS Bomb Scripting
 
Quote:

Another way for checking if a player has c4 is
The "offset" version can be achieved with cs_get_user_plant(). It uses basically m_bHasC4 player's offset.

Quote:

If you want to detect when a user stop planting, you need to register BarTime event but also Ham_Item_Holster to prevent it being innacurate due to weapon switch.
You can check simply m_bIsDefusing which is set to false before BarTime. Unfortunately, m_bStartDefuse used by cs_get_c4_defusing() is set after BarTime, so you can't use it in this event.

HamletEagle 12-26-2014 15:31

Re: [FAQ/Tutorial] CS Bomb Scripting
 
What defusing has to do with planting ? If the bomb is not planted how someone could be defusing it ? I mean, if the bomb is not yet planted m_bIsDefusing won't be always false ?

Arkshine 12-26-2014 17:16

Re: [FAQ/Tutorial] CS Bomb Scripting
 
No need to think too much, It's kind of obvious I've misread.

But it's the same reasoning. You could probably just check m_bStartedArming which is set to false before BarTime is called.

HamletEagle 12-27-2014 06:03

Re: [FAQ/Tutorial] CS Bomb Scripting
 
But m_bStatedArming doesn't make you sure that he started arming the bomb at some time. If the BarTime is called with correct filters you would know that at some point he started planting the bomb and then stopped. Holster() just "fix" BarTime problem with weapon switch when it's not updated correctly.

Arkshine 12-27-2014 08:15

Re: [FAQ/Tutorial] CS Bomb Scripting
 
BarTime could be called anytime by any plugins and holster just detects one of possible reasons of stopping.
A more reliable way is to not rely on BarTime: Hooking WeaponIdle of weapon_c4 and checking m_bStartedArming.

Code:

void CC4::WeaponIdle(void)
{
        if (m_bStartedArming)
        {
                // If you are here it means you stopped to plant.
        }


HamletEagle 12-27-2014 13:03

Re: [FAQ/Tutorial] CS Bomb Scripting
 
Yes, this would do the trick. Also it's a good ideea to Enable the forward in Deploy() and to Disable it on Holster()

GoldNux 11-06-2022 03:06

Re: [FAQ/Tutorial] CS Bomb Scripting
 
How can I avoid players getting points for defusing / planting the bomb?
Thanks.


All times are GMT -4. The time now is 02:34.

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