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

[FAQ/Tutorial] CS Bomb Scripting


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
VEN
Veteran Member
Join Date: Jan 2005
Old 06-24-2006 , 11:35   [FAQ/Tutorial] CS Bomb Scripting
Reply With Quote #1

Intro
Bomb is the one of the most interesting aspects of the CS scripting. I saw many bomb scripting questions/mistakes. So i decided to create the "CS Bomb Scripting FAQ/Tutorial".

Requirements
You should be familiar with the basics of the AMXX scripting. Fakemeta Utilities functions is used here. To get the player's index (only inside "logevent_function_p") you have to use:
PHP Code:
stock get_loguser_index() {
    new 
loguser[80], name[32]
    
read_logargv(0loguser79)
    
parse_loguser(logusername31)
 
    return 
get_user_index(name)

Example:
PHP Code:
public logevent_function_p() {
    new 
id get_loguser_index()
    
// ...

1. Player/Bomb
PHP Code:
// Is bomb dropped/carried?
    
if (fm_find_ent_by_class(-1"weapon_c4"))
 
// Is bomb dropped?
    
new bomb fm_find_ent_by_class(-1"weapon_c4")
    if (
bomb && pev(bombpev_owner) > get_maxplayers())
 
// Is bomb carried/who is the carrier?
    
new carrier 0ownerentbomb fm_find_ent_by_class(-1"weapon_c4")
    if (
bomb && (ownerent pev(bombpev_owner)) <= get_maxplayers())
        
carrier ownerent
    
if (carrier// we have the carrier
    
else // we do not have a carrier
 
// Is given player has the bomb?
    
if (user_has_weapon(idCSW_C4)) // method #1
    
if (pev(idpev_weapons) & (1<<CSW_C4)) // method #2
    
if (fm_find_ent_by_owner(-1"weapon_c4"id)) // method #3
 
// How to transfer the bomb from one player to another?
    
fm_transfer_user_gun(carrierrecipientCSW_C4// returns true on success
 
// How to force a player to drop the bomb?
    
engclient_cmd(id"drop""weapon_c4")
 
// How to remove the dropped bomb?
    
new weapboxbomb fm_find_ent_by_class(-1"weapon_c4")
    if (
bomb && (weapbox pev(bombpev_owner)) > get_maxplayers()) {
        
dllfunc(DLLFunc_Thinkweapbox// will remove weaponbox + weapon_c4 entity pair
        // remove blinking red bomb mark on the radar
        
message_begin(MSG_ALLget_user_msgid("BombPickup"))
        
message_end()
    }
 
// How to give the bomb to a player?
    
fm_give_item(id"weapon_c4")
    
// use cs_set_user_plant(id) to allow planting
 
// How to strip the bomb from a player?
    
engclient_cmd(id"weapon_c4")
    
cs_set_user_bpammo(idCSW_C40)
    
engclient_cmd(id"lastinv")
    
// remove bomb hud icon
    
message_begin(MSG_ONEget_user_msgid("StatusIcon"), _id)
    
write_byte(0)
    
write_string("c4")
    
message_end()
 
// Is bomb planted/how to remove the planted bomb?
    
new bomb
    
if ((bomb fm_find_ent_by_model(-1"grenade""models/w_c4.mdl"))) {
        
// bomb is planted
        
fm_remove_entity(bomb// remove the planted bomb
    

2. Drop/Collect
PHP Code:
// Player spawned with the bomb event
    
register_logevent("logevent_function_p"3"2=Spawned_With_The_Bomb")
 
// Bomb dropped (including disconnect/death) event
    
register_logevent("logevent_function_p"3"2=Dropped_The_Bomb")
    
// use is_user_alive/is_user_connected to check for disconnect/death
 
// Bomb collected (except spawn) event
    
register_logevent("logevent_function_p"3"2=Got_The_Bomb")
 
// Bomb gained (including spawn/give_item) event
    
register_event("WeapPickup""event_function""be""1=6"
3. Plant/Defuse
PHP Code:
// Bomb planting started event
    
register_event("BarTime""event_function""be""1=3")
 
// Bomb planted event
    
register_logevent("logevent_function_p"3"2=Planted_The_Bomb")
 
// Bomb defusion started event
    
register_event("BarTime""event_function""be""1=5""1=10")
 
// Bomb defusion (without kit) started event
    
register_logevent("logevent_function_p"3"2=Begin_Bomb_Defuse_Without_Kit")
 
// Bomb defusion (with kit) started event
    
register_logevent("logevent_function_p"3"2=Begin_Bomb_Defuse_With_Kit")
 
// Bomb defused event
    
register_logevent("logevent_function_p"3"2=Defused_The_Bomb")
 
// Bomb planting/defusion canceled event
    
register_event("BarTime""event_function""b""1=0")
    
register_event("CurWeapon""event_function""be""2!6")
    
// you must be sure that bomb planting/defusion is in progress!
 
// Target saved event
    
register_logevent("logevent_function"6"3=Target_Saved"
4. Explosion
PHP Code:
// Target bombed (right before round end) event
    
register_logevent("logevent_function"6"3=Target_Bombed")
 
// Planted bomb exploded (before/after round end) event (discovered by Ryan)
    
register_event("23""event_function""a""1=17""6=-105""7=17")
 
// Player killed by bomb explosion event(forward) (discovered by Brad/VEN)
    // will not work if victim is killed by env_explosion entity that is triggered by explosion
    
public client_death(killervictimwpnindexhitplaceTK) {
        if (
wpnindex == CSW_C4)
    } 
5. Targets
PHP Code:
// Is player at the bomb target (func_bomb_target)?
    // Note: there are no good way to detect if player is at the info_bomb_target
    
new target = -1, class[] = "func_bomb_target"bool:is_inside false
    
while ((target fm_find_ent_by_class(target, class))) {
        if (!
fm_boxents_distance(indextarget)) {
            
is_inside true
            
break
        }
    }
    if (
is_inside)
 
// Is map contain bomb targets?
    
if (fm_find_ent_by_class(-1"func_bomb_target") || fm_find_ent_by_class(-1"info_bomb_target"))
 
// How to remove bomb targets?
    
new target = -1classname[] = "func_bomb_target"
    
while ((target fm_find_ent_by_class(targetclassname)))
        
fm_remove_entity(target)
    
classname "info_bomb_target"
    
while ((target fm_find_ent_by_class(targetclassname)))
        
fm_remove_entity(target

Last edited by Exolent[jNr]; 11-10-2010 at 02:00. Reason: Added CurWeapon for bomb plant/defuse cancel event.
VEN is offline
SubStream
Veteran Member
Join Date: Aug 2005
Location: USA
Old 06-24-2006 , 17:24   Re: CS Bomb Scripting FAQ/Tutorial
Reply With Quote #2

Nice stuff VEN I'm happy to see a tutorials section and this is definetly a needed one.

Last edited by SubStream; 06-24-2006 at 17:24. Reason: Forgot to uncheck my signature
SubStream is offline
xnn
Junior Member
Join Date: Jun 2006
Old 06-26-2006 , 18:41   Re: CS Bomb Scripting FAQ/Tutorial
Reply With Quote #3

Yep, very useful stuff. Thank you VEN.
xnn is offline
ConManKilla07
BANNED
Join Date: Aug 2006
Old 08-12-2006 , 18:06   Re: CS Bomb Scripting FAQ/Tutorial
Reply With Quote #4

Ok I have two questions :
1. How would i just find the bomb , becasue you have for wether its dropped or is carried and who is carrying and etc etc . But what would i use to just find the bomb wether its dropped or not ?
2. when you used

Code:
if (fm_find_ent_by_class(-1, "func_bomb_target"))
what does it return for a value ? So I can use it like so
Code:
if (fm_find_ent_by_class(-1, "func_bomb_target"))==0) //if 0 is no targets return PLUGIN_HANDLED }

Last edited by ConManKilla07; 08-12-2006 at 18:11.
ConManKilla07 is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 08-12-2006 , 23:11   Re: CS Bomb Scripting FAQ/Tutorial
Reply With Quote #5

It returns the entity's index.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
ConManKilla07
BANNED
Join Date: Aug 2006
Old 08-12-2006 , 23:23   Re: CS Bomb Scripting FAQ/Tutorial
Reply With Quote #6

which is ?????????
ConManKilla07 is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 08-13-2006 , 00:16   Re: CS Bomb Scripting FAQ/Tutorial
Reply With Quote #7

Anywhere from get_maxplayers()+1 to global_get(glb_maxEntites).
Entity ranges default to 1-500.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
ConManKilla07
BANNED
Join Date: Aug 2006
Old 08-13-2006 , 01:09   Re: CS Bomb Scripting FAQ/Tutorial
Reply With Quote #8

oh ok . thats a high index . so I could use the maxplayers as a return value ?
ConManKilla07 is offline
The Specialist
BANNED
Join Date: Nov 2006
Old 11-27-2006 , 06:49   Re: CS Bomb Scripting FAQ/Tutorial
Reply With Quote #9

Is there a way to block a bomb from being defused without removing buttons? And How can you make the bomb explode when ever you want instead of when its supposed to.

Last edited by The Specialist; 11-27-2006 at 11:08.
The Specialist is offline
Send a message via AIM to The Specialist
Rolnaaba
Veteran Member
Join Date: May 2006
Old 11-28-2006 , 10:16   Re: CS Bomb Scripting FAQ/Tutorial
Reply With Quote #10

how can I get the bomb defused, and bomb planted events to call different functions?
Code:
register_logevent("logevent_function_p", 3, "2=Planted_The_Bomb"); // Bomb planted Event  register_logevent("logevent_function_p", 3, "2=Defused_The_Bomb"); // Bomb Defused Event
seems to me to call the same function "logevent_function_p" how would I sort out which one activated the event?
__________________
DO NOT PM me about avp mod.
Rolnaaba 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 06:46.


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