| Mirage Source http://miragesource.net/forums/ |
|
| Genusis beginner guide. http://miragesource.net/forums/viewtopic.php?f=210&t=2006 |
Page 1 of 1 |
| Author: | genusis [ Sat Jun 09, 2007 7:52 pm ] |
| Post subject: | Genusis beginner guide. |
Ok I am going to cover or at least try to cover the stuff people don't understand when they first come here. The other one only covered ip address settings, the way the server connects to the client, and what it was coded from. I think that was all of it last time I looked. well here is the first part of the tutorial kind of lame but at least it goes into detail. Welcome to my beginner tutorial. I will introduce you to what each separate folder mirage source starts out with is for. there is 5 folders in the client side and 5 in the server side mattering on if you have an interface folder or not for the client. If you do there will be 6 folders , but I'll talk about them all. CLIENT SIDE: Gfx= this is the folder that holds all your games playing pictures like the character, the tiles they walk on, Spell animation, Spell icons, Item pictures and more. Logs= This is where your client stores its error information, and player chat information. This is truly not really needed, but that's up to you. Music=If you don't know what this is ill slap you so hard your children's children wont have babies, But if you don't this is the folder that holds the sounds in the game on on the client like the special clicking noises. Interface= This folder is for Menu animations and looks its where you store the pictures that make your client look unique, or could be used for really cool flash animation main menus and options {YAI BABY!}. Maps= This is where all of your map data gets stored. this is the maps that your person who's playing on the client gets saved for so loading is faster next time and helps save space for the server to load it for other users. Src= This is the folder that contains the source code this is the stuff you will be editing and the stuff i will be talking about in this long tutorial for beginners. SERVER: Accounts= This is where all the accounts your users and you make are stored. you can edit them randomly, make your character a god, and so on. Logs= See client logs definition. Data=This is your most important folder for your game. this makes your server the most important part, and it helps keep people from cheating because they can't get to it if you have the server. All what is in here is the data on everything except the maps, and charters. This folder contains information about your items what animations and how much damage spells do, and how much def armor adds and so on. Maps= this is the server side maps these are the maps that get saved and transferred to the client side maps if changed the client side maps get saved over. sorted by number usually. Src= This is the special source you have to have in order to start a game its involves what is in your game as what each thing can do giving everything limitations, and also is a safe guard to help stop people from cheating. --------Client/Server Frm's---------- frmserver and stuff like it are just forums filled with buttons and text that work along and slowly activate the code. by pressing exit you leave. by pressing play you go to the next on and so on. DirectX here is also used for showign animated pictures or the game screen of course on something like frmmirage. It also has loading bars and other things. but they can not run by them selves without just a bit of gamelogic code or any kind of code that tells and sets limitations. |
|
| Author: | Robin [ Sat Jun 09, 2007 8:20 pm ] |
| Post subject: | Re: Genusis beginner guide. |
It would help if you knew how to spell >.> Or use Bold to set out the sections. Or knew what you were on about... But overall its an ok idea... just needs some more meat on it. |
|
| Author: | genusis [ Sat Jun 09, 2007 8:32 pm ] |
| Post subject: | Re: Genusis beginner guide. |
correct me if i get something wrong please and thanks oh and once I'm finished mapping everything ill go back and do the bold and also spell check it,but first I'm trying to finish it. I was playing on doing it in the beginning sorry. -----------Client Side source------------- -------ModClientTcp------- This is the most important source of the client by my mind of thought. This is the part that reads the game ip address and games port to connect it to the server. Code: Sub TcpInit() '**************************************************************** '* WHEN WHO WHAT '* ---- --- ---- '* 07/12/2005 Shannara Replaced hard-coded IP with constant. '**************************************************************** SEP_CHAR = Chr(0) END_CHAR = Chr(237) PlayerBuffer = "" frmMirage.Socket.RemoteHost = GAME_IP frmMirage.Socket.RemotePort = GAME_PORT End Sub it also destroying the connection if its invalid or no connection is detected. Code: Sub TcpDestroy() frmMirage.Socket.Close If frmChars.Visible Then frmChars.Visible = False If frmCredits.Visible Then frmCredits.Visible = False If frmDeleteAccount.Visible Then frmDeleteAccount.Visible = False If frmLogin.Visible Then frmLogin.Visible = False If frmNewAccount.Visible Then frmNewAccount.Visible = False If frmNewChar.Visible Then frmNewChar.Visible = False End Sub This folder has a buffer system built in that allows an almost equal buffer towards all the players. Code: Sub IncomingData(ByVal DataLength As Long) Dim Buffer As String Dim Packet As String Dim top As String * 3 Dim Start As Integer frmMirage.Socket.GetData Buffer, vbString, DataLength PlayerBuffer = PlayerBuffer & Buffer Start = InStr(PlayerBuffer, END_CHAR) Do While Start > 0 Packet = Mid(PlayerBuffer, 1, Start - 1) PlayerBuffer = Mid(PlayerBuffer, Start + 1, Len(PlayerBuffer)) Start = InStr(PlayerBuffer, END_CHAR) If Len(Packet) > 0 Then Call HandleData(Packet) End If Loop End Sub The mod also sends all the data to the server which then verifies it and send more data back. Code: Sub SendLogin(ByVal Name As String, ByVal Password As String) Dim Packet As String Packet = "login" & SEP_CHAR & Trim(Name) & SEP_CHAR & Trim(Password) & SEP_CHAR & App.Major & SEP_CHAR & App.Minor & SEP_CHAR & App.Revision & SEP_CHAR & END_CHAR Call SendData(Packet) End Sub ----------ModConstants----------- mod constant holds all of the special paths , ip, port, character speeds, player/npc contants,directions,item,tile,character size, time, admin, and map constants. some examples. Code: ' Winsock globals Public Const GAME_IP = "127.0.0.1" Public Const GAME_PORT = 7000 ' Key constants Public Const VK_UP = &H26 Public Const VK_DOWN = &H28 Public Const VK_LEFT = &H25 Public Const VK_RIGHT = &H27 Public Const VK_SHIFT = &H10 Public Const VK_RETURN = &HD Public Const VK_CONTROL = &H11 ' Menu states Public Const MENU_STATE_NEWACCOUNT = 0 Public Const MENU_STATE_DELACCOUNT = 1 Public Const MENU_STATE_LOGIN = 2 Public Const MENU_STATE_GETCHARS = 3 Public Const MENU_STATE_NEWCHAR = 4 Public Const MENU_STATE_ADDCHAR = 5 Public Const MENU_STATE_DELCHAR = 6 Public Const MENU_STATE_USECHAR = 7 Public Const MENU_STATE_INIT = 8 ' General constants Public Const GAME_NAME = "Mirage Source Engine" Public Const MAX_PLAYERS = 100 Public Const MAX_ITEMS = 200 Public Const MAX_NPCS = 200 Public Const MAX_INV = 50 Public Const MAX_MAP_ITEMS = 20 Public Const MAX_MAP_NPCS = 5 Public Const MAX_SHOPS = 200 Public Const MAX_PLAYER_SPELLS = 20 Public Const MAX_SPELLS = 200 Public Const MAX_TRADES = 10 Public Const NO = 0 Public Const YES = 1 --------ModDatabase--------- This is the mod that makes sure the files exist, It makes ,open, or over writes logs, saves the local maps, and revises the maps as well. example code. Code: Public Sub AddLog(ByVal Text As String) '**************************************************************** '* WHEN WHO WHAT '* ---- --- ---- '* 07/12/2005 Shannara Added log constants. '**************************************************************** Dim FileName As String Dim f As Long If Trim(Command) = "-debug" Then If frmDebug.Visible = False Then frmDebug.Visible = True End If FileName = App.Path & LOG_PATH & LOG_DEBUG If Not FileExist(LOG_DEBUG, True) Then f = FreeFile Open FileName For Output As #f Close #f End If f = FreeFile Open FileName For Append As #f Print #f, Time & ": " & Text Close #f End If End Sub -----------ModDeclares----------- This mod just declares functions which run the game and client with otu them it probably would not run at all. example code Code: ' Sound declares Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long --------ModDirectX--------- This is the first and second most important function to playing any game. it defines where everything should be placed and where it should stay as what color it is and stuff. also decides on certain variables like animations 2d and 3d. Sample Code: Public Sub InitDirectX() '**************************************************************** '* WHEN WHO WHAT '* ---- --- ---- '* 07/12/2005 Shannara Optimized function. '**************************************************************** ' Initialize direct draw Set DD = DX.DirectDrawCreate("") frmMirage.Show With DD ' Indicate windows mode application Call .SetCooperativeLevel(frmMirage.hWnd, DDSCL_NORMAL) End With With DDSD_Primary ' Init type and get the primary surface .lFlags = DDSD_CAPS .ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Set DD_PrimarySurf = DD.CreateSurface(DDSD_Primary) End With ' Create the clipper Set DD_Clip = DD.CreateClipper(0) ' Associate the picture hwnd with the clipper DD_Clip.SetHWnd frmMirage.picScreen.hWnd ' Have the blits to the screen clipped to the picture box DD_PrimarySurf.SetClipper DD_Clip ' Initialize all surfaces Call InitSurfaces End Sub ----------ModGameLogic------------- This mod is an important mod as well it tells the functions of what everything on the client side does as well as something things from the server side which the server is also needed as well to communicate and restrict and allow the client to do what it wants. It controls Main functions as well as status's and sends them as a string or any variable you want it to send as. sample code Code: Public Sub BltFringeTile(ByVal x As Long, ByVal y As Long) '**************************************************************** '* WHEN WHO WHAT '* ---- --- ---- '* 07/12/2005 Shannara Optimized function. '**************************************************************** Dim Fringe As Long ' Only used if ever want to switch to blt rather then bltfast With rec_pos .top = y * PIC_Y .Bottom = .top + PIC_Y .Left = x * PIC_X .Right = .Left + PIC_X End With Fringe = Map.Tile(x, y).Fringe If Fringe > 0 Then With rec .top = Int(Fringe / 7) * PIC_Y .Bottom = .top + PIC_Y .Left = (Fringe - Int(Fringe / 7) * 7) * PIC_X .Right = .Left + PIC_X End With Call DD_BackBuffer.BltFast(x * PIC_X, y * PIC_Y, DD_TileSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY) End If End Sub ----------ModGlobals------------ This mod is used for certain variables. with out this the system would not know what or how much a certain thing is or how to read it as so it throws errors at you like my printing machine throws middle fingers. sample code Code: ' Used to check if in editor or not and variables for use in editor Public InEditor As Boolean Public EditorTileX As Long Public EditorTileY As Long Public EditorWarpMap As Long Public EditorWarpX As Long Public EditorWarpY As Long ' Used for map item editor Public ItemEditorNum As Long Public ItemEditorValue As Long ' Used for map key editor Public KeyEditorNum As Long Public KeyEditorTake As Long ' Used for map key opene ditor Public KeyOpenEditorX As Long Public KeyOpenEditorY As Long ' Map for local use Public SaveMap As MapRec Public SaveMapItem(1 To MAX_MAP_ITEMS) As MapItemRec Public SaveMapNpc(1 To MAX_MAP_NPCS) As MapNpcRec --------ModHandleData----------- kind of simulate to another thing but its more specific to what it sends. its calculate the amount of bits to send and what to send them as and such. It is the packet area for those who cant find the packets when your searching look here or ill have a monkey bit your arm off. sample code Code: ' ::::::::::::::::::::::::::: ' :: All characters packet :: ' ::::::::::::::::::::::::::: If LCase(Parse(0)) = "allchars" Then n = 1 frmChars.Visible = True frmSendGetData.Visible = False frmChars.lstChars.Clear For i = 1 To MAX_CHARS Name = Parse(n) Msg = Parse(n + 1) Level = Val(Parse(n + 2)) If Trim(Name) = "" Then frmChars.lstChars.AddItem "Free Character Slot" Else frmChars.lstChars.AddItem Name & " a level " & Level & " " & Msg End If n = n + 3 Next i frmChars.lstChars.ListIndex = 0 Exit Sub End If ---------ModSound--------- If you don't know what this is for you deserve a swift kick in the nutz. but it Ok some people cant hear but see so ill describe it anyways. this is the thing that plays and sends sound animations in the game. could be used to make your people magically talk instead of text. sample code. Code: Public Sub PlayMidi(Song As String) '**************************************************************** '* WHEN WHO WHAT '* ---- --- ---- '* 07/12/2005 Shannara Added music constant. '**************************************************************** Dim i As Long i = mciSendString("close all", 0, 0, 0) i = mciSendString("open " & App.Path & MUSIC_PATH & Song & " type sequencer alias background", 0, 0, 0) i = mciSendString("play background notify", 0, 0, frmMirage.hWnd) End Sub -----------ModText------------ Some people may think this is for special variables at first, but your wrong. this is the area that defines and transfers text though out the game from player to player to npc to player.Basically controls fonts color and stuff. sample code Code: Public Sub SetFont(ByVal Font As String, ByVal Size As Byte) GameFont = CreateFont(Size, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Font) End Sub Public Sub DrawText(ByVal hdc As Long, ByVal x, ByVal y, ByVal Text As String, Color As Long) Call SelectObject(hdc, GameFont) Call SetBkMode(hdc, vbTransparent) Call SetTextColor(hdc, RGB(0, 0, 0)) Call TextOut(hdc, x + 2, y + 2, Text, Len(Text)) Call TextOut(hdc, x + 1, y + 1, Text, Len(Text)) Call SetTextColor(hdc, Color) Call TextOut(hdc, x, y, Text, Len(Text)) End Sub ------------ModTypes--------------- just like modglobal but these are allot less important. these are the variable settings for the str def or anything you want in your game but they don't run the game it self. sample code. Code: Type PlayerInvRec
Num As Byte Value As Long Dur As Integer End Type Type PlayerRec ' General Name As String * NAME_LENGTH Class As Byte Sprite As Integer Level As Byte Exp As Long Access As Byte PK As Byte ' Vitals HP As Long MP As Long SP As Long ' Stats STR As Byte DEF As Byte SPEED As Byte MAGI As Byte POINTS As Byte |
|
| Author: | William [ Sat Jun 09, 2007 8:37 pm ] |
| Post subject: | Re: Genusis beginner guide. |
Im sorry but I will not give it time to read it unless it uses code tags, and bold text for headings and such. Very hard to navigate through it now. |
|
| Author: | genusis [ Sat Jun 09, 2007 9:15 pm ] |
| Post subject: | Re: Genusis beginner guide. |
--------SERVER SIDE----------- --------ModConstants-----------same as clients modconstants just with a few special constants in there for the server like the log constants. sample. Code: Public Const GAME_WEBSITE = "Http://www/miragesource.com" Public Const ADMIN_LOG = "admin.log" Public Const PLAYER_LOG = "player.log" ' Version constants Public Const CLIENT_MAJOR = 0 Public Const CLIENT_MINOR = 0 Public Const CLIENT_REVISION = 1 Public Const Quote = """" Public Const MAX_LINES = 500 ---------ModDatabase-----------The servers database is a bit different it is something that is used to save and load everything, from the people to the map tiles and so on. It also give new special functions like getvar and putvar. sample codes. Code: Public Function GetVar(File As String, Header As String, Var As String) As String Dim sSpaces As String ' Max string length Dim szReturn As String ' Return default value if not found szReturn = "" sSpaces = Space(5000) Call GetPrivateProfileString(Header, Var, szReturn, sSpaces, Len(sSpaces), File) GetVar = RTrim(sSpaces) GetVar = Left(GetVar, Len(GetVar) - 1) End Function Public Sub PutVar(File As String, Header As String, Var As String, Value As String) Call WritePrivateProfileString(Header, Var, Value, File) End Sub Sub SavePlayer(ByVal Index As Long) Dim FileName As String Dim f As Long FileName = App.Path & "\accounts\" & Trim$(Player(Index).Login) & ".bin" f = FreeFile Open FileName For Binary As #f Put #f, , Player(Index) Close #f End Sub Sub LoadPlayer(ByVal Index As Long, ByVal Name As String) Dim FileName As String Dim f As Long Call ClearPlayer(Index) FileName = App.Path & "\accounts\" & Trim(Name) & ".bin" f = FreeFile Open FileName For Binary As #f Get #f, , Player(Index) Close #f End Sub ----------ModDeclares----------- This is a small part of the server even thou its has three or more functions that the server has to use. sample code Code: ' Text API Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As Any, ByVal lpString As String, ByVal lpfilename As String) As Long Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As Any, ByVal lpdefault As String, ByVal lpreturnedstring As String, ByVal nsize As Long, ByVal lpfilename As String) As Long Public Declare Function GetTickCount Lib "kernel32" () As Long -------ModGameLogic--------exact opposite of what client gamelogic does. instead of sending and receiving data it is used to promote and controlled variable objects in the game, to get them and to find them as well. sample codes. Code: Function FindOpenPlayerSlot() As Long Dim i As Long FindOpenPlayerSlot = 0 For i = 1 To MAX_PLAYERS If Not IsConnected(i) Then FindOpenPlayerSlot = i Exit Function End If Next i End Function Function GetPlayerDamage(ByVal Index As Long) As Long Dim WeaponSlot As Long GetPlayerDamage = 0 ' Check for subscript out of range If IsPlaying(Index) = False Or Index <= 0 Or Index > MAX_PLAYERS Then Exit Function End If GetPlayerDamage = Int(GetPlayerSTR(Index) / 2) If GetPlayerDamage <= 0 Then GetPlayerDamage = 1 End If If GetPlayerWeaponSlot(Index) > 0 Then WeaponSlot = GetPlayerWeaponSlot(Index) GetPlayerDamage = GetPlayerDamage + Item(GetPlayerInvItemNum(Index, WeaponSlot)).Data2 Call SetPlayerInvItemDur(Index, WeaponSlot, GetPlayerInvItemDur(Index, WeaponSlot) - 1) If GetPlayerInvItemDur(Index, WeaponSlot) <= 0 Then Call PlayerMsg(Index, "Your " & Trim(Item(GetPlayerInvItemNum(Index, WeaponSlot)).Name) & " has broken.", Yellow) Call TakeItem(Index, GetPlayerInvItemNum(Index, WeaponSlot), 0) Else If GetPlayerInvItemDur(Index, WeaponSlot) <= 5 Then Call PlayerMsg(Index, "Your " & Trim(Item(GetPlayerInvItemNum(Index, WeaponSlot)).Name) & " is about to break!", Yellow) End If End If End If End Function ---------ModGeneral--------It finds and connects the server and client together and finds out how much stuff they need to play the game like fps. Code: Sub InitServer() Dim IPMask As String Dim i As Long Dim f As Long Randomize Timer ' Init atmosphere GameWeather = WEATHER_NONE WeatherSeconds = 0 GameTime = TIME_DAY TimeSeconds = 0 ' Check if the maps directory is there, if its not make it If LCase(Dir(App.Path & "\maps", vbDirectory)) <> "maps" Then Call MkDir(App.Path & "\maps") End If ' Check if the accounts directory is there, if its not make it If LCase(Dir(App.Path & "\accounts", vbDirectory)) <> "accounts" Then Call MkDir(App.Path & "\accounts") End If SEP_CHAR = Chr(0) END_CHAR = Chr(237) ServerLog = False ' Get the listening socket ready to go frmServer.Socket(0).RemoteHost = frmServer.Socket(0).LocalIP frmServer.Socket(0).LocalPort = GAME_PORT ' Init all the player sockets For i = 1 To MAX_PLAYERS Call SetStatus("Initializing player array...") Call ClearPlayer(i) Load frmServer.Socket(i) Next i Call SetStatus("Clearing temp tile fields...") Call ClearTempTile Call SetStatus("Clearing maps...") Call ClearMaps Call SetStatus("Clearing map items...") Call ClearMapItems Call SetStatus("Clearing map npcs...") Call ClearMapNpcs Call SetStatus("Clearing npcs...") Call ClearNpcs Call SetStatus("Clearing items...") Call ClearItems Call SetStatus("Clearing shops...") Call ClearShops Call SetStatus("Clearing spells...") Call ClearSpells Call SetStatus("Loading classes...") Call LoadClasses Call SetStatus("Loading maps...") Call LoadMaps Call SetStatus("Loading items...") Call LoadItems Call SetStatus("Loading npcs...") Call LoadNpcs Call SetStatus("Loading shops...") Call LoadShops Call SetStatus("Loading spells...") Call LoadSpells Call SetStatus("Spawning map items...") Call SpawnAllMapsItems Call SetStatus("Spawning map npcs...") Call SpawnAllMapNpcs ' Check if the master char list file exists for checking duplicate names, and if it doesnt make it If Not FileExist("accounts\charlist.txt") Then f = FreeFile Open App.Path & "\accounts\charlist.txt" For Output As #f Close #f End If ' Start listening frmServer.Socket(0).Listen Call UpdateCaption frmLoad.Visible = False frmServer.Show SpawnSeconds = 0 frmServer.tmrGameAI.Enabled = True End Sub ----------ModGlobals------------Same exact thing as on client side. see client side mod globals for information. ------ModHandleData--------- Same exact thing as on client side. see client side modHandleData for information. ---------ModServerTCP---------This is the thing which makes sure no one is multi using n account and other security stuff.It also send variable information back to the client so that way the client can receive the info it needs and keep chugging along for the ride. sample code Code: Function IsMultiIPOnline(ByVal IP As String) As Boolean Dim i As Long Dim n As Long n = 0 IsMultiIPOnline = False For i = 1 To MAX_PLAYERS If IsConnected(i) And Trim(GetPlayerIP(i)) = Trim(IP) Then n = n + 1 If (n > 1) Then IsMultiIPOnline = True Exit Function End If End If Next i End Function Sub SendDataTo(ByVal Index As Long, ByVal Data As String) Dim i As Long, n As Long, startc As Long If IsConnected(Index) Then frmServer.Socket(Index).SendData Data DoEvents End If End Sub Sub SendDataToAll(ByVal Data As String) Dim i As Long For i = 1 To MAX_PLAYERS If IsPlaying(i) Then Call SendDataTo(i, Data) End If Next i End Sub --------ModText---------- Same as client side. Read that one for definition. ----------ModTypes---------- Same as client side . Read that one for definition. I thank you all for reading my guide and I hope it helped you in your way of becoming a successful coder. And for you coders that know more than me just point out my mistakes and ill fix them except spelling since my google spell check is not working as well today or any day server connection errors. |
|
| Author: | genusis [ Sat Jun 09, 2007 9:46 pm ] |
| Post subject: | Re: Genusis beginner guide. |
know I'm going to show you how to create your first character, make it a mod then make your first map. (Thanks to cruzn for given me the ideal and for going though and fixing my spelling errors when he gets the time.) first step is to start up your server, Then to start up your client. find the button or word that says create new account. second step create an account. first you create it using any name or letters/numbers you want to since its up to you. my example Code: user name bob password give than say create.third step is to edit your account. you open up your server folder and then open up accounts find your characters name and open that in word pad. In here you can change any of your stats to what you want but its no fun then. well GO TO ACCESS AND CHANGE IT TO 4 fourth step once edited save it. shut down your server and start it back up again. know enter the game and you will be the head admin. once here you go and create a character by selecting new character and then naming him and stuff. It will kick you out after it is done. just log back on and then select use character. once on the game it self type /admin to see if you where successful other wise you need to go back and do step 3 again. fifth step once it shows you a list of option type in /mapeditor and the map editor will appear. sixth step Ok know is the time you get to play around with the animations. you should be able to figure out what they do on your own from here. but once you are done and you want it to look the way you made it press send it will save your change of items or npcs. its not hard from there out everything else is really easy to understand how to use. Thanks for reading the map and admin setting guide I hope it at least helped you out. |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|