local P = require "scriptbank\\physlib" local barrels = {} local delay = 100 local random = math.random math.randomseed(os.time()) random(); random(); random() function physics_barrel_hit_sound_init( e ) barrels[ e ] = { state = 'init' } end function physics_barrel_hit_sound_main( e ) local bh = barrels[ e ] if bh == nil then return end local Ent = g_Entity[ e ] --PromptLocal( e, bh.state ) if bh.state == 'init' then SetEntityHealth( e, 510 ) -- one shot bh.state = 'idle' elseif bh.state == 'idle' and Ent.health < 500 then bh.timer = g_Time + delay StartParticleEmitter( e ) bh.state = 'delay' elseif bh.state == 'delay' and g_Time > bh.timer then bh.pushv = { x = -0.1 + random() * 0.2, y = 0.3 + random() * 0.2, z = -0.1 + random() * 0.2 } bh.rotv = { x = -0.1 + random() * 0.2, y = -0.1 + random() * 0.2, z = -0.1 + random() * 0.2 } bh.timer = g_Time + 100 bh.state = 'launching' elseif bh.state == 'launching' then PushObject( Ent.obj, bh.pushv.x * 100, bh.pushv.y * 100, bh.pushv.z * 100, bh.rotv.x * 100, bh.rotv.y * 100, bh.rotv.z * 100) bh.lasty = Ent.y if g_Time > bh.timer then bh.timer = g_Time + 2000 bh.state = 'launched' end elseif bh.state == 'launched' then if Ent.y < bh.lasty or g_Time > bh.timer then StopParticleEmitter( e ) AddObjectCollisionCheck( Ent.obj ) bh.timer = g_Time + 10000 bh.state = 'active' end elseif bh.state == 'active' then local colList = P.GetObjectCollisionDetails( Ent.obj ) if colList ~= nil then PlaySoundIfSilent( e, 0 ) PromptLocal( e, "Clang" ) bh.timer = g_Time + 1000 else colList = P.GetTerrainCollisionDetails( Ent.obj ) if colList ~= nil then PlaySoundIfSilent( e, 1 ) PromptLocal( e, "Dong" ) bh.timer = 0 end end if g_Time > bh.timer then RemoveObjectCollisionCheck( Ent.obj ) bh.state = 'done' end end end