local start_wheel = 0 local mod = 0 local zoom_speed = 1 --how fast you zoom while scrolling the mouse wheel local init_mod = 10 --how far to zoom in when first putting on the binoculars local min_mod = -10 --how far you can zoom out by scrolling down on the mouse wheel local max_mod = 40 --how far you can zoom in by scrolling up on the mouse wheel local call_airstrike = 1 --set to 0 if you don't want to call friendly airstrikes while using binoculars local air_strike_range = 3000 --maximum range of enemy to call airstrike (note might not work as we also need enemy to be able to "see" us) local bomber = {} bomber_destx = {} bomber_destz = {} last_weapon = nil pressed = 0 function binoculars_init_name(e,name) binoc_img = CreateSprite(LoadImage("scriptbank\\images\\binoculars.png")) --where to find the image used to display on screen while using binoculars SetSpritePosition(binoc_img,200,200) SetSpriteSize(binoc_img,100,100) weapon_name[e] = name end function binoculars_main(e) if fov == nil then fov = g_PlayerFOV end if bomber[e] == nil and call_airstrike > 0 then Prompt("no bomber for airstrike "..weapon_name[e]) for a = 1,9999 do if g_Entity[a] ~= nil then if a ~= e then if weapon_name[a] ~= nil then if weapon_name[a] == weapon_name[e] then bomber[e] = a break end end end end end else if g_MouseClick == 2 then if last_weapon == nil then last_weapon = g_PlayerGunID SetPlayerWeapons(0) end SetPlayerFOV(fov-mod) PasteSpritePosition(binoc_img,0,0) if g_MouseWheel < start_wheel then mod = mod - zoom_speed start_wheel = g_MouseWheel elseif g_MouseWheel > start_wheel then mod = mod + zoom_speed start_wheel = g_MouseWheel end if mod < min_mod then mod = min_mod elseif mod > max_mod then mod = max_mod end if call_airstrike > 0 then if g_KeyPressE == 1 and pressed == 0 then pressed = 1 if state[bomber[e]] == "wait" then for a = 1, 2999 do if g_Entity[a] ~= nil then if ai_soldier_state[a] ~= nil then if PlayerLooking(a,air_strike_range,5) == 1 and AICouldSee(g_Entity[a]['obj'],g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ) ==1 then bomber_destx[bomber[e]] = g_Entity[a]['x'] bomber_destz[bomber[e]] = g_Entity[a]['z'] state[bomber[e]] = "active" PlaySound(e,3) break end end end end end end end else if last_weapon ~= nil then SetPlayerWeapons(1) ChangePlayerWeaponID(last_weapon) last_weapon = nil mod = init_mod start_wheel = g_MouseWheel SetPlayerFOV(fov) end end end if g_KeyPressE == 0 then pressed = 0 end end function binoculars_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