local gun_shot = {} function gun_shot_init(e) CollisionOff(e) Scale(e, 80) Hide(e) end function FireGunShot(x,y,z,xi,yi,zi,soundVolume) for k,v in pairs (gun_shot) do if not v.used then gun_shot[k] = {x = x, y = y, z = z, xi = xi, yi = yi, zi = zi, used = true, expiry_time = g_Time + 5000} Show(k) PlaySoundIfSilent(k, 0) SetSoundVolume(soundVolume) return end end end local function CloserThan(x, z, dist) local dX, dZ = x - g_PlayerPosX, z - g_PlayerPosZ return (dX*dX + dZ*dZ) < dist*dist end function gun_shot_main(e) local vars = gun_shot[e] if vars == nil then local Ent = g_Entity[e] if Ent ~= nil then gun_shot[e] = {x = 0, y = 0, z = 0, xi = 0, yi = 0, zi = 0, used = false, expiry_time = math.huge}; end return elseif vars.used then vars.x = vars.x + vars.xi vars.y = vars.y + vars.yi vars.z = vars.z + vars.zi local terrH = GetTerrainHeight(vars.x, vars.z) if vars.y < terrH or g_Time > vars.expiry_time then -- shot has hit the ground or expired Hide(e) gun_shot[e].used = false gun_shot[e].expiry_time = math.huge return end if CloserThan (vars.x, vars.z, 40) then HurtPlayer(e, 1) Hide(e) gun_shot[e].used = false gun_shot[e].expiry_time = math.huge end ResetPosition(e, vars.x, vars.y, vars.z) RotateToCamera(e) end end