Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spawn NPC Tiles
#1
I made a new tile type called TILE_TYPE_SCRIPT
This doesn't acutally load any kind of script, I just called it script cuz it can serve multiple purposes.

Anyways, .Data3 carried by TILE_TYPE_SCRIPT gets saved and loaded properly (Data2 doesn't have a purpose until I get weather implimented into my game, and the code that uses .Data1 works perfectly fine) however, .Data3 is supposed to be an NPC spawn, but for some reason, it only seems to work right if I use NPC Number 1 (In which case, happens to be a drunken sea pirate).

Below are snips of my spawn npc code:
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_SCRIPT Then
                       If MAP(MapNum).Tile(x, y).Data2 = MapNpcNum Then
                           MapNpc(MapNum, MapNpcNum).x = x
                           MapNpc(MapNum, MapNpcNum).y = y
                           Spawned = True
                           Exit For
                       End If
                  End If
              Next y
        Next x
        
        ' Well try 100 times to randomly place the sprite
        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
        
        ' Didn't spawn, so now we'll just try to find a free tile
        If Not Spawned Then
            For y = 0 To MAX_MAPY
                For x = 0 To MAX_MAPX
                    If MAP(MapNum).Tile(x, y).Type = TILE_TYPE_WALKABLE Then
                        MapNpc(MapNum, MapNpcNum).x = x
                        MapNpc(MapNum, MapNpcNum).y = y
                        Spawned = True
                    End If
                Next x
            Next y
        End If

I could post the whole code, but I'm pretty sure the problem is in one of the If Statments above.

So, if anyone sees anything wrong with this code, please let me know, I'd really like to get this to function correctly Smile

[Edit]
Heh, nevermind. I see what I did wrong. I didn't fully understand how the system worked xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)