thisi is the flashlight 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 new_regen_delay = 0
local replace_battery_delay = 3 --how many seconds til battery reloading is complete
flashlight_batteries = 0 --number of batteries player starts with (can be 0, forcing player to have no flashlight until a battery is found *note, the flashlight will still have a battery inside it so remember to set regen_delay to a very high number)
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 regen_while_off = 0 --set to 0 to turn battery automatically restore power while off
local regen_delay = 10 --this is actually a modifier and multiplies the drain speed by this to get the value (so a drain of 0.5s becomes 2s to restore 1% at 4)
local current_battery = 0
local state = "off"
fpressed = 0
local timer = {}
local show_battery_icon = 1 --set to 0 if you aren't using spare batteries and don't want the sprite icon to appear on screen
local fl_i = LoadImage("scriptbank\\images\\flashlight\\fl_icon.png") --path to the flash light icon images\\flashlight\\fl_icon
local fl_sprite_posx = 13 --x position of the flashlight image on screen (% of screen)
local fl_sprite_posy = 86 --y position of the flashlight image on screen (% of screen)
local fl_sprite_sizex = 10 --x size of the flashlight image on screen (% of screen)
local fl_sprite_sizey = 13 --y size of the flashlight image on screen (% of screen)
local flb_i = LoadImage("scriptbank\\images\\flashlight\\flb_icon.png") --path the the battery image
local flb_sprite_posx = 23
local flb_sprite_posy = 92
local flb_sprite_sizex = 5
local flb_sprite_sizey = 7
flashlight_batteries_txt = flashlight_batteries
local is_flashight_active = {}
--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 flashlight3_init(e)
flashlight_battery_life[0] = 0
flashlight_battery_drain_delay[0] = 0
SetFlashLightKeyEnabled(0)
is_flashlight_active = 0
if flashlight_batteries > 0 then
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) original 0.2
end
end
timer[e] = 0
end
function flashlight3_main(e)
if is_flashlight_active == 1 then
if fl_sprite == nil and fl_i ~= nil then
fl_sprite = CreateSprite(fl_i)
SetSpriteSize(fl_sprite,fl_sprite_sizex,fl_sprite_sizey)
if show_battery_icon == 1 then
if flb_sprite == nil and flb_i ~= nil then
flb_sprite = CreateSprite(flb_i)
SetSpriteSize(flb_sprite,flb_sprite_sizex,flb_sprite_sizey)
end
end
else
if flashlight_batteries == 0 then
current_battery = 0
end
SetFlashLightKeyEnabled(0)
if g_KeyPressF == 1 and fpressed < 3 then
fpressed = 2
if os.time() > timer[e] + (replace_battery_delay * 0.35) then
if current_battery < flashlight_batteries then
TextCenterOnX(50,85,3,"Replacing flash light batteries...")
if os.time() > timer[e] + replace_battery_delay then
PlaySoundIfSilent(e,1)
current_battery = current_battery + 1
flashlight_batteries_txt = flashlight_batteries_txt - 1
timer[e] = os.time()
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)
new_regen_delay = g_Time + regen_delay
state = "off"
PlaySound(e,0)
end
elseif state == "off" then
if regen_while_off == 1 then
if g_Time > new_regen_delay then
new_regen_delay = g_Time + ((flashlight_battery_drain_delay[current_battery]*1000)*regen_delay)
if flashlight_battery_life[current_battery] < 100 then
flashlight_battery_life[current_battery] = flashlight_battery_life[current_battery] + 1
end
end
end
end
if g_KeyPressF == 0 then
timer[e] = os.time()
if fpressed == 2 then
PlaySound(e,0)
if state == "off" then
state = "on"
SetFlashLight(1)
else
new_regen_delay = g_Time + ((flashlight_battery_drain_delay[current_battery]*1000)*regen_delay)
state = "off"
SetFlashLight(0)
end
fpressed = 0
elseif fpressed == 3 then
new_regen_delay = g_Time + ((flashlight_battery_drain_delay[current_battery]*1000)*regen_delay)
SetFlashLight(0)
state = "off"
fpressed = 0
end
end
SetSpritePosition(fl_sprite,fl_sprite_posx,fl_sprite_posy)
PasteSprite(fl_sprite)
TextCenterOnX(fl_sprite_posx+(fl_sprite_sizex/1.5),fl_sprite_posy+(fl_sprite_sizey/2),3," "..flashlight_battery_life[current_battery].."%")
SetSpritePosition(fl_sprite,200,200)
if show_battery_icon == 1 then
SetSpritePosition(flb_sprite,flb_sprite_posx,flb_sprite_posy)
PasteSprite(flb_sprite)
TextCenterOnX(flb_sprite_posx+(flb_sprite_sizex/1.5),flb_sprite_posy+(flb_sprite_sizey/2),3," x "..flashlight_batteries_txt)
SetSpritePosition(flb_sprite,200,200)
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
end --main
function flashlight3_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
end
this is the flashlight equipped script
--set this to the name of the weapon your player will use as the flashlight
--note that any \ must be doubled i.e. "modern\\colt1911"
local weapon_name = "modern\\JC Leon\\Flashlight"
--if you're unsure what that would be then set show_weapon_names = 1 and equip the desired weapon
local show_weapon_names = 1
--should the flashlight be on when equipped?
local turnOnWhenEquipped = 0
local held_weapon = ""
function flashlight_equipped_init(e)
SetFlashLightKeyEnabled(0)--JC LEON Addon
end
function flashlight_equipped_main(e)
if show_weapon_names == 1 then
Prompt(g_PlayerGunName)
end
--only trigger the check when player changes weapon
if g_PlayerGunName ~= held_weapon then
--holding the flashlight
if g_PlayerGunName == weapon_name then
SetFlashLightKeyEnabled(1)
is_flashlight_active = 1
--check if flashlight should start on or not when player holds it (otherwise he can toggle it as normal with F)
if turnOnWhenEquipped == 1 then
SetFlashLight(1)
else
SetFlashLight(0)
end
else --not holding the flashlight
SetFlashLightKeyEnabled(0)
SetFlashLight(0)
is_flashlight_active = 0
end
--set the current weapon so we don't repeat the check til weapon is changed
held_weapon = g_PlayerGunName
end
end
and this is the flashlight pickup script
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Weapon
pressed = 0
local U = require "scriptbank\\utillib"
function weapon3flashlight_init_name(e,name)
weapon_name[e] = name
Include( "utillib.lua" )
g_mouse_sprite = CreateSprite(LoadImage ( "scriptbank\\examine_stuff\\cursor.png"))
SetSpriteOffset(g_mouse_sprite, -1 , 1.5)
SetSpriteSize (g_mouse_sprite, -1 , 3)
SetSpriteDepth (g_mouse_sprite, 0)
SetSpritePosition (g_mouse_sprite, 200, 200)
g_hand_sprite = CreateSprite(LoadImage ( "scriptbank\\examine_stuff\\hand.png"))
SetSpriteOffset(g_hand_sprite, -1 , 1.5)
SetSpriteSize (g_hand_sprite, -1 , 3)
SetSpriteDepth (g_hand_sprite, 0)
SetSpritePosition (g_hand_sprite, 200, 200)
end
local function ShowSprite(spr)
if spr == g_hand_sprite then
SetSpritePosition (g_mouse_sprite, 200, 200)
SetSpritePosition (g_hand_sprite, 50, 50)
else
SetSpritePosition (g_mouse_sprite, 50, 50)
SetSpritePosition (g_hand_sprite, 200, 200)
end
end
function weapon3flashlight_main(e)
if U.PlayerLookingAt( e, 150 ) then
if g_PlayerGunCount < 9 then
if g_PlayerGunID > 0 then
if g_PlayerController==0 then
ShowSprite(g_hand_sprite)
--PromptLocal (e,"Press E to pick up the " .. weapon_name[e] .. " or T to replace" )
TextColor(40,40,1,"Press E to pick up the " .. weapon_name[e] .. " or T to replace",255,0,0)
else
ShowSprite(g_hand_sprite)
PromptLocal (e,"Press Y Button to pick up the " .. weapon_name[e] )
end
else
if g_PlayerController==0 then
ShowSprite(g_hand_sprite)
--PromptLocal (e,"Press E To pick up the " .. weapon_name[e] )
TextColor(42,40,1,"Press E to pick up the " .. weapon_name[e] ,255,0,0)
else
ShowSprite(g_hand_sprite)
PromptLocal (e,"Press Y Button to pick up the " .. weapon_name[e] )
end
end
if g_KeyPressE == 1 and pressed == 0 then
ShowSprite(g_mouse_sprite)
--PromptDuration("Collected the " .. weapon_name[e],3000)
TextColor(40,40,1,"Collected the " .. weapon_name[e],255,0,0)
PlaySound(e,0)
AddPlayerWeapon(e)
--is_flashlight_active = 1
SetFlashLightKeyEnabled(1)
Show(3)
Destroy(e)
ActivateIfUsed(e)
pressed = 1
end
else
if g_PlayerController==0 then
if g_PlayerGunID > 0 then
ShowSprite(g_hand_sprite)
--PromptLocal (e,"Press T to replace with " .. weapon_name[e] )
TextColor(40,40,1,"Press T to replace with " .. weapon_name[e] ,255,0,0)
else
ShowSprite(g_hand_sprite)
--PromptLocal (e,"Cannot collect any more weapons" )
TextColor(40,40,1,"Cannot collect any more weapons ",255,0,0)
end
else
PromptLocal (e,"Cannot collect any more weapons" )
end
end
if GetScancode() == 20 and g_PlayerGunID > 0 and pressed == 0 then
PromptDuration("Replaced with " .. weapon_name[e],3000)
PlaySound(e,0)
ReplacePlayerWeapon(e)
Destroy(e)
ActivateIfUsed(e)
pressed = 1
end
end
if g_KeyPressE == 0 and GetScancode() ~= 20 then
pressed = 0
end
end
smallg knows all of them LOL
PC Specs:
AMD QUADCORE 880K @4.5GHZ, 32GB RAM DDR3 1600, M/B ASUS A88XM-PLUS
SVGA NVDIA 1660GTX 6GB , SSD KINGSTON A400 1TB, 2X HHD SEAGATE BARRACUDA 4TB