Thanks and i got other question... do u know why the VEHICLE GUNNER SCRIPT overpass al entities like a ghost?+
local enter_range = {}
local enter_angle = {}
local pos_mod = {}
local pos_y = {}
local pos_x = nil
local pos_z = nil
local posy = nil
local state = {}
local speed = {}
local max_speed = {}
local min_speed = {}
local turn_speed = {}
local acceleration = {}
local decceleration = {}
local impact_range = {}
local impact_angle = {}
local angle_mod = {}
local health = {}
local old_health = nil
local vpressed = 0
function vehicle_gunner_init(e)
enter_range[e] = 200 --how close player needs to be to mount the vehicle
enter_angle[e] = 35 --player looking at the vehicle (smaller = tighter angle)
pos_mod[e] = 60 --how far back/forward in the vehicle the player will be (negative value = backwards)
pos_y[e] = 20 --how high above/below the vehicle height the player will be
max_speed[e] = 150 --top speed for the vehicle
min_speed[e] = -20 --top reversing speed
acceleration[e] = 2 --how quickly the vehicle gains speed (in reverse too)
decceleration[e] = 1 --how quickly the vehicle slows down if player not pressing W or S
turn_speed[e] = 1 --how quickly the vehicle turns
impact_range[e] = 200 --when enemies will get run over
impact_angle[e] = 20 --adjusts angle for when enemies will get run over (smaller value = narrow vehicle)
health[e] = 1000 --how much health to give vehicle (adjusts player health while in the vehicle)
angle_mod[e] = 0 --if you want the player to face a different direction (other than forward) when first entering the vehicle
state[e] = "wait"
speed[e] = 0
end
function vehicle_gunner_main(e)
if state[e] == "wait" then
CollisionOn(e)
if PlayerLooking(e,enter_range[e],enter_angle[e]) == 1 then
Prompt("Mount the gun? *E*")
if g_KeyPressE == 1 and vpressed == 0 then
vpressed = 1
old_health = g_PlayerHealth
SetPlayerHealth(health[e])
new_y = math.rad(g_Entity[e]['angley'])
pos_x = g_Entity[e]['x'] + (math.sin(new_y) * pos_mod[e])
pos_z = g_Entity[e]['z'] + (math.cos(new_y) * pos_mod[e])
SetFreezePosition(pos_x,g_Entity[e]['y']+pos_y[e],pos_z)
SetFreezeAngle(g_Entity[e]['anglex'],g_Entity[e]['angley']+angle_mod[e],g_Entity[e]['anglez'])
TransportToFreezePosition()
state[e] = "drive"
end
end
elseif state[e] == "drive" then
new_y = math.rad(g_Entity[e]['angley'])
pos_x = g_Entity[e]['x'] + (math.sin(new_y) * pos_mod[e])
pos_z = g_Entity[e]['z'] + (math.cos(new_y) * pos_mod[e])
SetFreezePosition(pos_x,g_Entity[e]['y']+pos_y[e],pos_z)
TransportToFreezePositionOnly()
if g_KeyPressW == 1 then
if speed[e] < max_speed[e] then
speed[e] = speed[e] + acceleration[e]
else
speed[e] = max_speed[e]
end
elseif g_KeyPressS == 1 then
if speed[e] > min_speed[e] then
speed[e] = speed[e] - acceleration[e]
else
speed[e] = min_speed[e]
end
else
if speed[e] > 0 then
speed[e] = speed[e] - decceleration[e]
elseif speed[e] < 0 then
speed[e] = speed[e] + decceleration[e]
end
end
CollisionOff(e)
new_y = math.rad(g_Entity[e]['angley'])
pos_x = g_Entity[e]['x'] + (math.sin(new_y) * (speed[e]/10))
pos_z = g_Entity[e]['z'] + (math.cos(new_y) * (speed[e]/10))
posy = GetTerrainHeight(pos_x,pos_z)
SetPosition(e,pos_x,posy,pos_z)
if g_KeyPressA == 1 then
SetRotation(e,g_Entity[e]['anglex'],g_Entity[e]['angley']-turn_speed[e],g_Entity[e]['anglez'])
elseif g_KeyPressD == 1 then
SetRotation(e,g_Entity[e]['anglex'],g_Entity[e]['angley']+turn_speed[e],g_Entity[e]['anglez'])
end
if speed[e] > 0 - (max_speed[e]/10) and speed[e] < 0 + (max_speed[e]/10) then
Prompt("Leave the gun? *E*")
else
if GetTimer(e) > 50 then
StartTimer(e)
for a = 1,9999 do
if g_Entity[a] ~= nil then
if ai_soldier_state[a] ~= nil then
if g_Entity[a]['health'] > 0 then
if (EntityLooking(e,a,impact_range[e],impact_angle[e]) == 1 and speed[e] > 0) or (EntityLooking(e,a,impact_range[e],360-impact_angle[e]) == 0 and GetDistance(e,a) < impact_range[e] and speed[e] < 0) then
SetEntityHealth(a,0)
SetEntityRagdollForce(a,"head",g_Entity[a]['x']-g_Entity[e]['x'],10,g_Entity[a]['z']-g_Entity[e]['z'],math.random(math.abs(speed[e])*100,math.abs(speed[e])*150))
end
end
end
end
end
end
end
if g_KeyPressE == 1 and speed[e] > 0 - (max_speed[e]/10) and speed[e] < 0 + (max_speed[e]/10) and vpressed == 0 then
vpressed = 1
speed[e] = 0
new_y = math.rad(g_Entity[e]['y'])
health[e] = g_PlayerHealth
pos_x = g_Entity[e]['x'] + (math.sin(new_y) * enter_range[e])
pos_z = g_Entity[e]['z'] + (math.cos(new_y) * enter_range[e])
SetFreezePosition(pos_x,GetTerrainHeight(pos_x,pos_y),pos_z)
--TransportToFreezePositionOnly()
CollisionOn(e)
SetPlayerHealth(old_health)
state[e] = "wait"
end
if g_PlayerHealth < 1 then
SetEntityHealth(e,0)
end
end
if g_KeyPressE == 0 then
vpressed = 0
end
end
function vehicle_gunner_exit(e)
end
function PlayerLooking(e,dis,v)
if g_Entity[e] ~= nil then
if dis == nil then
dis = 3000
end
if v == nil then
v = 0.5
end
if GetPlayerDistance(e) <= dis then
local destx = g_Entity[e]['x'] - g_PlayerPosX
local destz = g_Entity[e]['z'] - g_PlayerPosZ
local angle = math.atan2(destx,destz)
angle = angle * (180.0 / math.pi)
if angle <= 0 then
angle = 360 + angle
elseif angle > 360 then
angle = angle - 360
end
while g_PlayerAngY < 0 or g_PlayerAngY > 360 do
if g_PlayerAngY <= 0 then
g_PlayerAngY = 360 + g_PlayerAngY
elseif g_PlayerAngY > 360 then
g_PlayerAngY = g_PlayerAngY - 360
end
end
local L = angle - v
local R = angle + v
if L <= 0 then
L = 360 + L
elseif L > 360 then
L = L - 360
end
if R <= 0 then
R = 360 + R
elseif R > 360 then
R = R - 360
end
if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then
return 1
elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then
return 1
else
return 0
end
else
return 0
end
end
end
function EntityLooking(e,t,dis,v)
if g_Entity[e] ~= nil and g_Entity[t] ~= nil then
if dis == nil then
dis = 3000
end
if v == nil then
v = 0.5
end
local destx = g_Entity[t]['x'] - g_Entity[e]['x']
local destz = g_Entity[t]['z'] - g_Entity[e]['z']
if math.sqrt((destx*destx)+(destz*destz)) <= dis then
local angle = math.atan2(destx,destz)
angle = angle * (180.0 / math.pi)
if angle <= 0 then
angle = 360 + angle
elseif angle > 360 then
angle = angle - 360
end
while g_Entity[e]['angley'] < 0 or g_Entity[e]['angley'] > 360 do
if g_Entity[e]['angley'] <= 0 then
g_Entity[e]['angley'] = 360 + g_Entity[e]['angley']
elseif g_Entity[e]['angley'] > 360 then
g_Entity[e]['angley'] = g_Entity[e]['angley'] - 360
end
end
local L = angle - v
local R = angle + v
if L <= 0 then
L = 360 + L
elseif L > 360 then
L = L - 360
end
if R <= 0 then
R = 360 + R
elseif R > 360 then
R = R - 360
end
if (L < R and math.abs(g_Entity[e]['angley']) > L and math.abs(g_Entity[e]['angley']) < R) then
return 1
elseif (L > R and (math.abs(g_Entity[e]['angley']) > L or math.abs(g_Entity[e]['angley']) < R)) then
return 1
else
return 0
end
else
return 0
end
end
end
function GetDistance(e,v)
if g_Entity[e] ~= nil and g_Entity[e] ~= 0 and g_Entity[v] ~= nil and g_Entity[v] ~= 0 then
local disx = g_Entity[e]['x'] - g_Entity[v]['x']
local disz = g_Entity[e]['z'] - g_Entity[v]['z']
local disy = g_Entity[e]['y'] - g_Entity[v]['y']
return math.sqrt(disx^2 + disz^2 + disy^2)
end
end