Hi! I tried to make hood for flashlight , but I could not . Gives an error message. Please help!
Original script :
flashlight_battery_life = {}
flashlight_battery_drain_delay = {}
local new_flashlight_battery_drain_delay = {}
local new_flicker_delay_off = nil
local new_flicker_delay_on = nil
local remaining_batteries = 0
local replace_battery_delay = 3 --how many seconds til battery reloading is complete
flashlight_batteries = 1 --number of batteries player starts with (can be 0, forcing player to have no flashlight until a battery is found)
max_flashlight_batteries = 5 --maximum batteries player can hold at one time
local flickering_on = 1 --set to 1 for flickering effect, 0 for constant on (when state is on)
local flickering_perc_start = 40 --what % of battery life the flickering will begin
local flicker_delay_off = math.random(1,3) --how many seconds before flashlight can go off again while flickering
local flicker_delay_on = 0.2 --how long til light comes back on while flickering
local current_battery = 1
local state = "off"
fpressed = 0
--sound at slot 0 is for replacing batteries
--sound at slot 1 is for clicking on/off
--set entity always active & use with flashlight_battery.lua for extra batteries
function flashlight_init(e)
flashlight_battery_life[0] = 0
flashlight_battery_drain_delay[0] = 0
for a = 1,flashlight_batteries do
flashlight_battery_life[a] = 100 --starting amount of life for the batteries
flashlight_battery_drain_delay[a] = 0.2 --how fast the batteries drain (in seconds)
end
end
function flashlight_main(e)
if flashlight_batteries == 0 then
current_battery = 0
end
SetFlashLightKeyEnabled(0)
if g_KeyPressF == 1 and fpressed < 3 then
fpressed = 2
if GetTimer(e) > (replace_battery_delay * 1000) * 0.35 then
if current_battery < flashlight_batteries then
TextCenterOnX(50,85,3,"Replacing flash light batteries...")
if GetTimer(e) > replace_battery_delay * 1000 then
PlaySoundIfSilent(e,1)
current_battery = current_battery + 1
StartTimer(e)
fpressed = 3
end
else
TextCenterOnX(50,85,3,"No spare batteries remaining...")
end
end
end
if state == "on" then
if flashlight_battery_life[current_battery] > 0 then
if new_flashlight_battery_drain_delay[current_battery] == nil then
new_flashlight_battery_drain_delay[current_battery] = g_Time + (flashlight_battery_drain_delay[current_battery]*1000)
end
if flickering_on == 1 then
if flashlight_battery_life[current_battery] <= flickering_perc_start then
if new_flicker_delay_off == nil then
new_flicker_delay_off = g_Time + (flicker_delay_off*1000)
new_flicker_delay_on = g_Time + (flicker_delay_off*1000)
end
if g_Time > new_flicker_delay_off then
SetFlashLight(0)
new_flicker_delay_on = g_Time + (flicker_delay_on*1000)
new_flicker_delay_off = g_Time + (math.random(flicker_delay_off*0.8,flicker_delay_off*1.2)*1000)
end
if g_Time > new_flicker_delay_on then
SetFlashLight(1)
end
end
end
if g_Time > new_flashlight_battery_drain_delay[current_battery] then
flashlight_battery_life[current_battery] = flashlight_battery_life[current_battery] - 1
new_flashlight_battery_drain_delay[current_battery] = g_Time + (flashlight_battery_drain_delay[current_battery]*1000)
end
else
SetFlashLight(0)
state = "off"
end
elseif state == "off" then
end
if g_KeyPressF == 0 then
StartTimer(e)
if fpressed == 2 then
PlaySound(e,0)
if state == "off" then
state = "on"
SetFlashLight(1)
else
state = "off"
SetFlashLight(0)
end
fpressed = 0
elseif fpressed == 3 then
SetFlashLight(0)
state = "off"
fpressed = 0
end
end
remaining_batteries = flashlight_batteries - current_battery
if remaining_batteries < 0 then
remaining_batteries = 0
end
TextCenterOnX(50,90,3,"spare batteries = "..remaining_batteries.." , current battery life = "..flashlight_battery_life[current_battery].."% , current drain per sec = 1% per "..flashlight_battery_drain_delay[current_battery].."s")
end --main
function flashlight_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
My script :
flashlight_battery_life = {}
flashlight_battery_drain_delay = {}
local new_flashlight_battery_drain_delay = {}
local new_flicker_delay_off = nil
local new_flicker_delay_on = nil
local remaining_batteries = 0
local replace_battery_delay = 3 --how many seconds til battery reloading is complete
flashlight_batteries = 1 --number of batteries player starts with (can be 0, forcing player to have no flashlight until a battery is found)
max_flashlight_batteries = 5 --maximum batteries player can hold at one time
local flickering_on = 1 --set to 1 for flickering effect, 0 for constant on (when state is on)
local flickering_perc_start = 40 --what % of battery life the flickering will begin
local flicker_delay_off = math.random(1,3) --how many seconds before flashlight can go off again while flickering
local flicker_delay_on = 0.2 --how long til light comes back on while flickering
local sprite_duration = 6000
FlashlightImage1 = 0
FlashlightSprite1 = 0
FlashlightImage2 = 0
FlashlightSprite2 = 0
local current_battery = 1
local state = "off"
fpressed = 0
--sound at slot 0 is for replacing batteries
--sound at slot 1 is for clicking on/off
--set entity always active & use with flashlight_battery.lua for extra batteries
function flashlight_init(e)
FlashlightImage1 = LoadImage ( "scriptbank\\images\\Flashlight\\Flashlight1.png" )
FlashlightSprite1 = CreateSprite ( FlashlightImage1 )
FlashlightImage2 = LoadImage ( "scriptbank\\images\\Flashlight\\Flashlight2.png" )
FlashlightImage3 = LoadImage ( "scriptbank\\images\\Flashlight\\Flashlight3.png" )
FlashlightImage3 = LoadImage ( "scriptbank\\images\\Flashlight\\Flashlight4.png" )
flashlight_battery_life[0] = 0
flashlight_battery_drain_delay[0] = 0
for a = 1,flashlight_batteries do
flashlight_battery_life[a] = 100 --starting amount of life for the batteries
flashlight_battery_drain_delay[a] = 0.2 --how fast the batteries drain (in seconds)
end
end
function flashlight_main(e)
if flashlight_batteries_life > 100 then
flashlight_batteries_life = 100
end
if flashlight_batteries == 0 then
current_battery = 0
end
SetFlashLightKeyEnabled(0)
if g_KeyPressF == 1 and fpressed < 3 then
fpressed = 2
if GetTimer(e) > (replace_battery_delay * 1000) * 0.35 then
if current_battery < flashlight_batteries then
TextCenterOnX(50,85,3,"Replacing flash light batteries...")
if GetTimer(e) > replace_battery_delay * 1000 then
PlaySoundIfSilent(e,1)
current_battery = current_battery + 1
StartTimer(e)
fpressed = 3
end
else
TextCenterOnX(50,85,3,"No spare batteries remaining...")
end
end
end
if state == "on" then
if flashlight_battery_life[current_battery] > 0 then
if new_flashlight_battery_drain_delay[current_battery] == nil then
new_flashlight_battery_drain_delay[current_battery] = g_Time + (flashlight_battery_drain_delay[current_battery]*1000)
end
if flickering_on == 1 then
if flashlight_battery_life[current_battery] <= flickering_perc_start then
if new_flicker_delay_off == nil then
new_flicker_delay_off = g_Time + (flicker_delay_off*1000)
new_flicker_delay_on = g_Time + (flicker_delay_off*1000)
end
if g_Time > new_flicker_delay_off then
SetFlashLight(0)
new_flicker_delay_on = g_Time + (flicker_delay_on*1000)
new_flicker_delay_off = g_Time + (math.random(flicker_delay_off*0.8,flicker_delay_off*1.2)*1000)
end
if g_Time > new_flicker_delay_on then
SetFlashLight(1)
end
end
end
if g_Time > new_flashlight_battery_drain_delay[current_battery] then
flashlight_battery_life[current_battery] = flashlight_battery_life[current_battery] - 1
new_flashlight_battery_drain_delay[current_battery] = g_Time + (flashlight_battery_drain_delay[current_battery]*1000)
end
else
SetFlashLight(0)
state = "off"
end
elseif state == "off" then
end
if g_KeyPressF == 0 then
StartTimer(e)
if fpressed == 2 then
PlaySound(e,0)
if state == "off" then
state = "on"
SetFlashLight(1)
else
state = "off"
SetFlashLight(0)
end
fpressed = 0
elseif fpressed == 3 then
SetFlashLight(0)
state = "off"
fpressed = 0
end
end
remaining_batteries = flashlight_batteries - current_battery
if remaining_batteries < 0 then
remaining_batteries = 0
end
TextCenterOnX(50,90,3,"spare batteries = "..remaining_batteries.." , current battery life = "..flashlight_battery_life[current_battery].."% , current drain per sec = 1% per "..flashlight_battery_drain_delay[current_battery].."s")
if flashlight_battery_life > 70 then
SetSpriteImage ( FlashlightSprite1 , FlashlightImage1 )
end
if flashlight_battery_life < 70 and flashlight_battery_life > 30 then
SetSpriteImage ( FlashlightSprite1 , FlashlightImage2 )
end
if flashlight_battery_life < 30 and flashlight_battery_life > 1 then
SetSpriteImage ( FlashlightSprite1 , FlashlightImage3 )
end
if flashlight_battery_life < 1 then
SetSpriteImage ( FlashlightSprite1 , FlashlightImage4 )
end
end --main
function flashlight_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