Raised This Month: $32 Target: $400
 8% 

[FAQ/Tutorial] CS Bomb Scripting


Post New Thread Reply   
 
Thread Tools Display Modes
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-26-2014 , 13:53   Re: [FAQ/Tutorial] CS Bomb Scripting
Reply With Quote #81

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.
__________________

Last edited by HamletEagle; 12-26-2014 at 14:06.
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-26-2014 , 15:11   Re: [FAQ/Tutorial] CS Bomb Scripting
Reply With Quote #82

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.
__________________

Last edited by Arkshine; 12-26-2014 at 15:12.
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-26-2014 , 15:31   Re: [FAQ/Tutorial] CS Bomb Scripting
Reply With Quote #83

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 ?
__________________

Last edited by HamletEagle; 12-26-2014 at 15:35.
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-26-2014 , 17:16   Re: [FAQ/Tutorial] CS Bomb Scripting
Reply With Quote #84

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.
__________________

Last edited by Arkshine; 12-26-2014 at 17:18.
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-27-2014 , 06:03   Re: [FAQ/Tutorial] CS Bomb Scripting
Reply With Quote #85

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.
__________________

Last edited by HamletEagle; 12-27-2014 at 06:04.
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-27-2014 , 08:15   Re: [FAQ/Tutorial] CS Bomb Scripting
Reply With Quote #86

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.
	}
__________________
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-27-2014 , 13:03   Re: [FAQ/Tutorial] CS Bomb Scripting
Reply With Quote #87

Yes, this would do the trick. Also it's a good ideea to Enable the forward in Deploy() and to Disable it on Holster()
__________________
HamletEagle is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 11-06-2022 , 03:06   Re: [FAQ/Tutorial] CS Bomb Scripting
Reply With Quote #88

How can I avoid players getting points for defusing / planting the bomb?
Thanks.
GoldNux is offline
Reply



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 14:56.


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