Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Help with adding code to serverloop


Justn
 Share

Recommended Posts

Ok I may just be having a brain fart but I am trying to add this piece of code to Sub UpdateMapLogic (ServerLoop).

```
' check if in conversation
                        If MapNpc(mapNum).Npc(x).c_inChatWith > 0 Then
                            ' check if we can stop having conversation
                            If Not TempPlayer(MapNpc(mapNum).Npc(x).c_inChatWith).inChatWith = npcNum Then
                                MapNpc(mapNum).Npc(x).c_inChatWith = 0
                                MapNpc(mapNum).Npc(x).Dir = MapNpc(mapNum).Npc(x).c_lastDir
                                NpcDir mapNum, x, MapNpc(mapNum).Npc(x).Dir
                            End If
                        Else
```
I have used this code before with no problems but now when I add it I am getting an compile error "Next without for" way down into the sub I'm looking at my old project and it seems to be the same but it compiles fine.. If anyone can show me what I did wrong it would be great =/ Here is the main part of the sub the green is what i am trying to add and the red is what im getting an error on.

> ' /////////////////////////////////////////////
>                 ' // This is used for NPC walking/targetting //
>                 ' /////////////////////////////////////////////
>                 ' Make sure theres a npc with the map
>                 If Map(mapNum).NPC(x) > 0 And MapNpc(mapNum).NPC(x).Num > 0 Then
>                     If MapNpc(mapNum).NPC(x).StunDuration > 0 Then
>                         ' check if we can unstun them
>                         If GetTickCount > MapNpc(mapNum).NPC(x).StunTimer + (MapNpc(mapNum).NPC(x).StunDuration * 1000) Then
>                             MapNpc(mapNum).NPC(x).StunDuration = 0
>                             MapNpc(mapNum).NPC(x).StunTimer = 0
>                         End If
>                     Else
>                     ' check if in conversation
>                         If MapNpc(mapNum).Npc(x).c_inChatWith > 0 Then
>                             ' check if we can stop having conversation
>                             If Not TempPlayer(MapNpc(mapNum).Npc(x).c_inChatWith).inChatWith = npcNum Then
>                                 MapNpc(mapNum).Npc(x).c_inChatWith = 0
>                                 MapNpc(mapNum).Npc(x).Dir = MapNpc(mapNum).Npc(x).c_lastDir
>                                 NpcDir mapNum, x, MapNpc(mapNum).Npc(x).Dir
>                             End If
>                         Else  
>                        
>                         target = MapNpc(mapNum).NPC(x).target
>                         targetType = MapNpc(mapNum).NPC(x).targetType
>    
>                         ' Check to see if its time for the npc to walk
>                         If NPC(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER Then
>                        
>                             If targetType = 1 Then ' player
>    
>                                 ' Check to see if we are following a player or not
>                                 If target > 0 Then
>        
>                                     ' Check if the player is even playing, if so follow'm
>                                     If IsPlaying(target) And GetPlayerMap(target) = mapNum Then
>                                         DidWalk = False
>                                         target_verify = True
>                                         TargetY = GetPlayerY(target)
>                                         TargetX = GetPlayerX(target)
>                                     Else
>                                         MapNpc(mapNum).NPC(x).targetType = 0 ' clear
>                                         MapNpc(mapNum).NPC(x).target = 0
>                                     End If
>                                 End If
>                            
>                             ElseIf targetType = 2 Then 'npc
>                                
>                                 If target > 0 Then
>                                    
>                                     If MapNpc(mapNum).NPC(target).Num > 0 Then
>                                         DidWalk = False
>                                         target_verify = True
>                                         TargetY = MapNpc(mapNum).NPC(target).y
>                                         TargetX = MapNpc(mapNum).NPC(target).x
>                                     Else
>                                         MapNpc(mapNum).NPC(x).targetType = 0 ' clear
>                                         MapNpc(mapNum).NPC(x).target = 0
>                                     End If
>                                 End If
>                             End If
>                            
>                             If target_verify Then
>                                
>                                 i = Int(Rnd * 5)
>    
>                                 ' Lets move the npc
>                                 Select Case i
>                                     Case 0
>    
>                                         ' Up
>                                         If MapNpc(mapNum).NPC(x).y > TargetY And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_UP) Then
>                                                 Call NpcMove(mapNum, x, DIR_UP, MOVING_WALKING)
>                                                 If CanNpcMove(mapNum, x, DIR_UP) Then Call NpcMove(mapNum, x, DIR_UP, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Down
>                                         If MapNpc(mapNum).NPC(x).y < TargetY And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_DOWN) Then
>                                                 Call NpcMove(mapNum, x, DIR_DOWN, MOVING_WALKING)
>                                                 If CanNpcMove(mapNum, x, DIR_DOWN) Then Call NpcMove(mapNum, x, DIR_DOWN, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Left
>                                         If MapNpc(mapNum).NPC(x).x > TargetX And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_LEFT) Then
>                                                 Call NpcMove(mapNum, x, DIR_LEFT, MOVING_WALKING)
>                                                 If CanNpcMove(mapNum, x, DIR_LEFT) Then Call NpcMove(mapNum, x, DIR_LEFT, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Right
>                                         If MapNpc(mapNum).NPC(x).x < TargetX And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_RIGHT) Then
>                                                 Call NpcMove(mapNum, x, DIR_RIGHT, MOVING_WALKING)
>                                                 If CanNpcMove(mapNum, x, DIR_RIGHT) Then Call NpcMove(mapNum, x, DIR_RIGHT, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                     Case 1
>    
>                                         ' Right
>                                         If MapNpc(mapNum).NPC(x).x < TargetX And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_RIGHT) Then
>                                                 Call NpcMove(mapNum, x, DIR_RIGHT, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Left
>                                         If MapNpc(mapNum).NPC(x).x > TargetX And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_LEFT) Then
>                                                 Call NpcMove(mapNum, x, DIR_LEFT, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Down
>                                         If MapNpc(mapNum).NPC(x).y < TargetY And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_DOWN) Then
>                                                 Call NpcMove(mapNum, x, DIR_DOWN, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Up
>                                         If MapNpc(mapNum).NPC(x).y > TargetY And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_UP) Then
>                                                 Call NpcMove(mapNum, x, DIR_UP, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                     Case 2
>    
>                                         ' Down
>                                         If MapNpc(mapNum).NPC(x).y < TargetY And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_DOWN) Then
>                                                 Call NpcMove(mapNum, x, DIR_DOWN, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Up
>                                         If MapNpc(mapNum).NPC(x).y > TargetY And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_UP) Then
>                                                 Call NpcMove(mapNum, x, DIR_UP, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Right
>                                         If MapNpc(mapNum).NPC(x).x < TargetX And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_RIGHT) Then
>                                                 Call NpcMove(mapNum, x, DIR_RIGHT, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Left
>                                         If MapNpc(mapNum).NPC(x).x > TargetX And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_LEFT) Then
>                                                 Call NpcMove(mapNum, x, DIR_LEFT, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                     Case 3
>    
>                                         ' Left
>                                         If MapNpc(mapNum).NPC(x).x > TargetX And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_LEFT) Then
>                                                 Call NpcMove(mapNum, x, DIR_LEFT, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Right
>                                         If MapNpc(mapNum).NPC(x).x < TargetX And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_RIGHT) Then
>                                                 Call NpcMove(mapNum, x, DIR_RIGHT, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Up
>                                         If MapNpc(mapNum).NPC(x).y > TargetY And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_UP) Then
>                                                 Call NpcMove(mapNum, x, DIR_UP, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                         ' Down
>                                         If MapNpc(mapNum).NPC(x).y < TargetY And Not DidWalk Then
>                                             If CanNpcMove(mapNum, x, DIR_DOWN) Then
>                                                 Call NpcMove(mapNum, x, DIR_DOWN, MOVING_WALKING)
>                                                 DidWalk = True
>                                             End If
>                                         End If
>    
>                                 End Select
>    
>                                 ' Check if we can't move and if Target is behind something and if we can just switch dirs
>                                 If Not DidWalk Then
>                                     If MapNpc(mapNum).NPC(x).x - 1 = TargetX And MapNpc(mapNum).NPC(x).y = TargetY Then
>                                         If MapNpc(mapNum).NPC(x).Dir <> DIR_LEFT Then
>                                             Call NpcDir(mapNum, x, DIR_LEFT)
>                                         End If
>    
>                                         DidWalk = True
>                                     End If
>    
>                                     If MapNpc(mapNum).NPC(x).x + 1 = TargetX And MapNpc(mapNum).NPC(x).y = TargetY Then
>                                         If MapNpc(mapNum).NPC(x).Dir <> DIR_RIGHT Then
>                                             Call NpcDir(mapNum, x, DIR_RIGHT)
>                                         End If
>    
>                                         DidWalk = True
>                                     End If
>    
>                                     If MapNpc(mapNum).NPC(x).x = TargetX And MapNpc(mapNum).NPC(x).y - 1 = TargetY Then
>                                         If MapNpc(mapNum).NPC(x).Dir <> DIR_UP Then
>                                             Call NpcDir(mapNum, x, DIR_UP)
>                                         End If
>    
>                                         DidWalk = True
>                                     End If
>    
>                                     If MapNpc(mapNum).NPC(x).x = TargetX And MapNpc(mapNum).NPC(x).y + 1 = TargetY Then
>                                         If MapNpc(mapNum).NPC(x).Dir <> DIR_DOWN Then
>                                             Call NpcDir(mapNum, x, DIR_DOWN)
>                                         End If
>    
>                                         DidWalk = True
>                                     End If
>    
>                                     ' We could not move so Target must be behind something, walk randomly.
>                                     If Not DidWalk Then
>                                         i = Int(Rnd * 2)
>    
>                                         If i = 1 Then
>                                             i = Int(Rnd * 4)
>    
>                                             If CanNpcMove(mapNum, x, i) Then
>                                                 Call NpcMove(mapNum, x, i, MOVING_WALKING)
>                                             End If
>                                         End If
>                                     End If
>                                 End If
>    
>                             Else
>                                 i = Int(Rnd * 4)
>    
>                                 If i = 1 Then
>                                     i = Int(Rnd * 4)
>    
>                                     If CanNpcMove(mapNum, x, i) Then
>                                         Call NpcMove(mapNum, x, i, MOVING_WALKING)
>                                     End If
>                                 End If
>                             End If
>                         End If
>                     End If
>                 End If
>
>                 ' /////////////////////////////////////////////
>                 ' // This is used for npcs to attack targets //
>                 ' /////////////////////////////////////////////
>                 ' Make sure theres a npc with the map
>                 If Map(mapNum).NPC(x) > 0 And MapNpc(mapNum).NPC(x).Num > 0 Then
>                     target = MapNpc(mapNum).NPC(x).target
>                     targetType = MapNpc(mapNum).NPC(x).targetType
>
>                     ' Check if the npc can attack the targeted player player
>                     If target > 0 Then
>                    
>                         If targetType = 1 Then ' player
>
>                             ' Is the target playing and on the same map?
>                             If IsPlaying(target) And GetPlayerMap(target) = mapNum Then
>                                 TryNpcAttackPlayer x, target
>                             Else
>                                 ' Player left map or game, set target to 0
>                                 MapNpc(mapNum).NPC(x).target = 0
>                                 MapNpc(mapNum).NPC(x).targetType = 0 ' clear
>                             End If
>                     End If
>                 End If
>                
>                                             ' Spell Casting
>                                 For i = 1 To MAX_NPC_SPELLS
>                                     If NPC(npcNum).Spell(i) > 0 Then
>                                         If MapNpc(mapNum).NPC(x).SpellTimer(i) + (Spell(NPC(npcNum).Spell(i)).CastTime * 1000) < GetTickCount Then
>                                             NpcSpellPlayer x, target, i
>                                         End If
>                                     End If
>                                 Next
>                             End If
>
>                 ' ////////////////////////////////////////////
>                 ' // This is used for regenerating NPC's HP //
>                 ' ////////////////////////////////////////////
>                 ' Check to see if we want to regen some of the npc's hp
>                 If Not MapNpc(mapNum).NPC(x).stopRegen Then
>                     If MapNpc(mapNum).NPC(x).Num > 0 And TickCount > GiveNPCHPTimer + 10000 Then
>                         If MapNpc(mapNum).NPC(x).Vital(Vitals.HP) > 0 Then
>                             MapNpc(mapNum).NPC(x).Vital(Vitals.HP) = MapNpc(mapNum).NPC(x).Vital(Vitals.HP) + GetNpcVitalRegen(npcNum, Vitals.HP)
>    
>                             ' Check if they have more then they should and if so just set it to max
>                             If MapNpc(mapNum).NPC(x).Vital(Vitals.HP) > GetNpcMaxVital(npcNum, Vitals.HP) Then
>                                 MapNpc(mapNum).NPC(x).Vital(Vitals.HP) = GetNpcMaxVital(npcNum, Vitals.HP)
>                             End If
>                         End If
>                     End If
>                 End If
>
>                 ' ////////////////////////////////////////////////////////
>                 ' // This is used for checking if an NPC is dead or not //
>                 ' ////////////////////////////////////////////////////////
>                 ' Check if the npc is dead or not
>                 'If MapNpc(y, x).Num > 0 Then
>                 '    If MapNpc(y, x).HP <= 0 And Npc(MapNpc(y, x).Num).STR > 0 And Npc(MapNpc(y, x).Num).DEF > 0 Then
>                 '        MapNpc(y, x).Num = 0
>                 '        MapNpc(y, x).SpawnWait = TickCount
>                 '  End If
>                 'End If
>                
>                 ' //////////////////////////////////////
>                 ' // This is used for spawning an NPC //
>                 ' //////////////////////////////////////
>                 ' Check if we are supposed to spawn an npc or not
>                 If MapNpc(mapNum).NPC(x).Num = 0 And Map(mapNum).NPC(x) > 0 Then
>                     If TickCount > MapNpc(mapNum).NPC(x).SpawnWait + (NPC(Map(mapNum).NPC(x)).SpawnSecs * 1000) Then
>                         Call SpawnNpc(x, mapNum)
>                     End If
>                 End If
>
>             **Next**
>
>         End If
>
>         DoEvents
>     Next
>
>     ' Make sure we reset the timer for npc hp regeneration
>     If GetTickCount > GiveNPCHPTimer + 10000 Then
>         GiveNPCHPTimer = GetTickCount
>     End If
>
>     ' Make sure we reset the timer for door closing
>     If GetTickCount > KeyTimer + 15000 Then
>         KeyTimer = GetTickCount
>     End If
>
> End Sub
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...