OSP Code Combat Grenades and Explosions (Originally by Beaver)

Best answers
0
Hi everyone, I don't know if this is worthy of its own topic, but here is a fixed version of Beaver's grenade script that has existed http://mbmodwiki.ollclan.eu/Grenade here for a long time. Thanks to the help of DuskVoyager, I have made a fixed version, that is also much more user friendly and modular. Note this is only tested in SP, but it could be converted to MP pretty easily.

An example grenade to put in your module_items.py

Code:
["grenade_1", "Grenades", [("grenade_1",0)],itp_type_thrown |itp_merchandise|itp_primary, itcf_throw_stone,500,weight(4)|difficulty(0)|spd_rtng(85) | shoot_speed(30) | thrust_damage(1 ,  blunt)|max_ammo(2)|weapon_length(8),imodbits_none, [(ti_on_missile_hit, [	(this_or_next|multiplayer_is_server), #Only run on server for multiplayer
(neg|game_in_multiplayer_mode),
(store_trigger_param_1,":grenadier"),

#GRENADE STATS
(assign, ":damageMin", 60),
(assign, ":damageMax", 100),
(assign, ":radius", 250),
(call_script, "script_create_explosion", ":grenadier", ":damageMin", ":damageMax", ":radius"), 
])]],

For your module_scripts.py

Code:
 #script_create_explosion
  #Input: grenadier, damage min, damage max, explosion radius, 
  #Output: none
  #NOTE: If creating an explosion outside of weapon triggers, store the location in pos1
  ("create_explosion", [
      
     (store_script_param, ":grenadier", 1),
     (store_script_param, ":damageMin", 2),
     (store_script_param, ":damageMax", 3),
     (store_script_param, ":radius", 4),
      
      
      
      
       (particle_system_burst,"psys_pistol_smoke",pos1,50),
        (particle_system_burst,"psys_village_fire_big",pos1,50),
          (try_for_agents,":target"),

            (agent_is_alive, ":target"),
            (agent_is_active, ":target"),
            (agent_get_team, ":grenadiers_team", ":grenadier"),
            (agent_get_team, ":targets_team", ":target"),
            (teams_are_enemies, ":grenadiers_team", ":targets_team"), 

            (agent_get_position,pos2,":target"),
            (get_distance_between_positions,":dist",pos1,pos2),
       (try_begin),
               (lt,":dist", ":radius"),
               (store_agent_hit_points,":hp",":target",1),
      (store_random_in_range,":dmg", ":damageMin", ":damageMax"),
      (val_sub,":hp",":dmg"),
      (try_begin),
       (lt, ":hp", 0),
        #if you want to play a custom animation for explosive deaths, put it here.       
        #(agent_set_animation, ":target", "anim_explosion_death"),
       (try_end),
      (agent_deliver_damage_to_agent,":grenadier",":target", ":dmg"),
       (try_end),
        (try_end)
  
  ]),

Go crazy you guys

CREDITS:
Beaver for the original script
DuskVoyager for fixing the "WTF the grenades keep blowing me up for no reason" bug.
 
Best answers
0
jacobhinds said:
Whoa, didn't know ti_on_missile_hit had a parameter for the shooter. Nice find.
Yeah, there's all sorts of cool **** you can do with triggers. it's always awesome when you find something new.
 

Nikephoros

Section Moderator
M&BWB
Best answers
0
Would it be possible to assign these to another kind of weapon, like a crossbow?
And if so, does it need to be applied on the projectile side or on the weapon itself?