| Mirage Source http://miragesource.net/forums/ |
|
| Weather System http://miragesource.net/forums/viewtopic.php?f=210&t=1482 |
Page 1 of 3 |
| Author: | Matt2 [ Fri Mar 09, 2007 10:39 pm ] |
| Post subject: | Weather System |
Always wanted weather for your game? Always thought you could do it yourself? Tried the weather from the old forms and aren't happy with it's results? You've come to the right place! This is from Konfuze's source, or whatever they wanna call it now..(Elysium... Diamond..?) Anyways... Don't add this unless you've saved your code. Level of Dificulty: 1/5(Just C&P and Understand...) First, and foremost, back up your code. Second, Open the Server. This is the only thing you have to add. Change Code: ' Lets change the weather if its time to If WeatherSeconds >= 60 Then i = Int(Rnd * 3) If i <> GameWeather Then GameWeather = i Call SendWeatherToAll End If WeatherSeconds = 0 End If To read Code: ' Lets change the weather if its time to If WeatherSeconds >= 18600 / 2 Then i = Int(Rnd * 3) If i <> GameWeather Then GameWeather = i Call SendWeatherToAll Call PutVar(FileName, "Weather", "Weather", Trim(GameWeather)) End If WeatherSeconds = 0 End If That just checks for half a day(12 hours, irl) and changes the weather randomly. Also, uncomment this line Code: WeatherSeconds = WeatherSeconds + 1 That's important. Keeps the time for weather. Now, close the server. You're done with it. (AHMAGAWD, THAT WAS EASY!!1) Next, open the client. Open modDirectX. Put this in there Code: Sub BltWeather() Dim i As Long Call DD_BackBuffer.SetForeColor(RGB(0, 0, 200)) If GameWeather = WEATHER_RAINING Then For i = 1 To MAX_RAINDROPS If DropRain(i).Randomized = False Then If frmMirage.tmrRainDrop.Enabled = False Then BLT_RAIN_DROPS = 1 frmMirage.tmrRainDrop.Enabled = True If frmMirage.tmrRainDrop.Tag = "" Then frmMirage.tmrRainDrop.Interval = 200 frmMirage.tmrRainDrop.Tag = "123" End If End If End If Next i ElseIf GameWeather = WEATHER_SNOWING Then For i = 1 To MAX_RAINDROPS If DropSnow(i).Randomized = False Then If frmMirage.tmrSnowDrop.Enabled = False Then BLT_SNOW_DROPS = 1 frmMirage.tmrSnowDrop.Enabled = True If frmMirage.tmrSnowDrop.Tag = "" Then frmMirage.tmrSnowDrop.Interval = 200 frmMirage.tmrSnowDrop.Tag = "123" End If End If End If Next i Else If BLT_RAIN_DROPS > 0 And BLT_RAIN_DROPS <= RainIntensity Then Call ClearRainDrop(BLT_RAIN_DROPS) End If frmMirage.tmrRainDrop.Tag = "" End If 'actually blt the rain For i = 1 To MAX_RAINDROPS If Not ((DropRain(i).X = 0) Or (DropRain(i).Y = 0)) Then DropRain(i).X = DropRain(i).X + DropRain(i).Speed DropRain(i).Y = DropRain(i).Y + DropRain(i).Speed Call DD_BackBuffer.DrawLine(DropRain(i).X, DropRain(i).Y, DropRain(i).X + DropRain(i).Speed, DropRain(i).Y + DropRain(i).Speed) If (DropRain(i).X > (MAX_MAPX + 1) * PIC_X) Or (DropRain(i).Y > (MAX_MAPY + 1) * PIC_Y) Then DropRain(i).Randomized = False End If End If Next i 'declare snow tile rec.top = 0 rec.Bottom = rec.top + PIC_Y rec.Left = 0 rec.Right = rec.Left + PIC_X 'actualy blt the snow For i = 1 To MAX_RAINDROPS If Not ((DropSnow(i).X = 0) Or (DropSnow(i).Y = 0)) Then DropSnow(i).X = DropSnow(i).X + DropSnow(i).Speed DropSnow(i).Y = DropSnow(i).Y + DropSnow(i).Speed Call DD_BackBuffer.BltFast(DropSnow(i).X + DropSnow(i).Speed, DropSnow(i).Y + DropSnow(i).Speed, DD_SnowSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY) If (DropSnow(i).X > (MAX_MAPX + 1) * PIC_X) Or (DropSnow(i).Y > (MAX_MAPY + 1) * PIC_Y) Then DropSnow(i).Randomized = False End If End If Next i ' If it's raining, make the screen randomly flash white If GameWeather = WEATHER_RAINING Then If Int((100 - 1 + 1) * Rnd) + 1 = 8 Then DD_BackBuffer.SetFillColor RGB(255, 255, 255) Call DD_BackBuffer.DrawBox(0, 0, (MAX_MAPX + 1) * PIC_X, (MAX_MAPY + 1) * PIC_Y) End If End If End Sub Sub ClearRainDrop(ByVal RDNumber As Long) On Error Resume Next DropRain(RDNumber).X = 0 DropRain(RDNumber).Y = 0 DropRain(RDNumber).Speed = 0 DropRain(RDNumber).Randomized = False End Sub Sub ClearSnowDrop(ByVal RDNumber As Long) On Error Resume Next DropSnow(RDNumber).X = 0 DropSnow(RDNumber).Y = 0 DropSnow(RDNumber).Speed = 0 DropSnow(RDNumber).Randomized = False End Sub Sub RNDRainDrop(ByVal RDNumber As Long) Start: DropRain(RDNumber).X = Int((((MAX_MAPX + 1) * PIC_X) * Rnd) + 1) DropRain(RDNumber).Y = Int((((MAX_MAPY + 1) * PIC_Y) * Rnd) + 1) If (DropRain(RDNumber).Y > (MAX_MAPY + 1) * PIC_Y / 4) And (DropRain(RDNumber).X > (MAX_MAPX + 1) * PIC_X / 4) Then GoTo Start DropRain(RDNumber).Speed = Int((10 * Rnd) + 6) DropRain(RDNumber).Randomized = True End Sub Sub RNDSnowDrop(ByVal RDNumber As Long) Start: DropSnow(RDNumber).X = Int((((MAX_MAPX + 1) * PIC_X) * Rnd) + 1) DropSnow(RDNumber).Y = Int((((MAX_MAPY + 1) * PIC_Y) * Rnd) + 1) If (DropSnow(RDNumber).Y > (MAX_MAPY + 1) * PIC_Y / 4) And (DropSnow(RDNumber).X > (MAX_MAPX + 1) * PIC_X / 4) Then GoTo Start DropSnow(RDNumber).Speed = Int((10 * Rnd) + 6) DropSnow(RDNumber).Randomized = True End Sub That just blts the weather, plain and simple. If it's raining, it draws random lines. If it's snowing, it gets snow from a file(this one! Snow GFX) and blits it randomly on the screen. Also, if it's raining, It makes it go boom. xD Now, you have the snow tile. HOW TEH HELLZ R WE GONNA PUT IT ON TEH GAME, LOL! Simple. Just in the General Declaration part, put this Code: Public DD_SnowSurf As DirectDrawSurface7 Si, tis all you need. Now, go to InitSurfaces... I'm not sure how the blank mirage does it... But, we're not noobs... Load the picture you downloaded onto the surface you declared. If you have trouble with this, feel free to leave me a PM or IM me on a messenger. Anyways, onwards! Client side, put this in the declaration section of modTypes Code: Public MAX_RAINDROPS As Long Public BLT_RAIN_DROPS As Long Public DropRain() As DropRainRec Public BLT_SNOW_DROPS As Long Public DropSnow() As DropRainRec Public RainIntensity As Byte Also add this to the 'TypeRec' Area up there(anywhere before it is declared) Code: Type DropRainRec x As Long y As Long Randomized As Boolean Speed As Byte End Type One last thing to change. Then we gotta do a bit of programming for ourselves. Find Code: If Lcase(Parse(0)) = "weather" Then In handle data or something similar and replace that whole statement with this: Code: If (LCase(Parse(0)) = "weather") Then If Val(Parse(1)) = WEATHER_RAINING And GameWeather <> WEATHER_RAINING Then Call AddText("You see drops of rain falling from the sky above!", frmMirage.txtChat, BrightGreen) End If If Val(Parse(1)) = WEATHER_SNOWING And GameWeather <> WEATHER_SNOWING Then Call AddText("You see snow falling from the sky above!", frmMirage.txtChat, BrightGreen) End If If Val(Parse(1)) = WEATHER_NONE Then If GameWeather = WEATHER_RAINING Then Call AddText("The rain beings to calm.", frmMirage.txtChat, BrightGreen) ElseIf GameWeather = WEATHER_SNOWING Then Call AddText("The snow is melting away.", frmMirage.txtChat, BrightGreen) End If End If GameWeather = Val(Parse(1)) RainIntensity = 100 If MAX_RAINDROPS <> RainIntensity Then MAX_RAINDROPS = RainIntensity ReDim DropRain(1 To MAX_RAINDROPS) As DropRainRec ReDim DropSnow(1 To MAX_RAINDROPS) As DropRainRec End If End If One more thing to do. In Sub GameLoop Add Code: If InEditor = False Then If GameWeather <> WEATHER_NONE Then Call BltWeather End If End If Right under Code: ' Blit out tile layer fringe For Y = 0 To MAX_MAPY For X = 0 To MAX_MAPX Call BltFringeTile(X, Y) Next X Next Y Now, weather's almost done! Open frmMirage, and make Two Timers and set them to these values. Timer1 Name: tmrRainDrop Enabled: False Interval: 100 Timer2 Name: tmrSnowDrop Enabled: False Interval: 100 For the timers, this is the code you want for them. Do not double click the timers to open the code window. Just right click on the form and click on 'View Code' Add these to the bottom Code: Private Sub tmrRainDrop_Timer()
If BLT_RAIN_DROPS > RainIntensity Then tmrRainDrop.Enabled = False Exit Sub End If If BLT_RAIN_DROPS > 0 Then If DropRain(BLT_RAIN_DROPS).Randomized = False Then Call RNDRainDrop(BLT_RAIN_DROPS) End If End If BLT_RAIN_DROPS = BLT_RAIN_DROPS + 1 If tmrRainDrop.Interval > 30 Then tmrRainDrop.Interval = tmrRainDrop.Interval - 10 End If End Sub Private Sub tmrSnowDrop_Timer() If BLT_SNOW_DROPS > RainIntensity Then tmrSnowDrop.Enabled = False Exit Sub End If If BLT_SNOW_DROPS > 0 Then If DropSnow(BLT_SNOW_DROPS).Randomized = False Then Call RNDSnowDrop(BLT_SNOW_DROPS) End If End If BLT_SNOW_DROPS = BLT_SNOW_DROPS + 1 If tmrSnowDrop.Interval > 30 Then tmrSnowDrop.Interval = tmrSnowDrop.Interval - 10 End If End Sub And that should be it. If you have any problems whatsoever, or if I'm missing anything, please tell me. This is as easy as I could get it, ripped from Elysium to work for MSE. Sorry I can't explain what any of it does. I don't understand DirectX too well to do so. Maybe someone else could explain? |
|
| Author: | Coke [ Fri Mar 09, 2007 10:48 pm ] |
| Post subject: | |
Err, i may be wrong but is there not a weather editing interface missing? |
|
| Author: | Matt2 [ Fri Mar 09, 2007 10:49 pm ] |
| Post subject: | |
Nah. If they want more weather, they can build off this one. |
|
| Author: | Aleano [ Sat Mar 10, 2007 12:53 am ] |
| Post subject: | |
Isn't this DragoonsMaster's weather system which he released ages ago on the old forums. |
|
| Author: | Matt2 [ Sat Mar 10, 2007 3:32 am ] |
| Post subject: | |
No idea. Came from Konfuze. xD |
|
| Author: | GodSentDeath [ Sat Mar 10, 2007 4:39 am ] |
| Post subject: | |
In that case, yes, the rain it was based off of DragoonsMaster's code a while back =P He just had rain and I added other shit... But yeah, credit goes to him |
|
| Author: | Xlithan [ Sat Mar 10, 2007 6:34 am ] |
| Post subject: | |
Also if you add the weather command from Konfuze, don't forget to fix the security hole |
|
| Author: | Erik [ Mon Mar 12, 2007 10:37 am ] |
| Post subject: | |
You forgot to include the DropRainRec... Code: Type DropRainRec
x As Long y As Long Randomized As Boolean Speed As Byte End Type |
|
| Author: | Matt2 [ Mon Mar 12, 2007 11:48 pm ] |
| Post subject: | |
Erik wrote: You forgot to include the DropRainRec...
Code: Type DropRainRec x As Long y As Long Randomized As Boolean Speed As Byte End Type Thank you. I edited and updated the tutorial. Heheh, nice catch. |
|
| Author: | GodSentDeath [ Tue Mar 13, 2007 2:20 am ] |
| Post subject: | |
GameBoy wrote: Also if you add the weather command from Konfuze, don't forget to fix the security hole
lol yeah xD It's not really that bad though.... >< |
|
| Author: | Ramsey [ Tue Mar 13, 2007 1:16 pm ] |
| Post subject: | |
what the security hole? never hear about it would'nt this make a weather on every map even in a house? |
|
| Author: | Xlithan [ Tue Mar 13, 2007 2:44 pm ] |
| Post subject: | |
You can extend this easily. Add a new type to maps (indoor), if the map is indoor don't use weather. I think this was in Deloria Source. The weather security hole was quite easy to fix. If you check the packet handler on the server you'll notice it doesn't properly check to see if a moderator is changing the weather, there's only a check on the client to see if a moderator has entered the command which means with a simple packet editor, anybody can change the weather. So make sure you do server checks as well as client checks. Very important |
|
| Author: | Sephiroth187 [ Wed Mar 14, 2007 12:39 am ] |
| Post subject: | |
What I dont like is how you are using a timer for the raindrop/snow drop. Use a function like GetTickCount Code: Public Declare Function GetTickCount lib "Kernel32" as long() Code: Global SnowDropTimer1 as long 'Our Tick based timer Global Constant SnowDropTimer2 = 100 'Our constant time in MS Global IsRaining as boolean 'Is it raining? Put it somewhere Code: SnowDropTimer1 = GetTickCount + SnowDropTimer2 Code: If GetTickCount => SnowDropTimer1 Then SnowDropTimer1 = GetTickcount + SnowDropTimer2 'You've got to update the information Call IIf(IsRaining, IsRaining = False, IsRaining = True) 'If it is raining, then it isnt. If it isnt, then it is. :) End If ...Use the rest for your imagination :P [/code] |
|
| Author: | Matt2 [ Thu Mar 15, 2007 12:41 am ] |
| Post subject: | |
Not my code. xD This is just a straigt rip. |
|
| Author: | Sephiroth187 [ Thu Mar 15, 2007 4:52 am ] |
| Post subject: | |
Ooohhh ok. Anwyays timers arent that good to use, because they work on depending the computer speed not by..pure seconds. Dont want to cause any seizures now do we? |
|
| Author: | Dragoons Master [ Sat Mar 17, 2007 1:55 pm ] |
| Post subject: | |
Lol, yeah, that's mine xD I'm not reading forums that frequently now... I just got into college and I don't have my computer here >< Omg , that's OLD xD Good luck with it. I still use it on my game and it works pretty good. |
|
| Author: | Slevin [ Mon Apr 23, 2007 2:20 pm ] |
| Post subject: | |
Variable not Defined |
|
| Author: | Lea [ Mon Apr 23, 2007 8:58 pm ] |
| Post subject: | |
Hmm... That's a strange error. I wonder if you forgot to define "filename" somewhere. |
|
| Author: | Da Undead [ Mon Apr 23, 2007 9:38 pm ] |
| Post subject: | |
Slevin, make sure that u have Function FileName and/or it defined in modTypes. (look at another blank source and compare/contrast) ---------- EDIT: Lmao when i just tried to add this i get samething rofl! ------------ EDIT AGAIN: Add this: Code: Dim FileName As String Under: Code: Dim DidWalk As Boolean
Which is in the Sub GameAI() |
|
| Author: | Da Undead [ Mon Apr 23, 2007 11:32 pm ] |
| Post subject: | |
In the Weather Packet, im having an error on AddText Says: Wrong number of arguments or invalid property assignment. Any idea? Heres my whole packet: Code: ' ::::::::::::::::::::
' :: Weather packet :: ' :::::::::::::::::::: If (LCase(Parse(0)) = "weather") Then If Val(Parse(1)) = WEATHER_RAINING And GameWeather <> WEATHER_RAINING Then Call AddText("You see drops of rain falling from the sky above!", frmMirage.txtChat, BrightGreen) End If If Val(Parse(1)) = WEATHER_SNOWING And GameWeather <> WEATHER_SNOWING Then Call AddText("You see snow falling from the sky above!", frmMirage.txtChat, BrightGreen) End If If Val(Parse(1)) = WEATHER_NONE Then If GameWeather = WEATHER_RAINING Then Call AddText("The rain beings to calm.", frmMirage.txtChat, BrightGreen) ElseIf GameWeather = WEATHER_SNOWING Then Call AddText("The snow is melting away.", frmMirage.txtChat, BrightGreen) End If End If GameWeather = Val(Parse(1)) RainIntensity = 100 If MAX_RAINDROPS <> RainIntensity Then MAX_RAINDROPS = RainIntensity ReDim DropRain(1 To MAX_RAINDROPS) As DropRainRec ReDim DropSnow(1 To MAX_RAINDROPS) As DropRainRec End If End If ------------ Oh and the link for snow isn't working |
|
| Author: | Reece [ Tue Apr 24, 2007 8:23 am ] |
| Post subject: | |
Its because you don't "Add text" in MS. I'm not to sure but I think you need to change it to Code: Call globalmsg
Check for other subs, maybe the attack one, and see how the broadcast a global message. And for the snow, make your own in paint. |
|
| Author: | Dragoons Master [ Tue Apr 24, 2007 4:56 pm ] |
| Post subject: | |
Sry about all the bugs. That's very old but it was developed for my game, witch is quite different. |
|
| Author: | Da Undead [ Wed Apr 25, 2007 2:04 am ] |
| Post subject: | |
Update it xD. And for the GlobalMsg, already tried that and it gives me an error on it and says.. Wrong number of arguments or invalid property assignments ----------- EDIT: MAJOR FIX FOR IT! I fixed it, it just wansn't registering straight so i had compared it to a previous call add text, well heres the correct packet Code: If (LCase(Parse(0)) = "weather") Then
If Val(Parse(1)) = WEATHER_RAINING And GameWeather <> WEATHER_RAINING Then Call TextAdd(frmMirage.txtChat, "You see rain drops falling from the sky above!", True) End If If Val(Parse(1)) = WEATHER_SNOWING And GameWeather <> WEATHER_SNOWING Then Call TextAdd(frmMirage.txtChat, "You see snow falling from the sky above!", True) End If If Val(Parse(1)) = WEATHER_NONE Then If GameWeather = WEATHER_RAINING Then Call TextAdd(frmMirage.txtChat, "The rain beings to calm.", True) ElseIf GameWeather = WEATHER_SNOWING Then Call TextAdd(frmMirage.txtChat, "The snow is melting away.", True) End If End If GameWeather = Val(Parse(1)) RainIntensity = 100 If MAX_RAINDROPS <> RainIntensity Then MAX_RAINDROPS = RainIntensity ReDim DropRain(1 To MAX_RAINDROPS) As DropRainRec ReDim DropSnow(1 To MAX_RAINDROPS) As DropRainRec End If End If |
|
| Author: | Styre [ Mon Apr 30, 2007 5:39 pm ] |
| Post subject: | |
This doesn't really fix it,, I used your packet and I still have the error. --------------------------------------------------------------------------------- EDIT: I have a RTE 5: Invalid Procedure call or Argument at Line: Code: Call DD_BackBuffer.BltFast(DropSnow(i).x + DropSnow(i).Speed, DropSnow(i).y + DropSnow(i).Speed, DD_SnowSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY) In Sub: Code: Sub BltWeather() Dim i As Long Call DD_BackBuffer.SetForeColor(RGB(0, 0, 200)) If GameWeather = WEATHER_RAINING Then For i = 1 To MAX_RAINDROPS If DropRain(i).Randomized = False Then If frmMirage.tmrRainDrop.Enabled = False Then BLT_RAIN_DROPS = 1 frmMirage.tmrRainDrop.Enabled = True If frmMirage.tmrRainDrop.Tag = "" Then frmMirage.tmrRainDrop.Interval = 200 frmMirage.tmrRainDrop.Tag = "123" End If End If End If Next i ElseIf GameWeather = WEATHER_SNOWING Then For i = 1 To MAX_RAINDROPS If DropSnow(i).Randomized = False Then If frmMirage.tmrSnowDrop.Enabled = False Then BLT_SNOW_DROPS = 1 frmMirage.tmrSnowDrop.Enabled = True If frmMirage.tmrSnowDrop.Tag = "" Then frmMirage.tmrSnowDrop.Interval = 200 frmMirage.tmrSnowDrop.Tag = "123" End If End If End If Next i Else If BLT_RAIN_DROPS > 0 And BLT_RAIN_DROPS <= RainIntensity Then Call ClearRainDrop(BLT_RAIN_DROPS) End If frmMirage.tmrRainDrop.Tag = "" End If 'actually blt the rain For i = 1 To MAX_RAINDROPS If Not ((DropRain(i).x = 0) Or (DropRain(i).y = 0)) Then DropRain(i).x = DropRain(i).x + DropRain(i).Speed DropRain(i).y = DropRain(i).y + DropRain(i).Speed Call DD_BackBuffer.DrawLine(DropRain(i).x, DropRain(i).y, DropRain(i).x + DropRain(i).Speed, DropRain(i).y + DropRain(i).Speed) If (DropRain(i).x > (MAX_MAPX + 1) * PIC_X) Or (DropRain(i).y > (MAX_MAPY + 1) * PIC_Y) Then DropRain(i).Randomized = False End If End If Next i 'declare snow tile rec.top = 0 rec.Bottom = rec.top + PIC_Y rec.Left = 0 rec.Right = rec.Left + PIC_X 'actualy blt the snow For i = 1 To MAX_RAINDROPS If Not ((DropSnow(i).x = 0) Or (DropSnow(i).y = 0)) Then DropSnow(i).x = DropSnow(i).x + DropSnow(i).Speed DropSnow(i).y = DropSnow(i).y + DropSnow(i).Speed Call DD_BackBuffer.BltFast(DropSnow(i).x + DropSnow(i).Speed, DropSnow(i).y + DropSnow(i).Speed, DD_SnowSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY) If (DropSnow(i).x > (MAX_MAPX + 1) * PIC_X) Or (DropSnow(i).y > (MAX_MAPY + 1) * PIC_Y) Then DropSnow(i).Randomized = False End If End If Next i ' If it's raining, make the screen randomly flash white If GameWeather = WEATHER_RAINING Then If Int((100 - 1 + 1) * Rnd) + 1 = 8 Then DD_BackBuffer.SetFillColor RGB(255, 255, 255) Call DD_BackBuffer.DrawBox(0, 0, (MAX_MAPX + 1) * PIC_X, (MAX_MAPY + 1) * PIC_Y) End If End If End Sub |
|
| Author: | Da Undead [ Mon Apr 30, 2007 9:03 pm ] |
| Post subject: | |
idk o-O, but i was just stating that the fix i posted was for the error on that packet cuz he uses a different way of adding text. |
|
| Page 1 of 3 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|