local P = require "scriptbank\\physlib" local Q = require "scriptbank\\quatlib" 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 PlaySoundIfSilent(e,0) --bh.pushv = { x = -0.1 + random() * 0.2, --y = 0.3 + random() * 0.2, --z = -0.1 + random() * 0.2 } local v1 = {} local x1, y1, z1 = GetEntityPosAng(e) local x2, y2, z2 = g_PlayerPosX, g_PlayerPosY, g_PlayerPosZ local pushPower = 0.0007 x1 = x1 * pushPower y1 = y1 * pushPower z1 = z1 * pushPower x2 = x2 * pushPower y2 = y2 * pushPower z2 = z2 * pushPower v1.x = x1 - x2 v1.y = y1 - y2 + (600 * pushPower) v1.z = z1 - z2 bh.pushv = { x = v1.x, y = v1.y, z = v1.z } --PromptDuration(v1.x.." , "..v1.y.." , "..v1.z, 5000) bh.rotv = { x = -0.1 + random() * 0.2, y = -0.1 + random() * 0.2, z = -0.1 + random() * 0.2 } --bh.rotv = {x = 0, y = 0, z = 0 } 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 PlaySound( e, 2 ) --PromptLocal( e, "Clang" ) SetEntityHealth(e,0) bh.timer = g_Time + 1000 else colList = P.GetTerrainCollisionDetails( Ent.obj ) if colList ~= nil then PlaySound( e, 1 ) --PromptLocal( e, "Dong" ) SetEntityHealth(e,0) bh.timer = 0 end end if g_Time > bh.timer then RemoveObjectCollisionCheck( Ent.obj ) bh.state = 'done' end end end