Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Weather simulation resource by vovo4ka
- -- e-mail: zolotayapipka@gmail.com
- -- client side script
- -- v 1.0
- -- Dyanmic weather
- cyclones = {{0,0,0},{0,0,0},{0,0,0}}
- function CycAcc ( x1,y1,r1,x2,y2,r2,x3,y3,r3 )
- cyclones[1][1] = x1
- cyclones[1][2] = y1
- cyclones[1][3] = r1
- cyclones[2][1] = x2
- cyclones[2][2] = y2
- cyclones[2][3] = r2
- cyclones[3][1] = x3
- cyclones[3][2] = y3
- cyclones[3][3] = r3
- end
- addEvent( "AcceptCyclones", true )
- addEventHandler( "AcceptCyclones", getRootElement(), CycAcc )
- -----------------------------
- -- Constant weather.
- -- Weather patterns. You can change it to make more realistic weather
- -- Every number means half of hour.
- -- For example weather id 12 -> 00:00 am 12 - > 00:30 am 15 -> 1:00 am
- weat_city = {12,12,15,15,66,66,12,12,61,58,63,28,28,28,6,11,11,11,11,11,11,11,2,2,14,14,14,14,34,34,34,34,1,1,1,1,17,17,18,3,3,3,3,3,1,0,3,3}
- weat_green = {1,1,54,1,1,1,9,1,61,58,63,28,28,28,6,11,11,11,11,11,11,11,2,2,14,14,14,14,34,34,34,34,1,1,1,1,17,17,18,3,3,3,2,1,1,0,3,3}
- weat_desert = {1,1,1,1,1,19,1,1,61,61,58,28,28,28,18,11,11,11,11,11,11,11,2,2,14,14,14,14,34,34,34,34,1,1,1,1,17,17,18,18,2,2,2,1,1,0,3,19}
- weat_lv = {12,12,15,15,66,66,12,12,61,58,28,28,28,28,18,11,11,11,11,11,11,11,2,2,14,14,14,14,34,34,34,34,1,1,1,1,17,17,18,3,3,3,2,1,1,0,3,3}
- weat_zone= --Const Weather Map -- it looks noobly. but allows precisely determine land type
- { -- Terrain type 1 - forest 2 - city 4 - desert 8 - LV (desert+city)
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1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
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
- }
- function WeatherStep(imm)
- if ( getElementInterior(getLocalPlayer()) == 0 ) then -- if outside
- local hour, mins = getTime ()
- hour = hour * 2
- if (mins>=30) then
- hour = hour + 1
- end
- local x,y,z = getElementPosition(getLocalPlayer())
- local px = math.floor((x+4000)/200)
- local py = math.floor((y+4000)/200)
- if (px<1) then
- px = 1
- elseif (px>40) then
- px = 40
- end
- if (py<1) then
- py = 1
- elseif (py>40) then
- py = 40
- end
- py = 41 - py
- local zone = weat_zone[py][px]
- if (zone == 2) then
- weat = weat_city[hour]
- elseif (zone == 4) then
- weat = weat_desert[hour]
- elseif (zone == 8) then
- weat = weat_lv[hour]
- else
- weat = weat_green[hour]
- end
- -- cyclones
- local cyc_power = 0
- for i, cyc in pairs(cyclones) do
- if (cyc[3]>0) then
- local dist = getDistanceBetweenPoints2D (x, y, cyc[1], cyc[2])
- if (cyc[3]>600) then -- if radius more than 300
- if (dist<cyc[3]/4) then -- center of cyclone - rain
- cyc_power = math.max(cyc_power,3)
- elseif (dist<cyc[3]*1/2) then -- very cloudly
- cyc_power = math.max(cyc_power,2)
- elseif (dist<cyc[3]) then -- cloudly
- cyc_power = math.max(cyc_power,1)
- end
- else
- if (dist<cyc[3]/2) then --
- cyc_power = math.max(cyc_power,2)
- elseif (dist<cyc[3]) then --
- cyc_power = math.max(cyc_power,1)
- end
- end
- end
- end
- if (cyc_power==3) then
- if (zone==4) then -- sandstorm
- weat = 18
- else
- weat = 8 -- rain
- end
- elseif (cyc_power==2) then
- if ((hour>2)and(hour<38)) then
- weat = 31 -- very cloudly
- else
- weat = 20
- end
- elseif (cyc_power==1) then
- weat = 7 -- cloudly
- end
- if (imm==0) then
- --setWeatherBlended ( weat, delay ) -- ;( I need this function
- setWeather( weat )
- else
- setWeather( weat )
- end
- --a,b = getWeather()
- --outputChatBox(a.." "..b)
- --outputChatBox(zone)
- end
- end
- function OnSpawn()
- if (source==getLocalPlayer()) then
- WeatherStep(1)
- end
- end
- addEventHandler ( "onClientPlayerSpawn", getLocalPlayer(), OnSpawn )
- setTimer ( WeatherStep, 10000, 0, 0)
- function weatherConfig ()
- setTrafficLightsLocked(false)
- setMinuteDuration(60000)
- setTrafficLightState(9)
- end
- addEventHandler("onClientResourceStart",getRootElement(),weatherConfig)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement