Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
3,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.15 KB | None | 0 0
  1. script_name('BetterSkybox')
  2. script_version('2.0.3')
  3. script_author('guru_guru')
  4. script_description('its just a bunch of semi-spheres with some nice clouds textures that follows you around everywhere')
  5. script_dependencies('MoonAdditions')
  6. script_url('http://gtaforums.com/topic/894333-better-skybox/')
  7. script_properties('work-in-pause')
  8.  
  9.  
  10. bEnable = true
  11. bDebug = true -- Prints info to moonloader.log .
  12. bDisableClouds = true -- This also disables the moon.If you want more control over this,download MixSets (http://mixmods.blogspot.com.br/2015/12/mod-mix-sets.html) and search for DisaVlmtCloud , DisaLowCloud and DisaSkyStuff functions
  13. bGetWeatherReportEachIngameHour = false  -- This should improve script perfomance at the cost of changing the skies each hour.If you are going to mess around with the weather I recommend to disable this.
  14. bForceDisColl = false -- Should fix the 'invisible wall' while flying. (This was reported only in SA-MP)
  15. iDawn = 5 -- Hour which the sun starts to rise.
  16. iDusk = 22 -- Hour which the sun starts to fall.
  17.  
  18. -- How much the skybox will rotate on each fram
  19. fRotationSpeed = {
  20.     Sunny   = 0.001,
  21.     Cloudy  = 0.002,
  22.     Night   = 0.0,
  23.     Rainbow = 0.0
  24. }
  25.  
  26. spModelsID = {
  27.     LS_Sunny =  15134,
  28.     SF_Sunny =  15135,
  29.     LV_Sunny =  15136,
  30.     CS_Sunny =  15137,
  31.     DS_Sunny =  15138,
  32.  
  33.     LS_Cloudy = 15139,
  34.     SF_Cloudy = 15140,
  35.     LV_Cloudy = 15141,
  36.     CS_Cloudy = 15142,
  37.     DS_Cloudy = 15143,
  38.  
  39.     LS_Night =  15144,
  40.     SF_Night =  15145,
  41.     LV_Night =  15146,
  42.     CS_Night =  15147,
  43.     DS_Night =  15148,
  44.  
  45.     -- Rainbow = 15149
  46. }
  47.  
  48. sampModelsID = {
  49.     LS_Sunny =  3890,
  50.     SF_Sunny =  3892,
  51.     LV_Sunny =  3893,
  52.     CS_Sunny =  3895,
  53.     DS_Sunny =  3897,
  54.  
  55.     LS_Cloudy = 3898,
  56.     SF_Cloudy = 3899,
  57.     LV_Cloudy = 3900,
  58.     CS_Cloudy = 3901,
  59.     DS_Cloudy = 3905,
  60.  
  61.     LS_Night =  3906,
  62.     SF_Night =  3910,
  63.     LV_Night =  3914,
  64.     CS_Night =  3915,
  65.     DS_Night =  3916
  66. }
  67.  
  68. centerID = 4227
  69.  
  70. local mad = require 'MoonAdditions'
  71. local memory = require 'memory'
  72.  
  73. function main()
  74.     if readSettings() then
  75.         loadSky()
  76.         local sky = createSkies()
  77.         tG_Skies = sky
  78.         while true do
  79.             drawSky(sky)
  80.             applyPersistentSettings(sky)
  81.         end
  82.     end
  83. end
  84.  
  85. function readSettings()
  86.     if bEnable == false then return false end
  87.     if bDisableClouds == true then
  88.         memory.fill(0x53E121, 0x90, 5, true)
  89.         memory.fill(0x53E1B4, 0x90, 5, true)
  90.         memory.fill(0x53DCA2, 0x90, 5, true)
  91.         memory.fill(0x53DFA0, 0x90, 5, true)
  92.     end
  93.     return true
  94. end
  95.  
  96. function applyPersistentSettings(skies)
  97.     if bForceDisColl then
  98.         local kType,tType , kSky, hSky
  99.  
  100.         for kType,tType in pairs(skies) do
  101.             for kSky, hSky in pairs(tType) do
  102.                 setObjectCollision(hSky, false)
  103.             end
  104.         end
  105.     end
  106. end
  107.  
  108. function loadSky() -- loads ids table
  109.  
  110.     local tIDs = getIDsTable()
  111.     local key,id
  112.     for key,id in pairs(tIDs) do
  113.         requestModel(tIDs)
  114.         if bDebug then print("@load_sky(): Requesting "..key.." w/ ID "..id) end
  115.     end
  116.     requestModel(centerID)
  117.     loadAllModelsNow()
  118.     return
  119. end
  120.  
  121. function createSkies()
  122.     local sky = {}
  123.     sky.Sunny = createSky("Sunny")
  124.     sky.Cloudy = createSky("Cloudy")
  125.     sky.Night = createSky("Night")
  126.     -- sky.Rainbow = createSky("Rainbow")
  127.     return sky
  128. end
  129.  
  130. function createSky(skyType)
  131.     local new_sky = {}
  132.     local z = 0.0
  133.     local key,id
  134.  
  135.     new_sky.center = createObjectNoOffset(centerID, 0.0,0.0,0.0)
  136.     makeObjectUnsaveable(new_sky.center)
  137.     if bDebug then print("@createSkies():   "..skyType) end
  138.     hideObject(new_sky.center)
  139.     local tIDs = getIDsTable()
  140.     for key,id in pairs(tIDs) do
  141.         if string.find(key,skyType) then
  142.             if bDebug then print("@createSkies():   Attemping to create "..key.." w/ modelID "..id.."...") end
  143.             new_sky[key] = createObjectNoOffset(id, 0.0, 0.0, 0.0)
  144.             makeObjectUnsaveable(new_sky[key])
  145.             hideObject(new_sky[key])
  146.             attachObjectToObject(new_sky[key], new_sky.center, 0.0, 0.0, z, 0.0, 0.0, 0.0)
  147.             z = z + 0.1
  148.             if bDebug then print("@createSkies():   Created sky "..key.." ,modelID "..id.." and handle "..new_sky[key]) end
  149.         end
  150.     end
  151.  
  152.     return new_sky
  153. end
  154.  
  155. function drawSky(skies)
  156.     local tSkiesToDraw = getSkiesToDraw()
  157.     if bInMenu() or bInInterior() then wait(0) return end
  158.  
  159.     wait(0)
  160.  
  161.     local fWeatherInterpolation = memory.getfloat(0xC8130C,false)
  162.     if bGetWeatherReportEachIngameHour then
  163.         if fWeatherInterpolation >= 0.0 and fWeatherInterpolation <= 0.05 then
  164.             local tSkiesToDraw = getSkiesToDraw()
  165.             clearSky(skies,tSkiesToDraw)
  166.         end
  167.     else
  168.         local tSkiesToDraw = getSkiesToDraw()
  169.         clearSky(skies,tSkiesToDraw)
  170.     end
  171.  
  172.     local x,y,z = getActiveCameraCoordinates()
  173.     local kType,tType , kSky, hSky
  174.     local kStatus,kDummy
  175.  
  176.     for kSky,kStatus in pairs(tSkiesToDraw) do
  177.         for kType,tType in pairs(skies) do
  178.             if tType[kSky] ~= nil then
  179.                 drawThisSky(tType[kSky], kType, kStatus)
  180.                 moveThisSky(tType.center, kType, x,y,z)
  181.             end
  182.         end
  183.     end
  184.  
  185.     return
  186. end
  187.  
  188. function clearSky( tSky,SkiesToDraw )
  189.     local sType,tType , key,handle
  190.     for sType,tType in pairs(tSky) do
  191.         for key,handle in pairs(tType) do
  192.             if SkiesToDraw[key] == nil then
  193.                 setObjectScale(handle,0.0)
  194.                 SkiesToDraw[key] = "HIDE"
  195.                 if bDebug and testCheat("getclearSky") then print("@clearSky: set sky "..key.." scale to 0.0") end
  196.             end
  197.         end
  198.     end
  199.     return
  200. end
  201.  
  202. function drawThisSky(hSky,typeID,status)
  203.     if typeID == "Sunny" then setSkySunnyAlpha(hSky,status) end
  204.     if typeID == "Cloudy" then setSkyCloudyAlpha(hSky,status) end
  205.     if typeID == "Night" then setSkyNightAlpha(hSky,status) end
  206.     -- if typeID == "Rainbow" then setSkySunnyAlpha(hSky,status) end
  207.     setObjectScale(hSky, getScale())
  208.     return
  209. end
  210.  
  211. function moveThisSky(hCenter,kType,x,y,z)
  212.     setObjectCoordinates(hCenter, x, y, z)
  213.     local rotationSpeed = fRotationSpeed[kType] * getTimeStepValue()
  214.     local fromAngle = getObjectHeading(hCenter)
  215.     local toAngle = fromAngle + rotationSpeed
  216.     setObjectHeading(hCenter, toAngle)
  217.     return
  218. end
  219.  
  220. function deleteSky(sky)
  221.     local kType,tType , kSky, hSky
  222.     for kType,tType in pairs(sky) do
  223.         for kSky, hSky in pairs(tType) do
  224.             deleteObject(hSky)
  225.             if bDebug then print("@deleteSky: deleting obj "..kSky.." w/ handle "..hSky) end
  226.         end
  227.     end
  228.     return
  229. end
  230.  
  231. function bInSavegameMenu()
  232.     if bInMenu() then
  233.         local menuID = readMemory(0xBA68A5, 1, false)
  234.         if menuID == 6 or menuID == 9 or menuID == 11 or menuID == 13 or menuID == 17 or menuID == 18 or menuID == 19 then
  235.             return true
  236.         end
  237.     end
  238.     return false
  239. end
  240.  
  241. function bInMenu()
  242.     local bInMenu = memory.read(0xBA67A4, 1, false)
  243.     if bInMenu == 1 then return true end
  244.     return false
  245. end
  246.  
  247. function bInInterior()
  248.     if getActiveInterior() == 0 then return false end
  249.     if bDebug and testCheat("interior") then printHelpString("Yeah,you are on a Interior") end
  250.     return true
  251. end
  252.  
  253. function getSkiesToDraw()
  254.     local weather= { [1] = readMemory(0xC81320, 2, false), [2] = readMemory(0xC8131C, 2, false) }
  255.     local draw = {}
  256.     local bIsDay,bIsNight = bIsDayHours(),bIsNightHours()
  257.     local sCurrWeatherType,sNextWeatherType = "" ,""
  258.     local i
  259.  
  260.     for i = 1, #weather do
  261.         while true do
  262.  
  263.             if weather[i] >= 0 and weather[i] <= 3 then
  264.                 if bIsDay then setStatus(draw,"LS_Sunny",i) end
  265.                 if bIsNight then setStatus(draw,"LS_Night",i) end
  266.                 if i == 1 then sCurrWeatherType = "Sunny" else sNextWeatherType = "Sunny" end
  267.                 break
  268.             end
  269.             if weather[i] == 5 or weather[i] == 6 then
  270.                 if bIsDay then setStatus(draw,"SF_Sunny",i) end
  271.                 if bIsNight then setStatus(draw,"SF_Night",i) end
  272.                 if i == 1 then sCurrWeatherType = "Sunny" else sNextWeatherType = "Sunny" end
  273.                 break
  274.             end
  275.             if weather[i] == 10 or weather[i] == 11 then
  276.                 if bIsDay then setStatus(draw,"LV_Sunny",i) end
  277.                 if bIsNight then setStatus(draw,"LV_Night",i) end
  278.                 if i == 1 then sCurrWeatherType = "Sunny" else sNextWeatherType = "Sunny" end
  279.                 break
  280.             end
  281.             if weather[i] == 13 or weather[i] == 14 then
  282.                 if bIsDay then setStatus(draw,"CS_Sunny",i) end
  283.                 if bIsNight then setStatus(draw,"CS_Night",i) end
  284.                 if i == 1 then sCurrWeatherType = "Sunny" else sNextWeatherType = "Sunny" end
  285.                 break
  286.             end
  287.             if weather[i] == 17 or weather[i] == 18 then
  288.                 if bIsDay then setStatus(draw,"DS_Sunny",i) end
  289.                 if bIsNight then setStatus(draw,"DS_Night",i) end
  290.                 if i == 1 then sCurrWeatherType = "Sunny" else sNextWeatherType = "Sunny" end
  291.                 break
  292.             end
  293.             if weather[i] == 4 then
  294.                 setStatus(draw,"LS_Cloudy",i)
  295.                 if i == 1 then sCurrWeatherType = "Cloudy" else sNextWeatherType = "Cloudy" end
  296.                 break
  297.             end
  298.             if weather[i] >= 7 and weather[i] <= 9 then
  299.                 setStatus(draw,"SF_Cloudy",i)
  300.                 if i == 1 then sCurrWeatherType = "Cloudy" else sNextWeatherType = "Cloudy" end
  301.                 break
  302.             end
  303.             if weather[i] == 12 then
  304.                 setStatus(draw,"LV_Cloudy",i)
  305.                 if i == 1 then sCurrWeatherType = "Cloudy" else sNextWeatherType = "Cloudy" end
  306.                 break
  307.             end
  308.             if weather[i] == 15 or weather[i] == 16 then
  309.                 setStatus(draw,"CS_Cloudy",i)
  310.                 if i == 1 then sCurrWeatherType = "Cloudy" else sNextWeatherType = "Cloudy" end
  311.                 break
  312.             end
  313.             if weather[i] == 19 then
  314.                 setStatus(draw,"DS_Cloudy",i)
  315.                 if i == 1 then sCurrWeatherType = "Cloudy" else sNextWeatherType = "Cloudy" end
  316.                 break
  317.             end
  318.  
  319.             break
  320.  
  321.         end
  322.  
  323.     end
  324.  
  325.     -- if bIsDay and not bNight then
  326.     --  if sCurrWeatherType == "Cloudy" and sNextWeatherType == "Sunny" then draw["Rainbow"] = "FADE_IN" end
  327.     --  if sCurrWeatherType == "Sunny" and sNextWeatherType == "Cloudy" then draw["Rainbow"] = "FADE_OUT" end
  328.     -- end
  329.  
  330.     if bDebug and testCheat("getSkies") then
  331.         local kSky,kStatus
  332.         for kSky,kStatus in pairs(draw) do
  333.             print("@getSkiesToDraw(): "..kSky.." = "..kStatus)
  334.         end
  335.         printHelpString("Printed Skies to draw.")
  336.  
  337.     end
  338.  
  339.     return draw
  340. end
  341.  
  342.  
  343. function setStatus(tDraw,kSky,curr_or_next_weather)
  344.     if curr_or_next_weather == 1 and tDraw[kSky] == nil then tDraw[kSky] = "FADE_OUT" return end
  345.     if curr_or_next_weather == 2 and tDraw[kSky] == nil then tDraw[kSky] = "FADE_IN" return end
  346.     if tDraw[kSky] ~= nil then tDraw[kSky] = "SHOW" return end
  347.     if bDebug then printHelpString("setStatus is broken,pls fix  xdDDD") end
  348.     return
  349. end
  350.  
  351. function setSkySunnyAlpha(sky,status)
  352.     local bIsDay = bIsDayHours()
  353.     if status == nil or status == "HIDE"  then mad.set_object_model_alpha(sky,0)    return end
  354.     if status == "FADE_IN" and bIsDay then doFadeIn(sky) return end
  355.     if status == "FADE_OUT" and bIsDay then doFadeOut(sky) return end
  356.     if status == "SHOW" then
  357.         local hh,mm = getTimeOfDay()
  358.         local dawn,dusk = iDawn,iDusk
  359.  
  360.         if hh == dawn then doFadeIn(sky) return end
  361.         if hh > dawn and hh < dusk then mad.set_object_model_alpha(sky,255) return end
  362.         if hh == dusk then doFadeOut(sky) return end
  363.         mad.set_object_model_alpha(sky,0) return
  364.     end
  365.     return
  366. end
  367.  
  368. function setSkyCloudyAlpha(sky, status)
  369.     if status == nil or status == "HIDE"  then mad.set_object_model_alpha(sky,0)    return end
  370.     if status == "FADE_IN" then doFadeIn(sky) return end
  371.     if status == "FADE_OUT" then doFadeOut(sky) return end
  372.     if status == "SHOW" then mad.set_object_model_alpha(sky,255) return end
  373.     return
  374. end
  375.  
  376. function setSkyNightAlpha(sky, status)
  377.     local bIsNight = bIsNightHours()
  378.     if status == nil or status == "HIDE"  then mad.set_object_model_alpha(sky,0) return end
  379.     if status == "FADE_IN" and bIsNight then doFadeIn(sky) return end
  380.     if status == "FADE_OUT" and bIsNight then doFadeOut(sky) return end
  381.     if status == "SHOW" then
  382.         local hh,mm = getTimeOfDay()
  383.         local dawn,dusk = iDawn,iDusk
  384.  
  385.         if hh == dusk then doFadeIn(sky)    return end
  386.         if hh > dusk or hh < dawn then mad.set_object_model_alpha(sky,255) return end
  387.         if hh == dawn then doFadeOut(sky) return end
  388.         mad.set_object_model_alpha(sky,0) return
  389.     end
  390.     return
  391. end
  392.  
  393. function doFadeIn(sky)
  394.     local fWeatherInterpolation = memory.getfloat(0xC8130C,false) * 255.0
  395.     local alpha = math.floor(fWeatherInterpolation)
  396.     mad.set_object_model_alpha(sky,alpha)
  397.     return
  398. end
  399.  
  400. function doFadeOut(sky)
  401.     local fWeatherInterpolation = memory.getfloat(0xC8130C,false)  * -255.0
  402.     fWeatherInterpolation = fWeatherInterpolation + 255.0
  403.     local alpha = math.floor(fWeatherInterpolation)
  404.     mad.set_object_model_alpha(sky,alpha)
  405.     return
  406. end
  407.  
  408. function bIsDayHours()
  409.     local hh,mm =  getTimeOfDay()
  410.     if hh >= iDawn and hh <= iDusk then return true end
  411.     return false
  412. end
  413.  
  414. function bIsNightHours()
  415.     local hh,mm =  getTimeOfDay()
  416.     if hh >= iDusk or hh <= iDawn then return true end
  417.     return false
  418. end
  419.  
  420. function hideObject(obj)
  421.     mad.set_object_model_alpha(obj, 0)
  422.     setObjectScale(obj, 0.0)
  423.     setObjectCollision(obj, 0)
  424.     return
  425. end
  426.  
  427. function getScale()
  428.     local fScale = memory.getfloat(0xB76848,false)
  429.     fScale = fScale / 2100.0
  430.     return fScale
  431. end
  432.  
  433.  
  434. function onSaveGame()
  435.     if bDebug then print("GAME HAS BEEN SAVED!") end
  436.     return
  437. end
  438.  
  439. function getIDsTable()
  440.     if isSampLoaded() then
  441.         if bDebug then print("@getIDsTable: Using SAMP models table... ") end
  442.         return sampModelsID
  443.     end
  444.  
  445.     if bDebug then print("@getIDsTable: Using SP models table... ") end
  446.  
  447.     return spModelsID
  448. end
  449.  
  450. function makeObjectUnsaveable(obj)
  451.     local objPtr = getObjectPointer(obj)
  452.     objPtr = objPtr + 0x13C
  453.     memory.write(objPtr, 6, 1)
  454. end
  455.  
  456. function disableColl(skies)
  457.     local kType,tType , kSky, hSky
  458.     for kType,tType in pairs(sky) do
  459.         for kSky, hSky in pairs(tType) do
  460.             setObjectCollision(hSky,false)
  461.         end
  462.     end
  463. end
  464.  
  465. -- function onScriptTerminate()
  466. --  deleteSky(tG_Skies)
  467. -- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement