![]() |
Adding in player options - Printable Version +- Mirage Source (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49) +---- Thread: Adding in player options (/showthread.php?tid=1570) |
Adding in player options - Stomach Pulser - 20-02-2008 OK! This is my tutorial on how to add options to your game. These will be simple On/Off options such as when the player want to display the FPS or not. OK! The tutorial will show you how to add a frmOptions that displays when the user types '/opt' and the ability to turn all options on or off by typing '/opt on' or '/opt off'. This tutorial was bade for MSE Build 1. Remember to back up your source! Difficulty: 2/5 (C/P really, try to understand it though) Creator: Stomach Pulser ::Client Side:: We will start off in 'modConstants'. At the very bottom add the following five constants: Code: ' Player Option Constants Now head over to 'modTypes'. Go into the PlayerRec and add an array to the bottom, so that it starts at 0 and ends at OPT_FINAL: Code: ' Options Open up 'modGameLogic'. At the very bottom add these functions/subs: Code: Function GetPlayerOption(ByVal Index As Long, ByVal Opt As Byte) As Byte The function GetPlayerOption does just that. It takes the player and the option given (0 ~ 4) and the returns whether it is on (true) or off (false). The sub SetPlayerOption is similar. It takes the player and set the option given (0 ~ 4) to on or off. The function ReadPlayerOption returns the option back as a string. This is where our constants come into play. By using the select case with our constants, it makes the code more readable in case you want to add more options or take some out. The sub PlayerOptionsInit is going to be used to set up our frmOptions to display the users current options. The sub PlayerOptionsOK is going to be used to get what the player selects in frmOptions and send it to the client for saving. It is only called if the user clicks OK in frmOptions. Now, let's set up our packet system. Go into 'modClientTCP' and add the following subs at the very bottom: Code: Sub SendGetPlayerOptions(ByVal Index As Long) The sub SendGetPlayerOptions is a request. It asks the server to send over the player's saved data for their options. It is used to load the player. The sub SendUpdatePlayerOptions takes the player's option choices and then send them to the server, asking for the server to save them. OK, now go into the 'modHandleData' and add this at the very bottom, right before where it says 'end sub': Code: ' :::::::::::::::::::::::::::: Head back over to 'modGameLogic'. Inside the sub 'HandleData', find: Code: ' Leave party Code: ' Options Request First off, we check to see if the user typed in “/optâ€. If they did, then we check to see if they added anything after that. If they did, we assign it to the variable chat text. Next, we check to see what chat text is. If it is on or off then we set all of the player's option choices to on or off, respectively and then send a packet to the server telling it to save that. If they didn't type in chat text, then we open up our frmOptions through the InitPlayerOptions. Because we added: Code: frmOptions.Show vbModal The last thing we need to do client wise is add the actual frmOptions itself. To do this click on the Project tab in the menu bar up top. Click on Add Form. Then, make sure the dialog box sets it to Form and hit OK. Rename this form to frmOptions. Set the caption to whatever you want and start adding GUI. Add two command buttons, rename them to cmdSend and cmdCancel. Captions set to whatever you want. Next, add a frame, and name it fraOpt[b]. Set the caption to your longest option (text wise), in this case it would be [b]Display Map Coordinates. Next, add two option buttons to the frame. Name them optOn and optOff. Next, click on the frame and press Ctrl + C to copy it. Then, press Ctrl + V to paste it. A dialog box will pop up asking if you want to make the frame a control array. Press OK. The dialog will ask again for your option buttons, again press OK. Arrange them how you want. The final piece of GUI is a lone label. Set it's name to lblIndex and set the visible property to False. This label will store who the player is. Now, we add the code. Double click on your cmdSend and add the following under it: Code: Call PlayerOptionsOK(frmOptions.lblIndex) Double click on your cmdCancel and add the following under it: Code: Me.Visible = False Phew! That is a lot of things Client Side. But, we are done with that much, the next part is about the same. ::Server Side:: Start off in 'modConstants'. At the very bottom add this: Code: ' Player Option Constants Code: POption(0 To OPT_FINAL) As Byte Code: ' Options Find the sub LoadPlayer at the very bottom, before the 'next I' add this: Code: ' Options Go into 'modServerTCP' and add the following sub at the very bottom: Code: Sub SendPlayerOptions(ByVal Index As Long) Now, go into your 'modHandleData' and add the following in before the end sub call: Code: ' ::::::::::::::::::::::::: Go into 'modGameLogic'. Add the following at the very end of the sub ClearChar: Code: For n = 0 To OPT_FINAL Finally, add the following at the very bottom of 'modGameLogic': Code: Function GetPlayerOption(ByVal Index As Long, ByVal Opt As Byte) That is it! If you have any questions/comments, post it here or PM me. Here is what my frmOptions looks like: ![]() Code: Version Log Re: Adding in player options - Ambientiger - 21-02-2008 Nice tutorial, I like the way you've added Code: Public Const OPT_FINAL = 4 Re: Adding in player options - Stomach Pulser - 21-02-2008 Thanks. It's meant to be like a good engine. It provides a rough and dirty base that can be easily edited and polished. Re: Adding in player options - Stomach Pulser - 27-02-2008 There was an error in the code that I fixed. It involved saving and loading. And I didn't catch it when i was testing it. Also, I made it so that it doesn't close of your game when opening frmOptions (this froze the game until you exited frmOptions). You will have to make your own code if you want it to display your options in chat after you you send frmOptions (now, it sends it when you open it up). If you added this code already, just replace the code in HandleData (Server and Client) with the new code in the guide, then change: Code: frmOptions.Show vbModal to Code: frmOptions.Visible = True Didn't mean to mess anyone up with his code, just a bug that slipped by. |