01-06-2006, 09:17 PM
Author: funkynut
Difficulty: 2/5
"Okay, this is a Guide to adding your very own NPC Spawn Tile. Now then What I’ll pretty just doing is simple, just making a new form so you can select the NPC to spawn, adding a new tile attribute and making the server check for spawn NPC tiles and if there is a Spawn NPC Tile, spawn the NPC on that spot, and skip the rest of the routine that will try to spawn the NPC somewhere else."
:: SERVER & CLIENT SIDE ::
First let’s add the Tile Constant to both the client and server so find:Below it, add:
:: SERVER SIDE ::
Find sub SpawnNPC.
Now, just above:Add:All this does is scan each tile for its type and if it’s an NPC spawn type it will then check if its meant to spawn the same NPC that its trying to spawn right now and if it is, it will place the NPC on that tile and skip the rest of the code that tries to spawn the NPC somewhere else.
Now we need to mod a bit of existing code so that we can skip it if we have already spawned an NPC so just below what you’ve added, change:To this:
:: CLIENT SIDE ::
Now we need to Blt the letter on top of the tiles so find:Below it, add:Now the explanation, each If Then statement is checking the Tile type and if its the correct type, will Blt a few letters to displaywhat tile it is.
This is the whole section:Now the ‘.Type’ for each If Then selects the section of the With statement its checking, so for this it will check Map.Tile.Type. The TILE_TYPE_BLOCKED etc are what were checking the .Type for, and if .Type is the same then we continue to blt the text on the tile.
The ‘TexthDC’ is kind of like the address or directions to the back buffer surface, and tells it what to write the text on, the next two sections tell the routine where to Blt the text, the next section is what is going to be bltted and the last section if the colour.
Okay, now we have to be able to add this tile type to any tile we click on so find:And after it add:This pretty much sets the tiles properties to store what you want it to, in this case the npc you selected.
Okay, we need somewhere to input the tile properties into so add a new form call ‘frmMapSpawnNpc’ and on it at a list box called ‘lstNpc’ and two command button named cmdOk, cmdCancel.
When we load this form, we need to load each npc that is spawned on the map into the list box so that the user can select the npc they wish to spawn, so in form load add:All this code does is scan each map npc slot and add the Map Npc num and the Npc Name. (If it doesn’t exist, it will just insert a “No Npc†statement)
Now we need a variable to remember what npc we need to spawn at the spawn point when we place it on the map so find:
Below it, add:Now we've added the variable, we need to record what we’ve selected to it so add for cmdOk:And of course if you haven’t already, put an unload me into cmdCancel
‘Now we just need to add the option button to frmmirage, so goto frmMirage, on the frame with the tile attribs on them, add a new option button called ‘optNpcSpawn’ and on the click event add:This basically loads the form but the ‘vbModal’ Part attaches it to frmMirage and gives it priority so you cant click on frmMirage until you’ve unloaded it
Difficulty: 2/5
"Okay, this is a Guide to adding your very own NPC Spawn Tile. Now then What I’ll pretty just doing is simple, just making a new form so you can select the NPC to spawn, adding a new tile attribute and making the server check for spawn NPC tiles and if there is a Spawn NPC Tile, spawn the NPC on that spot, and skip the rest of the routine that will try to spawn the NPC somewhere else."
:: SERVER & CLIENT SIDE ::
First let’s add the Tile Constant to both the client and server so find:
Code:
Public Const TILE_TYPE_KEYOPEN = 6
Code:
Public Const TILE_TYPE_NPCSPAWN = 7
:: SERVER SIDE ::
Find sub SpawnNPC.
Now, just above:
Code:
' Well try 100 times to randomly place the sprite
Code:
'Check if theres a spawn tile for the specific npc
For x = 0 To MAX_MAPX
For y = 0 To MAX_MAPY
If Map(MapNum).Tile(x, y).Type = TILE_TYPE_NPCSPAWN Then
If Map(MapNum).Tile(x, y).Data1 = MapNpcNum Then
MapNpc(MapNum, MapNpcNum).x = x
MapNpc(MapNum, MapNpcNum).y = y
Spawned = True
Exit For
End If
End If
Next y
Next x
Now we need to mod a bit of existing code so that we can skip it if we have already spawned an NPC so just below what you’ve added, change:
Code:
For i = 1 To 100
x = Int(Rnd * MAX_MAPX)
y = Int(Rnd * MAX_MAPY)
' Check if the tile is walkable
If Map(MapNum).Tile(x, y).Type = TILE_TYPE_WALKABLE Then
MapNpc(MapNum, MapNpcNum).x = x
MapNpc(MapNum, MapNpcNum).y = y
Spawned = True
Exit For
End If
Next i
Code:
If Not Spawned Then
' Well try 100 times to randomly place the sprite
For i = 1 To 100
x = Int(Rnd * MAX_MAPX)
y = Int(Rnd * MAX_MAPY)
' Check if the tile is walkable
If Map(MapNum).Tile(x, y).Type = TILE_TYPE_WALKABLE Then
MapNpc(MapNum, MapNpcNum).x = x
MapNpc(MapNum, MapNpcNum).y = y
Spawned = True
Exit For
End If
Next i
End If
:: CLIENT SIDE ::
Now we need to Blt the letter on top of the tiles so find:
Code:
If .Type = TILE_TYPE_KEYOPEN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "O", QBColor(White))
Code:
If .Type = TILE_TYPE_NPCSPAWN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "NS", QBColor(Yellow))
This is the whole section:
Code:
With Map.Tile(x, y)
If .Type = TILE_TYPE_BLOCKED Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "B", QBColor(BrightRed))
If .Type = TILE_TYPE_WARP Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "W", QBColor(BrightBlue))
If .Type = TILE_TYPE_ITEM Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "I", QBColor(White))
If .Type = TILE_TYPE_NPCAVOID Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "N", QBColor(White))
If .Type = TILE_TYPE_KEY Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "K", QBColor(White))
If .Type = TILE_TYPE_KEYOPEN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "O", QBColor(White))
If .Type = TILE_TYPE_NPCSPAWN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "NS", QBColor(Yellow))
End With
The ‘TexthDC’ is kind of like the address or directions to the back buffer surface, and tells it what to write the text on, the next two sections tell the routine where to Blt the text, the next section is what is going to be bltted and the last section if the colour.
Okay, now we have to be able to add this tile type to any tile we click on so find:
Code:
If frmMirage.optKeyOpen.Value = True Then
.Type = TILE_TYPE_KEYOPEN
.Data1 = KeyOpenEditorX
.Data2 = KeyOpenEditorY
.Data3 = 0
End If
Code:
If frmMirage.optNpcSpawn.Value = True Then
.Type = TILE_TYPE_NPCSPAWN
.Data1 = SpawnNpcNum
.Data2 = 0
.Data3 = 0
End If
Okay, we need somewhere to input the tile properties into so add a new form call ‘frmMapSpawnNpc’ and on it at a list box called ‘lstNpc’ and two command button named cmdOk, cmdCancel.
When we load this form, we need to load each npc that is spawned on the map into the list box so that the user can select the npc they wish to spawn, so in form load add:
Code:
Dim n As Long
For n = 1 To MAX_MAP_NPCS
If Map.Npc(n) > 0 Then
lstNpc.AddItem n & ": " & Npc(Map.Npc(n)).Name
Else
lstNpc.AddItem n & ": No Npc"
End If
Next n
Now we need a variable to remember what npc we need to spawn at the spawn point when we place it on the map so find:
Code:
Public KeyOpenEditorY As Long
Below it, add:
Code:
' Used for SpawnNpc editor
Public SpawnNpcNum As Long
Code:
SpawnNpcNum = lstNpc.ListIndex + 1
Unload me
‘Now we just need to add the option button to frmmirage, so goto frmMirage, on the frame with the tile attribs on them, add a new option button called ‘optNpcSpawn’ and on the click event add:
Code:
frmMapSpawnNpc.Show vbModal