local P = require "scriptbank\\physlib" local V = require "scriptbank\\vectlib" local barrels = {} local delay = 200 local pushPower = 0.0007 local random = math.random math.randomseed(os.time()) random(); random(); random() function physics_barrel_hit_sound2_init( e ) barrels[ e ] = { state = 'init' } end function physics_barrel_hit_sound2_main( e ) local bh = barrels[ e ] if bh == nil then return end local Ent = g_Entity[ e ] if bh.state == 'init' then SetEntityHealth( e, 50010 ) -- one shot bh.state = 'idle' return elseif bh.state == 'idle' and Ent.health < 50000 then bh.timer = g_Time + delay StartParticleEmitter( e ) PlaySoundIfSilent( e, 0 ) bh.state = 'delay' return else SetEntityHealth( e, 50000 ) end if bh.state == 'delay' and g_Time > bh.timer then bh.pushv = V.Create( -0.01 + random() * 0.02, 0, -0.01 + random() * 0.02 ) local v1 = V.Create( GetEntityPosAng( e ) ) local v2 = V.Create( g_PlayerPosX, g_PlayerPosY, g_PlayerPosZ ) v1 = V.Mul( V.Sub( v1, v2 ), pushPower ) v1.y = v1.y + ( 600 * pushPower ) bh.pushv = V.Mul( V.Add( bh.pushv, v1 ), 100 ) bh.rotv = V.Create( -10 + random() * 20, -10 + random() * 20, -10 + random() * 20 ) bh.timer = g_Time + 100 bh.state = 'launching' elseif bh.state == 'launching' then PushObject( Ent.obj, bh.pushv.x, bh.pushv.y, bh.pushv.z, bh.rotv.x, bh.rotv.y, bh.rotv.z ) 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 PlaySound( e, 2 ) bh.timer = g_Time + 1000 else colList = P.GetTerrainCollisionDetails( Ent.obj ) if colList ~= nil then PlaySound( e, 1 ) bh.timer = 0 end end if g_Time > bh.timer then RemoveObjectCollisionCheck( Ent.obj ) SetEntityHealth( e, 0 ) StopParticleEmitter( e ) bh.state = 'done' end end end