![]() |
Directional Blocking (My way) - 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: Directional Blocking (My way) (/showthread.php?tid=32) |
Directional Blocking (My way) - funkynut - 01-06-2006 Ok, quick note, I havent enabled this for npcs, I'mma very lazy person so if you want, you can complete it yourselfs, its not that hard. And asfar as I know, I works perfectly for players as it is... Originally posted by FunkyNut Directional Blocking (My way) Difficulty 4/5(Its not difficult to understand, but It can get a bit confusing since its not like a tile attibute and adds parts everywhere) [ATTACHMENT NOT FOUND] ^^^Forgot to show sample, so here is what mine finished looks like. I can walk on all the green tiles, but they wont allow me to walk on the grey tiles ok, This tut will give you the ability to Unblock/Block directions that a players on, if you want to stop a tile from access from all sides, its still easier to use a block attib (Which isnt removed by this tut),but this tile will allow a player to walk on a tile (Such as a ledge) but wont let them walk any further (so you dont waste a whole tile when stopping players walking over a ledge). Btw, I’m not sure, but I assume that this will muck up any maps you already have so you either have to redo the maps, or make a small app to convert all old maps to this new format Ok, lets Begin, first off lets change the way Tiles are read and saved, so find TileRec on both Client and Server and add to the bottom of the type: Code: WalkUp As Boolean This will be used to record which directions are walkable, if a directions walkable, it will be set to true Now, lets just add the controls we’ll be using in Map Editor, Add a Checkbox called chkDirectionView and two command buttons called cmdFillDirections and cmdClearDirections [ATTACHMENT NOT FOUND] Ok, now we’ve added the controls, we need the server to send us the new Tile Records to the client so find the sub SendMap, find: Code: Packet = Packet & .Ground & SEP_CHAR & .Mask & SEP_CHAR & .Anim & SEP_CHAR & .Fringe & SEP_CHAR & .Type & SEP_CHAR & .Data1 & SEP_CHAR & .Data2 & SEP_CHAR & .Data3 & SEP_CHAR and replace it with: Code: Packet = Packet & .Ground & SEP_CHAR & .Mask & SEP_CHAR & .Anim & SEP_CHAR & .Fringe & SEP_CHAR & .Type & SEP_CHAR & .Data1 & SEP_CHAR & .Data2 & SEP_CHAR & .Data3 & SEP_CHAR & .WalkUp & SEP_CHAR & .WalkDown & SEP_CHAR & .WalkLeft & SEP_CHAR & .WalkRight & SEP_CHAR Now find SendMap in the Client and replace the same thing Now, we need the client to interpret this new data when its received so find: Code: SaveMap.Tile(x, y).Ground = Val(Parse(n)) And after SaveMap.Tile(x, y).Data3 add: Code: SaveMap.Tile(x, y).WalkUp = Parse(n + 8) And change: Code: n = n + 8 Code: n = n + 12 Now we’ve done all that, we need to make the server aware of all this malarkey that the clients sending so find: Code: Map(MapNum).Tile(x, y).Ground = Val(Parse(n)) And add: Code: Map(MapNum).Tile(x, y).WalkUp = Parse(n + 8) And again, change the n = n +8 to n = n + 12 Now the server can quite happily send and retrieve the new data, we need to allow the Client to edit this data, so let’s first make the Client Blt the arrows onto each tile by adding a new surface containing the arrows. First, save this image to your Client Gfx Folder and call it ‘Direction’ and the extension you use. [ATTACHMENT NOT FOUND] We want to do this neatly and as fully as possible so find Code: If FileExist(FileName & "sprites" & GFX_EXT, True) = False Or FileExist(FileName & "tiles" & GFX_EXT, True) = False Or FileExist(FileName & "items" & GFX_EXT, True) = False Then Code: If FileExist(FileName & "sprites" & GFX_EXT, True) = False Or FileExist(FileName & "tiles" & GFX_EXT, True) = False Or FileExist(FileName & "items" & GFX_EXT, True) = False Or FileExist(FileName & "Direction" & GFX_EXT, True) = False Then Now, we need to create the DirectDraw surface, so find Code: Public DDSD_Item As DDSURFACEDESC2 Code: Public DDSD_Direction As DDSURFACEDESC2 Also find: Code: Public DD_ItemSurf As DirectDrawSurface7 Code: Public DD_DirectionSurf As DirectDrawSurface7 Now we need to add the code that actually inits the surface, so find Code: ' Init items ddsd type and load the bitmap And add under it Code: ' Init Direction ddsd type and load the bitmap Lets go though this line by line, the .lFlags is telling Dx what properties to look at, so if we added, ddsd_Height, it will check the height property, in this case its checking the caps property. The .lCaps is describing how to load the surface, in this case its placed into the video memory. (Not 100% sure what the OffScreenPlain does, but you use it for any surface that’s in the background) The next line tells it to load a picture from file onto the surface using the properties we’ve just set, and the line after that just tells it what colours to make invisible. We also have to unload the surface from memory when we exit so find Code: Set DD_ItemSurf = Nothing Code: Set DD_DirectionSurf = Nothing Now we need to display the directions on the map when we choose to so, find: Code: ' Blit out attribs if in editor And replace it with Code: ' Blit out attribs if in editor Now to main part that displays the arrows, we need this to be displayed above everything including all text, so we need to place this just after the backbuffer is released when blting text, so find: Code: Call DD_BackBuffer.ReleaseDC(TexthDC) And add this Code: If InEditor Then and then add the end of modGameLogic add this sub Code: Public Sub BltDirectionArrows() All this sub does is, go though each tile, checks its walkable properties and blts the correct image, once it’s done that it blts 2 lines which will eventually create a grid. The only other thing to explain about this sub is that it blts the center shape by checking if the tile is totally blocked, and if it is, it will blt a cross, if not, it blts a circle. We still need to make use of them buttons we added earlier, so double click on cmdFillDirections and add: Code: Dim X As Long, Y As Long All this does is scan each tile and make each direction walkable Now double click cmdClearDirections and add: Code: Dim X As Long, Y As Long This also scans each tile, but this time, it cuts off all directions. Thats all for now, its 11:25pm, and i still need a bath ready for school tomoz, i'll try finish it tomoz but its not guaranteed, but i've posted it anyway incase someone wants to try finish it by themselves. All it needs is a way to flick a single direction on/off and mod to playermove to scan directions ![]() Btw, incase your wondering, this is what mine looks like so far: [ATTACHMENT NOT FOUND] Direction Blocking Part 2 Finally gotten round to starting the second half ![]() I better explain first what I’m going to do next for detecting which tile and where on the tile you’ve clicked, so far, i've split the tile into sections like this... [ATTACHMENT NOT FOUND] Each section is a different clickable area, for example, the green area is for Blocking/Unblocking walking up and if the user clicks in this area then it will toggle it, the only problem now, is the corners at each side of the green section. The easiest way to solve this is to divide the whole tile into nine sections, like this… [ATTACHMENT NOT FOUND] What we need the client to do now when the mouse is clicked, is to scan which section was clicked. So, open up your client, find the sub EditorMouseDown. Now at the top with the variables declaration, add these variables: Code: Dim x2 As Long, y2 As Long ' Used to record where on the tile was clicked Now, to make it look neat, indent this Code: If (Button = 1) And (x1 >= 0) And (x1 = 0) And (y1 = 0) And (x1 = 0) And (y1 .Right Then ' Right side All this section does is scan for which of the nine parts of the tile we clicked, and changes the settings respectively. If it’s a corner, it will compare x and y to tell which side of the square its on, for, if X = Y, it will create a line from one corner to the other, if X > Y, it will make a point on one side of the line, if Y > X, it will create a point on the other side of the line. Ok, right now, we have to actually restrict player movement if the tile their standing on needs to so, in the client, find sub CanMove, find: Code: ' Check to see if a npc is already on that tile Code: ' Check if the tile will let us walk onto it Now, find this, which is a bit below it (This ones the walking down version) Code: ' Check to see if a npc is already on that tile and add below it Code: ' Check if the tile will let us walk onto it And now for the left movement, find Code: ' Check to see if a npc is already on that tile And add: Code: ' Check if the tile will let us walk onto it Now the right side, find Code: ' Check to see if a npc is already on that tile Then add: Code: ' Check if the tile will let us walk onto it Now, this alone would work, but if a player is using a hacked client, or has hacked the map somehow, this could be bypassed easily, so we need to change the Player movement in the server, so find in the server, sub PlayerMove, and we basically have to do something similar here so locate: Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) - 1).Type TILE_TYPE_BLOCKED Then Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) - 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkUp Then Now do the same with: Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED Then Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkDown Then Now do the same with: Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)-1, GetPlayerY(Index) ).Type TILE_TYPE_BLOCKED Then Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)-1, GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkLeft Then Now do the same with: Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)+1, GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED Then Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)+1, GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkRight Then That should be everything, find any problems with this let me know. Btw, I wont be surprised if you dont understand it, I found it a kinda hard to explain some of the things, if anyone wanna convert this into laymans terms, be my guest ![]() - ZS5 - 05-08-2006 Has anyone else tried it, yet? I triple checked and yes, I did this tutorial to the T, so to speak. That being said, it messes up for me when I walk through a one-way block onto a warp tile. It just sits there... Doing nothing. I have literaly spent says trying to figure out what is wrong, but to no avail. Works fine when the warps are nowhere near the directional blocks, but messes everything up when doing the afore mentioned. - Misunderstood - 06-08-2006 I haven't added it, but I might be able to help. I would think the problem would either be in canmove clientside or playermove serverside clientside I would compare the end(after the differnet checks for each direction) to a normal ms version to see if anything there might need to be changed. and also compare the serverside playermove with an unedited one, since its likely those 2 are the problems. Maybe gettingmap is set to true(which doesnt let you move till its set back to false) but the request to move to the tile isnt getting sent. I just looked over it so I could be wrong, but those would be my suggestions. Hopefully Mr. Funk knows more. - funkynut - 06-08-2006 Yea, Someone mentioned something like that on the old forums, but I couldnt find out what was wrong since mine was fine Perhaps I left a line out somewhere or maybe you placed a line of code the wrong place? I'll just try checking my source (If I still have it) to see if I can find whats wrong, but as mis says, its probably client since you see it doing nothing) *Edit* I have my source but I dont have visual basic anymroe (Reformatted the other day) and the code above doesnt really help much... - SheepDog - 06-08-2006 There are several bugs in this which I posted about on the old forums.. Easily fixed though.. I just can't remember what they were.. - Misunderstood - 07-08-2006 Notepad ![]() - ZS5 - 08-08-2006 I am thinking that it is caused by GetMapRevision (that is the sub, if I remember correctly), but that does not make sense, because it works perfectly fine when not being interfered with by this hack. See, I am not using the normal map###.dat files for my maps, but they work perfectly when warping in a place that has no directional blocking. (I take it I get no help if I did a mod?) Varrigan (sorry if I spelled it wrong!) helped me with that one, but he was way too busy to help debug it, since I could not figure out what was wrong with it. But even with a normal vanilla MS, there is one bug aside from the NPCs not being stopped by the blocking; I cannot attack them for the life of me. Rarely, I will be allowed to get a few hits off of them, but aside from that and them blocking me, it is like the NPCs are not there. Oh, right, and with the If GettingMap = True statements did not seem to be working, if I remember correctly... Hmm... I will try the debugging again and post the results, since I keep forgetting what was wrong. - funkynut - 08-08-2006 *sigh* I got visual basic back, but now I dont have my source, so If you want, get in touch with me on msn and i'll help you debug it As for it not blocking npcs movement, thats not a bug, I didnt add that with this tut - ZS5 - 09-08-2006 Well, I know; I was just counting it as one since it did not seem very natural and I was also waiting to debug the other parts before adding that feature. But the non-NPC-blocking seems like a nice way to make a "Ghost NPC" tutorial. I will try to contact you sometime next week, because I will be busy this weekend; I have to release a Flash episode in less than... Ooo... Almost over-due... Ooops... Thanks! ![]() (PS: I noticed how you sometimes capitalize If. VB programmer's syndrom? ![]() - funkynut - 09-08-2006 Yea, Just a habit I've carried over from it I also occasionally Capitalize important words in some sentences lol - Krloz - 09-08-2006 Haha ya I do that too Always xD - Misunderstood - 01-09-2006 Or maybe...you messed up your game adding it wrong? Of course you made a backup before adding this so it shouldn't matter. right? - Not2BeTrusted2 - 01-09-2006 loll nvm i restore my files to normal ![]() |