
old_time = {}
local impact_delay = {}
x_pos_mod = {}
z_pos_mod = {}
new_y = 0
local pos_x = 0
local pos_z = 0
local damage_range = {}
local bullet_speed = {}
local damage = {}
fired_gun = {}
local max_distance = {}
impacted = {}

function shiprpg_init_name(e,name)
weapon_name[e] = tonumber(name)

impact_delay[1] = 10
impact_delay[2] = 50


fired_gun[1] = 0
fired_gun[2] = 0

damage_range[1] = 190
damage_range[2] = 190

bullet_speed[1] = 5000
bullet_speed[2] = 2500
max_distance[1] = 50
max_distance[2] = 100

damage[1] = 10
damage[2] = 100

x_pos_mod[e] = 250
z_pos_mod[e] = 250 

Hide(e)
CollisionOff(e)
old_time[e] = g_Time + impact_delay[weapon_name[e]]
impacted[e] = 0
end 


function shiprpg_main(e)

if fired_gun[weapon_name[e]] ~= nil then
if fired_gun[weapon_name[e]] == 1 then
impacted[e] = 0
StopParticleEmitter(e)
CollisionOff(e)
new_y = math.rad(g_Entity[playership]['angley'])
pos_x = g_PlayerPosX + (math.sin(new_y) * x_pos_mod[e])
pos_z = g_PlayerPosZ + (math.cos(new_y) * z_pos_mod[e])
SetPosition(e,pos_x,g_PlayerPosY-60,pos_z)
SetRotation(e,g_PlayerAngX,g_Entity[playership]['angley']+180,g_PlayerAngZ)
old_time[e] = g_Time + (impact_delay[weapon_name[e]] * 5)
fired_gun[weapon_name[e]] = 2 
PlaySound(e,0)
StartParticleEmitter(e)

elseif fired_gun[weapon_name[e]] > 1 and fired_gun[weapon_name[e]] < max_distance[weapon_name[e]] then

MoveForward(e,bullet_speed[weapon_name[e]])
fired_gun[weapon_name[e]] = fired_gun[weapon_name[e]] + 1 
if impacted[e] == 0 then
Show(e)
if g_Time > old_time[e] then
old_time[e] = g_Time + impact_delay[weapon_name[e]]
for a = 1,9999 do
if g_Entity[a] ~= nil and a ~= e and weapon_name[a] == nil then
if GetDistance(e,a) < damage_range[weapon_name[e]] and GetPlayerDistance(e) > damage_range[weapon_name[e]] then
SetEntityHealth(a,g_Entity[a]['health'] - damage[weapon_name[e]])
PlaySound(e,1)
impacted[e] = 1 
StopParticleEmitter(e)
Hide(e)
end 
end 
end 
end 
end 
else 
Hide(e)
impacted[e] = 0
fired_gun[weapon_name[e]] = 0
StopParticleEmitter(e)
new_y = math.rad(g_PlayerAngY)
pos_x = g_PlayerPosX + (math.sin(new_y) * x_pos_mod[e])
pos_z = g_PlayerPosZ + (math.cos(new_y) * z_pos_mod[e])
SetPosition(e,pos_x,g_PlayerPosY-60,pos_z)
SetRotation(e,g_PlayerAngX,g_PlayerAngY,g_PlayerAngZ)
old_time[e] = g_Time + (impact_delay[weapon_name[e]] * 1.5)
end 
end

end --main(e)

function shiprpg_exit(e)

end 