Mirage Source http://www.miragesource.net/forums/ |
|
binary accounts the easy way.... http://www.miragesource.net/forums/viewtopic.php?f=201&t=1383 |
Page 1 of 11 |
Author: | genusis [ Mon Feb 19, 2007 12:18 am ] |
Post subject: | binary accounts the easy way.... |
Ok, yes I can do this on a new mirage source even mirage source 2 and it works fine but i have a problem the problem is how would I do it for something like this. Code: Sub LoadPlayer(ByVal index As Long, _ ByVal Name As String) Dim FileName As String Dim i As Long Dim N As Long Call ClearPlayer(index) FileName = App.Path & "\accounts\" & Trim$(Name) & ".ini" Player(index).Login = GetVar(FileName, "GENERAL", "Login") Player(index).Password = GetVar(FileName, "GENERAL", "Password") Player(index).Pet.Alive = NO For i = 1 To MAX_CHARS ' General Player(index).Char(i).Name = GetVar(FileName, "CHAR" & i, "Name") Player(index).Char(i).Sex = Val(GetVar(FileName, "CHAR" & i, "Sex")) Player(index).Char(i).Class = Val(GetVar(FileName, "CHAR" & i, "Class")) If Player(index).Char(i).Class = 0 Then Player(index).Char(i).Class = 1 Player(index).Char(i).Sprite = Val(GetVar(FileName, "CHAR" & i, "Sprite")) Player(index).Char(i).Level = Val(GetVar(FileName, "CHAR" & i, "Level")) Player(index).Char(i).Exp = Val(GetVar(FileName, "CHAR" & i, "Exp")) Player(index).Char(i).Access = Val(GetVar(FileName, "CHAR" & i, "Access")) Player(index).Char(i).PK = Val(GetVar(FileName, "CHAR" & i, "PK")) Player(index).Char(i).Guild = GetVar(FileName, "CHAR" & i, "Guild") Player(index).Char(i).Guildaccess = Val(GetVar(FileName, "CHAR" & i, "Guildaccess")) ' Vitals Player(index).Char(i).HP = Val(GetVar(FileName, "CHAR" & i, "HP")) Player(index).Char(i).MP = Val(GetVar(FileName, "CHAR" & i, "MP")) Player(index).Char(i).SP = Val(GetVar(FileName, "CHAR" & i, "SP")) ' Stats Player(index).Char(i).STR = Val(GetVar(FileName, "CHAR" & i, "str")) Player(index).Char(i).DEF = Val(GetVar(FileName, "CHAR" & i, "DEF")) Player(index).Char(i).Speed = Val(GetVar(FileName, "CHAR" & i, "SPEED")) Player(index).Char(i).Magi = Val(GetVar(FileName, "CHAR" & i, "MAGI")) Player(index).Char(i).POINTS = Val(GetVar(FileName, "CHAR" & i, "POINTS")) ' Worn equipment Player(index).Char(i).ArmorSlot = Val(GetVar(FileName, "CHAR" & i, "ArmorSlot")) Player(index).Char(i).WeaponSlot = Val(GetVar(FileName, "CHAR" & i, "WeaponSlot")) Player(index).Char(i).HelmetSlot = Val(GetVar(FileName, "CHAR" & i, "HelmetSlot")) Player(index).Char(i).ShieldSlot = Val(GetVar(FileName, "CHAR" & i, "ShieldSlot")) ' Position Player(index).Char(i).Map = Val(GetVar(FileName, "CHAR" & i, "Map")) Player(index).Char(i).x = Val(GetVar(FileName, "CHAR" & i, "X")) Player(index).Char(i).y = Val(GetVar(FileName, "CHAR" & i, "Y")) Player(index).Char(i).Dir = Val(GetVar(FileName, "CHAR" & i, "Dir")) ' Check to make sure that they aren't on map 0, if so reset'm If Player(index).Char(i).Map = 0 Then Player(index).Char(i).Map = START_MAP Player(index).Char(i).x = START_X Player(index).Char(i).y = START_Y End If ' Inventory For N = 1 To MAX_INV Player(index).Char(i).Inv(N).num = Val(GetVar(FileName, "CHAR" & i, "InvItemNum" & N)) Player(index).Char(i).Inv(N).Value = Val(GetVar(FileName, "CHAR" & i, "InvItemVal" & N)) Player(index).Char(i).Inv(N).Dur = Val(GetVar(FileName, "CHAR" & i, "InvItemDur" & N)) Next ' Spells For N = 1 To MAX_PLAYER_SPELLS Player(index).Char(i).Spell(N) = Val(GetVar(FileName, "CHAR" & i, "Spell" & N)) Next If Val(GetVar(FileName, "CHAR" & i, "HasPet")) = 1 Then Player(index).Pet.Sprite = Val(GetVar(FileName, "CHAR" & i, "Pet")) Player(index).Pet.Alive = YES Player(index).Pet.Dir = DIR_UP Player(index).Pet.Map = Player(index).Char(i).Map Player(index).Pet.x = Player(index).Char(i).x + Int((Rnd * 3) - 1) If Player(index).Pet.x < 0 Or Player(index).Pet.x > MAX_MAPX Then Player(index).Pet.x = GetPlayerX(index) Player(index).Pet.y = Player(index).Char(i).y + Int((Rnd * 3) - 1) If Player(index).Pet.y < 0 Or Player(index).Pet.y > MAX_MAPY Then Player(index).Pet.y = GetPlayerY(index) Player(index).Pet.MapToGo = 0 Player(index).Pet.XToGo = -1 Player(index).Pet.YToGo = -1 Player(index).Pet.Level = Val(GetVar(FileName, "CHAR" & i, "PetLevel")) Player(index).Pet.HP = Player(index).Pet.Level * 5 '??? End If For N = 1 To MAX_FRIENDS Player(index).Char(i).Friends(N) = GetVar(FileName, "CHAR" & i, "Friend" & N) Next FileName = App.Path & "\banks\" & Trim(Name) & ".ini" ' Bank For N = 1 To MAX_BANK Player(index).Char(i).Bank(N).num = Val(GetVar(FileName, "CHAR" & i, "BankItemNum" & N)) Player(index).Char(i).Bank(N).Value = Val(GetVar(FileName, "CHAR" & i, "BankItemVal" & N)) Player(index).Char(i).Bank(N).Dur = Val(GetVar(FileName, "CHAR" & i, "BankItemDur" & N)) Next N Next End Sub and Code: Sub SavePlayer(ByVal index As Long) Dim FileName As String Dim i As Long Dim N As Long FileName = App.Path & "\accounts\" & Trim$(Player(index).Login) & ".ini" Call PutVar(FileName, "GENERAL", "Login", Trim$(Player(index).Login)) Call PutVar(FileName, "GENERAL", "Password", Trim$(Player(index).Password)) For i = 1 To MAX_CHARS ' General Call PutVar(FileName, "CHAR" & i, "Name", Trim$(Player(index).Char(i).Name)) Call PutVar(FileName, "CHAR" & i, "Class", STR(Player(index).Char(i).Class)) Call PutVar(FileName, "CHAR" & i, "Sex", STR(Player(index).Char(i).Sex)) Call PutVar(FileName, "CHAR" & i, "Sprite", STR(Player(index).Char(i).Sprite)) Call PutVar(FileName, "CHAR" & i, "Level", STR(Player(index).Char(i).Level)) Call PutVar(FileName, "CHAR" & i, "Exp", STR(Player(index).Char(i).Exp)) Call PutVar(FileName, "CHAR" & i, "Access", STR(Player(index).Char(i).Access)) Call PutVar(FileName, "CHAR" & i, "PK", STR(Player(index).Char(i).PK)) Call PutVar(FileName, "CHAR" & i, "Guild", Trim$(Player(index).Char(i).Guild)) Call PutVar(FileName, "CHAR" & i, "Guildaccess", STR(Player(index).Char(i).Guildaccess)) ' Vitals Call PutVar(FileName, "CHAR" & i, "HP", STR(Player(index).Char(i).HP)) Call PutVar(FileName, "CHAR" & i, "MP", STR(Player(index).Char(i).MP)) Call PutVar(FileName, "CHAR" & i, "SP", STR(Player(index).Char(i).SP)) ' Stats Call PutVar(FileName, "CHAR" & i, "str", STR(Player(index).Char(i).STR)) Call PutVar(FileName, "CHAR" & i, "DEF", STR(Player(index).Char(i).DEF)) Call PutVar(FileName, "CHAR" & i, "SPEED", STR(Player(index).Char(i).Speed)) Call PutVar(FileName, "CHAR" & i, "MAGI", STR(Player(index).Char(i).Magi)) Call PutVar(FileName, "CHAR" & i, "POINTS", STR(Player(index).Char(i).POINTS)) ' Worn equipment Call PutVar(FileName, "CHAR" & i, "ArmorSlot", STR(Player(index).Char(i).ArmorSlot)) Call PutVar(FileName, "CHAR" & i, "WeaponSlot", STR(Player(index).Char(i).WeaponSlot)) Call PutVar(FileName, "CHAR" & i, "HelmetSlot", STR(Player(index).Char(i).HelmetSlot)) Call PutVar(FileName, "CHAR" & i, "ShieldSlot", STR(Player(index).Char(i).ShieldSlot)) ' Check to make sure that they aren't on map 0, if so reset'm If Player(index).Char(i).Map = 0 Then Player(index).Char(i).Map = START_MAP Player(index).Char(i).x = START_X Player(index).Char(i).y = START_Y End If ' Position Call PutVar(FileName, "CHAR" & i, "Map", STR(Player(index).Char(i).Map)) Call PutVar(FileName, "CHAR" & i, "X", STR(Player(index).Char(i).x)) Call PutVar(FileName, "CHAR" & i, "Y", STR(Player(index).Char(i).y)) Call PutVar(FileName, "CHAR" & i, "Dir", STR(Player(index).Char(i).Dir)) ' Inventory For N = 1 To MAX_INV Call PutVar(FileName, "CHAR" & i, "InvItemNum" & N, STR(Player(index).Char(i).Inv(N).num)) Call PutVar(FileName, "CHAR" & i, "InvItemVal" & N, STR(Player(index).Char(i).Inv(N).Value)) Call PutVar(FileName, "CHAR" & i, "InvItemDur" & N, STR(Player(index).Char(i).Inv(N).Dur)) Next ' Spells For N = 1 To MAX_PLAYER_SPELLS Call PutVar(FileName, "CHAR" & i, "Spell" & N, STR(Player(index).Char(i).Spell(N))) Next ' Pet If i = Player(index).CharNum Then If Player(index).Pet.Alive = YES Then Call PutVar(FileName, "CHAR" & i, "HasPet", 1) Call PutVar(FileName, "CHAR" & i, "Pet", STR(Player(index).Pet.Sprite)) Call PutVar(FileName, "CHAR" & i, "PetLevel", STR(Player(index).Pet.Level)) Else Call PutVar(FileName, "CHAR" & i, "HasPet", 0) Call DelVar(FileName, "CHAR" & i, "Pet") ' Saving space Call DelVar(FileName, "CHAR" & i, "PetLevel") End If Else Call PutVar(FileName, "CHAR" & i, "HasPet", 0) Call DelVar(FileName, "CHAR" & i, "Pet") ' Saving space Call DelVar(FileName, "CHAR" & i, "PetLevel") End If ' Friend list For N = 1 To MAX_FRIENDS Call PutVar(FileName, "CHAR" & i, "Friend" & N, Player(index).Char(i).Friends(N)) Next FileName = App.Path & "\banks\" & Trim(Player(index).Login) & ".ini" ' Bank For N = 1 To MAX_BANK Call PutVar(FileName, "CHAR" & i, "BankItemNum" & N, STR(Player(index).Char(i).Bank(N).num)) Call PutVar(FileName, "CHAR" & i, "BankItemVal" & N, STR(Player(index).Char(i).Bank(N).Value)) Call PutVar(FileName, "CHAR" & i, "BankItemDur" & N, STR(Player(index).Char(i).Bank(N).Dur)) Next N Next End Sub It confused me since I have banks and pets it makes me wounder if its possible while keeping the banks and pets in ini. unless if you change them to .bin I could still use them..... haven't the clue. |
Author: | Obsidian [ Mon Feb 19, 2007 3:24 am ] |
Post subject: | |
Well first off... you need to move Pet.Alive = NO, into the Sub ClearPlayer... that variable does not need to be saved at all. Secondly... If you use binary accounts the easy way... and you use my tutorial... it will still save that for you, no worries. |
Author: | genusis [ Mon Feb 19, 2007 2:19 pm ] |
Post subject: | |
so your say move the whole pet=no to the clear player then just replace the rest with Code: 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 Code: 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 and it will work, and I don't have to change anything else. oh oops that's already in sub clearplayers. I guess that it was being used twice and I didn't notice lol. |
Author: | Obsidian [ Mon Feb 19, 2007 4:19 pm ] |
Post subject: | |
Actually for the Put/Get stuff it's better to do it like this... Code: Open FileName For Binary As #f
Put #f, , Player(index).Login Put #f, , Player(index).Password for i = 1 to max_chars put #f, , Player(index).char(i) next i Close #f There are a ton of temporary variables stored in the accountrec... and if you just use Put #f, , Player(index) it will also save every one of the temporary variables (not that it's a huge problem, it's only an extra 15 or 20 bytes i think... but it's better practice to do it the way mentioned above. |
Author: | Spodi [ Mon Feb 19, 2007 6:34 pm ] |
Post subject: | |
Well if we are talking about best and worst, it is best to save in a method that allows you to load in one Get. For example, vbGORE loads a map directly into RAM, and takes about 2-3ms per 100x100 map, while before, it took about 300-400ms to load the map tile-by-tile. |
Author: | Obsidian [ Mon Feb 19, 2007 8:11 pm ] |
Post subject: | |
Well technically for speed. But if you're looking to save space (like 15 bytes, like i said before), it's better not to save all of the temporary variables... but like you said, it's faster to not have to go through loops first as well. Oh well. |
Author: | wanai [ Sun May 22, 2022 9:05 pm ] |
Post subject: | Re: binary accounts the easy way.... |
XVII |
Author: | wanai [ Sun May 22, 2022 9:06 pm ] |
Post subject: | Re: binary accounts the easy way.... |
160.7 |
Author: | wanai [ Sun May 22, 2022 9:08 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Unkn |
Author: | wanai [ Sun May 22, 2022 9:09 pm ] |
Post subject: | Re: binary accounts the easy way.... |
pers |
Author: | wanai [ Sun May 22, 2022 9:10 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Want |
Author: | wanai [ Sun May 22, 2022 9:11 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Lafa |
Author: | wanai [ Sun May 22, 2022 9:12 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Comf |
Author: | wanai [ Sun May 22, 2022 9:13 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Bert |
Author: | wanai [ Sun May 22, 2022 9:14 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Isaa |
Author: | wanai [ Sun May 22, 2022 9:15 pm ] |
Post subject: | Re: binary accounts the easy way.... |
oeuv |
Author: | wanai [ Sun May 22, 2022 9:17 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Pete |
Author: | wanai [ Sun May 22, 2022 9:18 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Shin |
Author: | wanai [ Sun May 22, 2022 9:19 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Clar |
Author: | wanai [ Sun May 22, 2022 9:20 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Fyod |
Author: | wanai [ Sun May 22, 2022 9:21 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Sync |
Author: | wanai [ Sun May 22, 2022 9:22 pm ] |
Post subject: | Re: binary accounts the easy way.... |
Shan |
Page 1 of 11 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |