 Rem File: Dndsub4 for Dndbbs Version v5.0a Release r2.0 Tweak t5.0a
 Rem $Include: 'dndbbs.inc'

Sub Numeric
 On Local Error Goto ErrorTrp6
 Var=False
 Var1=Instr(Parsed.Command1,"#")
 If Var1 Then
    Var=Int(Val(Mid$(Parsed.Command1,Var1+1))+.5)
    Parsed.Command1=Left$(Parsed.Command1,Var1-1)
 Endif
 Parse.Temp=Var
ErrorRsm6:
 Exit Sub
ErrorTrp6:
 Resume ErrorRsm6
End Sub

Sub Numeric2
 On Local Error Goto ErrorTrp6a
 Var=False
 Var1=Instr(Temp.Command,"#")
 If Var1 Then
    Var=Int(Val(Mid$(Temp.Command,Var1+1))+.5)
    Temp.Command=Left$(Temp.Command,Var1-1)
    User.Command=Left$(User.Command,Var1-1)
 Endif
 Parse.Temp=Var
ErrorRsm6a:
 Exit Sub
ErrorTrp6a:
 Resume ErrorRsm6a
End Sub

Sub Drop.Inventory(Var1!,Var2)
 On Local Error Goto ErrorTrp27
 VarX!=Lof(RoomInvFile)/MessWorkRecLen6+1!
 MessWorkRecord6.Room=Room
 MessWorkRecord6.User=SFalse
 MessWorkRecord6.Index=Var1!
 MessWorkRecord6.Charges=Var2
 MessWorkRecord6.Plus=False
 Call Write.Record(RoomInvFile,VarX!)
 Call Add.List.Node(VarX!)
ErrorRsm27:
 Exit Sub
ErrorTrp27:
 Resume ErrorRsm27
End Sub

Sub Add.List.Node(VarZ!)
 On Local Error Goto ErrorTrp27a
 Call Read.Record(RoomFile,Room)
 If RoomRecord.First=SFalse Then
    RoomRecord.First=VarZ!
    RoomRecord.Last=VarZ!
    Call Write.Record(RoomFile,Room)
    MessWorkRecord6.Prev=SFalse
    MessWorkRecord6.Next=SFalse
    Call Write.Record(RoomInvFile,VarZ!)
    Exit Sub
 Endif
 MessWorkRecord6.Prev=RoomRecord.Last
 MessWorkRecord6.Next=SFalse
 Call Write.Record(RoomInvFile,VarZ!)
 Call Read.Record(RoomInvFile,RoomRecord.Last)
 MessWorkRecord6.Next=VarZ!
 Call Write.Record(RoomInvFile,RoomRecord.Last)
 Call Read.Record(RoomInvFile,VarZ!)
 RoomRecord.Last=VarZ!
 Call Write.Record(RoomFile,Room)
ErrorRsm27a:
 Exit Sub
ErrorTrp27a:
 Resume ErrorRsm27a
End Sub

Sub Discard(Var1!,Var2)
 On Local Error Goto ErrorTrp28
 Call Read.Record(MessWorkFile6,Var1!)
 VarA!=MessWorkRecord6.Index
 VarB=MessWorkRecord6.Charges
 If VarA!>SFalse Then
    Call Read.Record(TreasureFile,VarA!)
    Weight=Weight-TreasureRecord.Weight
    If Weight<DFalse Then
       Weight=DFalse
    Endif
 Endif
 MessWorkRecord6.User=SFalse
 Call Write.Record(MessWorkFile6,Var1!)
 If Var2=False Then
    Call Drop.Inventory(VarA!,VarB)
 Endif
 For Var=1 To 4
    MessWorkRecord6.Desc(Var)=0!
 Next
 Call Write.Record(MessWorkFile6,Var1!)
ErrorRsm28:
 Exit Sub
ErrorTrp28:
 Resume ErrorRsm28
End Sub

Sub Add.Inventory(Var1!,Var2)
 On Local Error Goto ErrorTrp29
 VarQ1!=MessWorkRecord6.Desc(1)
 VarQ2!=MessWorkRecord6.Desc(2)
 VarQ3!=MessWorkRecord6.Desc(3)
 VarQ4!=MessWorkRecord6.Desc(4)
' Call Pack.Inventory(Var!)
 Var!=Lof(MessWorkFile6)/MessWorkRecLen6+1!
 Temp0!=Var!
 If Var!=SFalse Then
    Exit Sub
 Endif
 MessWorkRecord6.User=User.Index
 MessWorkRecord6.Room=SFalse
 MessWorkRecord6.Index=Var1!
 MessWorkRecord6.Charges=Var2
 MessWorkRecord6.Plus=False
 MessWorkRecord6.Prev=SFalse
 MessWorkRecord6.Next=SFalse
 If Var1!>SFalse Then
    Weight=Weight+TreasureRecord.Weight
    VarX=TreasureRecord.Plus
    If TreasureRecord.Spell Then
       Call Read.Record(SpellFile,TreasureRecord.Spell)
       VarX=SpellRecord.Level
    Endif
    MessWorkRecord6.Plus=VarX
 Endif
 MessWorkRecord6.Desc(1)=VarQ1!
 MessWorkRecord6.Desc(2)=VarQ2!
 MessWorkRecord6.Desc(3)=VarQ3!
 MessWorkRecord6.Desc(4)=VarQ4!
 Call Write.Record(MessWorkFile6,Var!)
ErrorRsm29:
 Exit Sub
ErrorTrp29:
 Resume ErrorRsm29
End Sub

Sub Clear.List.Node
 On Local Error Goto ErrorTrp32b
 MessWorkRecord6.User=SFalse
 MessWorkRecord6.Room=SFalse
 MessWorkRecord6.Index=SFalse
 MessWorkRecord6.Charges=False
 MessWorkRecord6.Plus=False
 MessWorkRecord6.Prev=SFalse
 MessWorkRecord6.Next=SFalse
 For Var=1 To 4
    MessWorkRecord6.Desc(Var)=0!
 Next
ErrorRsm32b:
 Exit Sub
ErrorTrp32b:
 Resume ErrorRsm32b
End Sub

Sub Delete.List.Node(VarZ!)
 On Local Error Goto ErrorTrp32a
 Call Read.Record(RoomFile,Room)
 If RoomRecord.First=VarZ! Then
    Call Read.Record(RoomInvFile,VarZ!)
    RoomRecord.First=MessWorkRecord6.Next
    Call Write.Record(RoomFile,Room)
    If RoomRecord.First>SFalse Then
       Call Read.Record(RoomInvFile,RoomRecord.First)
       MessWorkRecord6.Prev=SFalse
       Call Write.Record(RoomInvFile,RoomRecord.First)
    Endif
 Else
    If RoomRecord.Last=VarZ! Then
       Call Read.Record(RoomInvFile,VarZ!)
       RoomRecord.Last=MessWorkRecord6.Prev
       Call Write.Record(RoomFile,Room)
       If RoomRecord.Last>SFalse Then
          Call Read.Record(RoomInvFile,RoomRecord.Last)
          MessWorkRecord6.Next=SFalse
          Call Write.Record(RoomInvFile,RoomRecord.Last)
       Endif
    Else
       Call Read.Record(RoomInvFile,VarZ!)
       Previous.Node!=MessWorkRecord6.Prev
       Next.Node!=MessWorkRecord6.Next
       Call Read.Record(RoomInvFile,Previous.Node!)
       MessWorkRecord6.Next=Next.Node!
       Call Write.Record(RoomInvFile,Previous.Node!)
       Call Read.Record(RoomInvFile,Next.Node!)
       MessWorkRecord6.Prev=Previous.Node!
       Call Write.Record(RoomInvFile,Next.Node!)
       Call Read.Record(RoomInvFile,VarZ!)
    Endif
 Endif
ErrorRsm32a:
 Exit Sub
ErrorTrp32a:
 Resume ErrorRsm32a
End Sub

Sub Delete.User.Container(VarZ!)
 On Local Error Goto ErrorTrp32d
 If UserRecord.First2=VarZ! Then
    Call Read.Record(ContainerFile,VarZ!)
    UserRecord.First2=ContainerRecord.Next
    Call Write.Record(UserFile,User.Index)
    If UserRecord.First2>SFalse Then
       Call Read.Record(ContainerFile,UserRecord.First2)
       ContainerRecord.Prev=SFalse
       Call Write.Record(ContainerFile,UserRecord.First2)
    Endif
 Else
    If UserRecord.Last2=VarZ! Then
       Call Read.Record(ContainerFile,VarZ!)
       UserRecord.Last2=ContainerRecord.Prev
       Call Write.Record(UserFile,User.Index)
       If UserRecord.Last2>SFalse Then
          Call Read.Record(ContainerFile,UserRecord.Last2)
          ContainerRecord.Next=SFalse
          Call Write.Record(ContainerFile,UserRecord.Last2)
       Endif
    Else
       Call Read.Record(ContainerFile,VarZ!)
       Previous.Node!=ContainerRecord.Prev
       Next.Node!=ContainerRecord.Next
       Call Read.Record(ContainerFile,Previous.Node!)
       ContainerRecord.Next=Next.Node!
       Call Write.Record(ContainerFile,Previous.Node!)
       Call Read.Record(ContainerFile,Next.Node!)
       ContainerRecord.Prev=Previous.Node!
       Call Write.Record(ContainerFile,Next.Node!)
    Endif
 Endif
ErrorRsm32d:
 Exit Sub
ErrorTrp32d:
 Resume ErrorRsm32d
End Sub

Sub System.News
 On Local Error Goto ErrorTrp42
 Filename=DND.Path+"SYSNEWS.DAT"
 If Dir$(Filename)=Nul Then
    Strng="No system news for "+DateS$
    Call IO.O
    Exit Sub
 Endif
 Close #TempFile1
 Open Filename For Input Shared As #TempFile1
 Var=False
 Temp=1
 Allow.Break=True
 Break=False
 Continuous=False
 If UserRecord.SysNews=String$(10,Chr$(0)) Then
    Temp#=DateValue("01-01-1980")
 Else
    Temp#=DateValue(UserRecord.SysNews)
 Endif
 Line1!=0!
 Do While Security.Guard
    If Lost.Carrier Then
       Exit Do
    Endif
    If Eof(TempFile1) Then
       Exit Do
    Endif
    Line Input #TempFile1,Strng
    Line1!=Line1!+1!
    If Lcase$(Left$(Strng,6))="date: " Then
       Var=False
       Var$ = Mid$(Strng,7,10)
       If ValidDate(Var$)=0 Then
          Strng="Invalid Date in line:"+Str$(Line1!)+"."
          Call IO.O
       Else
          Temp2#=DateValue(Var$)
          If Temp2#>Temp# Then
             Var=True
             Graphics.Off=False
             Call IO.O
             Temp=Temp+1
          Endif
       Endif
    Else
       If Var Then
          No=0:Quit=0
          Graphics.Off=True
          Call Convert.String
          Call Convert.ANSI(True,VarQ,VarR)
          If No Or Quit Then ' possible moreprompt
             Strng=Nul:Out2=Nul
             Exit Do
          Endif
          Graphics.On=True
          Call IO.O
          Graphics.On=False
          If Break Then
             Exit Do
          Endif
          Temp=Temp+1
          If Temp>=User.PageLength-2 Then
             Temp=False
             If Continuous=False Then
                Call More.Prompt
                If No Or Quit Then
                   Exit Do
                Endif
             Endif
          Endif
       Endif
    Endif
 Loop
 Allow.Break=False
 Break=False
 Graphics.Off=False
 Strng="End of system news."
 Call IO.O
 Call More.Prompt
ErrorRsm42:
 Strng="[xon]"
 Call Convert.String
 Call Playwav(15) ' turn on playwav
 UserRecord.SysNews=DateS$
 Call Write.Record(UserFile,User.Index)
 Exit Sub
ErrorTrp42:
 Strng="Error:"+Str$(Err)
 If Err=5 Then
    Strng="Syntax error."
 Endif
 Call IO.O
 Resume ErrorRsm42
End Sub

Sub Read.User.Inventory
 On Local Error Goto ErrorTrp51
 Call Read.Record(UserFile,User.Index)
 For Var!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
    Call Read.Record(MessWorkFile6,Var!)
    If MessWorkRecord6.User=User.Index Then
       MessWorkRecord6.User=SFalse
       Call Write.Record(MessWorkFile6,Var!)
    Endif
 Next
 Weight=False
 Var1!=UserRecord.First
 If Var1! Then
    Do While Lost.Carrier=False
       Call Read.Record(UserInvFile,Var1!)
       Var3!=MessWorkRecord6.Next
       Temp1!=MessWorkRecord6.Index
       Temp2=MessWorkRecord6.Charges
       VarQ1!=MessWorkRecord6.Desc(1)
       VarQ2!=MessWorkRecord6.Desc(2)
       VarQ3!=MessWorkRecord6.Desc(3)
       VarQ4!=MessWorkRecord6.Desc(4)
       VarX=False
       If Temp1!>SFalse And Temp1!<=Lof(TreasureFile)/TreasureRecLen Then
          Call Read.Record(TreasureFile,Temp1!)
          If TreasureRecord.Container Then
             Call Add.Container.To.User(Temp1!)
             Temp1!=SFalse
          Else
             Weight=Weight+TreasureRecord.Weight
             VarX=TreasureRecord.Plus
             If TreasureRecord.Spell Then
                Call Read.Record(SpellFile,TreasureRecord.Spell)
                VarX=SpellRecord.Level
             Endif
          Endif
       Endif
       If Temp1! Then
          For Var2!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
             Call Read.Record(MessWorkFile6,Var2!)
             If MessWorkRecord6.User=SFalse Then
                Exit For
             Endif
          Next
          MessWorkRecord6.Index=Temp1!
          MessWorkRecord6.Charges=Temp2
          MessWorkRecord6.User=User.Index
          MessWorkRecord6.Plus=VarX
          MessWorkRecord6.Desc(1)=VarQ1!
          MessWorkRecord6.Desc(2)=VarQ2!
          MessWorkRecord6.Desc(3)=VarQ3!
          MessWorkRecord6.Desc(4)=VarQ4!
          Call Write.Record(MessWorkFile6,Var2!)
       Endif
       If Var3!=SFalse Then
          Exit Do
       Endif
       Var1!=Var3!
    Loop
 Endif
 Temp5!=UserRecord.First2
 If Temp5! Then
    Do While Lost.Carrier=False
       Call Read.Record(ContainerFile,Temp5!)
       Var6!=ContainerRecord.Next
       If ContainerRecord.DeletedContainer=False Then
          If ContainerRecord.WithinContainer=SFalse Then
             Weight=Weight+ContainerRecord.Weight
          Endif
       Endif
       If Var6!=SFalse Then
          Exit Do
       Endif
       Temp5!=Var6!
    Loop
 Endif
ErrorRsm51:
 Exit Sub
ErrorTrp51:
 Resume ErrorRsm51
End Sub

Sub Get.User.Record
 On Local Error Goto ErrorTrp52
 Call Read.Record(UserFile,User.Index)
 Room=UserRecord.Room
 Sorting=UserRecord.SortInv
 Call Get.User.Stats(Temp)
 If Temp=False Then
    Call Hang.Up(12)
 Endif
 If UserRecord.Hidden Then
    If Config2(13) Then
       Hidden.Player=True
    Endif
 Else
    Hidden.Player=Config2(13)
 Endif
ErrorRsm52:
 Exit Sub
ErrorTrp52:
 Resume ErrorRsm52
End Sub

Sub Put.User.Record
 On Local Error Goto ErrorTrp54
 If User.Index=SFalse Then
    Exit Sub
 Endif
 Var$=UserRecord.CodeName
 Call Valid.Name(Var$)
 If TempA=False Then
    Exit Sub
 Endif
 If Rtrim$(Var$)=Nul Then
    Exit Sub
 Endif
 For Temp7!=1! To Lof(UserInvFile)/MessWorkRecLen6
    Call Read.Record(UserInvFile,Temp7!)
    If MessWorkRecord6.User=User.Index Then
       MessWorkRecord6.Room=SFalse
       MessWorkRecord6.User=SFalse
       MessWorkRecord6.Index=SFalse
       MessWorkRecord6.Charges=False
       MessWorkRecord6.Plus=False
       MessWorkRecord6.Prev=SFalse
       MessWorkRecord6.Next=SFalse
       For Var=1 To 4
          MessWorkRecord6.Desc(Var)=SFalse
       Next
       Call Write.Record(UserInvFile,Temp7!)
    Endif
 Next
 UserRecord.First=SFalse
 UserRecord.Last=SFalse
 Call Write.Record(UserFile,User.Index)
 For Temp7!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
    Call Read.Record(MessWorkFile6,Temp7!)
    If MessWorkRecord6.User=User.Index Then
       Temp6!=Lof(UserInvFile)/MessWorkRecLen6+1!
       Call Add.List.Node3(Temp6!)
    Endif
 Next
 Call Write.User.Record
ErrorRsm54:
 Exit Sub
ErrorTrp54:
 Resume ErrorRsm54
End Sub

Sub Write.User.Record
 On Local Error Goto ErrorTrp55
 UserRecord.Room=Room
 UserRecord.SortInv=Sorting
 UserRecord.Hidden=Hidden.Player
 Call Write.Record(UserFile,User.Index)
ErrorRsm55:
 Exit Sub
ErrorTrp55:
 Resume ErrorRsm55
End Sub

Sub Add.List.Node3(VarZ!)
 On Local Error Goto ErrorTrp27b
 If UserRecord.First=SFalse Then
    UserRecord.First=VarZ!
    UserRecord.Last=VarZ!
    Call Write.Record(UserFile,User.Index)
    MessWorkRecord6.Prev=SFalse
    MessWorkRecord6.Next=SFalse
    Call Write.Record(UserInvFile,VarZ!)
    Exit Sub
 Endif
 MessWorkRecord6.Prev=UserRecord.Last
 MessWorkRecord6.Next=SFalse
 Call Write.Record(UserInvFile,VarZ!)
 Call Read.Record(UserInvFile,UserRecord.Last)
 MessWorkRecord6.Next=VarZ!
 Call Write.Record(UserInvFile,UserRecord.Last)
 Call Read.Record(UserInvFile,VarZ!)
 UserRecord.Last=VarZ!
 Call Write.Record(UserFile,User.Index)
ErrorRsm27b:
 Exit Sub
ErrorTrp27b:
 Resume ErrorRsm27b
End Sub

Sub Record.Time(Var)
 On Local Error Goto ErrorTrp55a
 Gosub Get.Config1
 If Var Then
    If UserRecord.TimeLimit>SFalse Then
       Var!=Timeit!-Timeon
       If Var!<SFalse Then
          Var!=Var!+86400!
       Endif
       UserRecord.TimeUsed=UserRecord.TimeUsed+Var!
    Endif
 Else
    UserRecord.TimeUsed=Csng(UserRecord.TimeLimit*60!)
 Endif
 UserRecord.TimesLogon=UserRecord.TimesLogon+1#
 If Option1#>0# Then
    If (UserRecord.TimesLogon Mod Option1#)=0# Then
       UserRecord.Gold=UserRecord.Gold+Option2#
       Call Amount(Option1#,Var1$)
       Call Amount(Option2#,Var2$)
       Strng="You are awarded "+Var2$+" gold for logging on "+Var1$+" times!"
       Call IO.O
       Strng="was rewarded for logging in"
       Call Update.DayFile(Strng,False,2)
    Endif
 Endif
 Call Write.Record(UserFile,User.Index)
 Exit Sub
Get.Config1:
 Option1#=1000000#
 Option2#=10000#
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[TRAIN]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          If Ucase$(Var$)="[END]" Then
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Select Case Lcase$(Var2$)
             Case "times.logon.counter"
                If Int(Val(Var3$)+.5)>0# Then
                   Option1#=Int(Val(Var3$)+.5)
                Endif
             Case "times.logon.reward"
                If Int(Val(Var3$)+.5)>0# Then
                   Option2#=Int(Val(Var3$)+.5)
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrorRsm55a:
 Exit Sub
ErrorTrp55a:
 Resume ErrorRsm55a
End Sub

Sub Actions(VarZ!)
 On Local Error Goto ErrorTrp58
 Gosub Get.Config2
 ' check actions in safe room
 Call Safe.Room
 If TempA Then
    Exit Sub
 Endif
 ' check actions in sanctuary
 If Room=Int(Val(Config3(24))+.5) Then
    Exit Sub
 Endif
 ' check action reccord number
 If VarZ!<=SFalse Or VarZ!>Lof(ActionFile)/ActionRecLen Then
    Exit Sub
 Endif
 ' read action record
 Call Read.Record(ActionFile,VarZ!)
 ' check inventory action
 Graphics.Off=False
 Out2=Nul
 Var1=ActionRecord.Inventory
 If Var1 Then
    Temp4=False
    VarX=False
    Var2!=UserRecord.Weapon(4).Index
    If Var2! Then
       Call Read.Record(TreasureFile,Var2!)
       If TreasureRecord.RingType=7 Then
          VarX=True
          Call Get.Ring.Hits(True,7)
       Endif
    Endif
    If VarX=False Then
       Var2!=UserRecord.Weapon(9).Index
       If Var2! Then
          Call Read.Record(TreasureFile,Var2!)
          If TreasureRecord.RingType=7 Then
             VarX=True
             Call Get.Ring.Hits(False,7)
          Endif
       Endif
    Endif
    If VarX=False Then
       Temp5=False
       For Temp2!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
          Call Read.Record(MessWorkFile6,Temp2!)
          If MessWorkRecord6.User=User.Index Then
             VarQ!=MessWorkRecord6.Index
             If VarQ!>SFalse And VarQ!<=Lof(TreasureFile)/TreasureRecLen Then
                Call Read.Record(TreasureFile,VarQ!)
                If TreasureRecord.WeaponNumber=Var1 Then
                   If MessWorkRecord6.Charges>False Then
                      Temp4=True
                      If ActionRecord.InvPercent>False Then
                         If Int(Rnd*100+1)>ActionRecord.InvPercent Then
                            Temp4=False
                         Endif
                      Endif
                      If Temp4 Then
                         If ActionRecord.InvNumber>False Then
                            If Temp5>=ActionRecord.InvNumber Then
                               Temp4=False
                            Endif
                         Endif
                         If Temp4 Then
                            Temp5=Temp5+1
                            MessWorkRecord6.Charges=False
                            Call Write.Record(MessWorkFile6,Temp2!)
                         Endif
                      Endif
                   Endif
                Endif
             Endif
          Endif
       Next
       If Temp5 Then
          Strng=Out3
          Call IO.O
          Strng2=Rtrim$(InventoryNames(Var1))
          Select Case Var1
          Case 1
             Strng2=Strng2+" breaks"
          Case 2 To 8
             Strng2=Strng2+"s break"
          End Select
          If ActionRecord.InvPercent Or ActionRecord.InvNumber Then
             If Temp5>=1 And Temp5<=10 Then
                Strng=Rtrim$(Numeral(Temp5))
             Else
                Strng=Mid$(Str$(Temp5),2)
             Endif
             Strng=Strng+" of your "+Strng2+"!"
             Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
          Else
             Strng="All your "+Strng2+"!"
          Endif
          Call IO.O
       Endif
    Endif
 Endif
 ' check fumble action
 If ActionRecord.Fumble Then
    VarX=False
    Var2!=UserRecord.Weapon(4).Index
    If Var2! Then
       Call Read.Record(TreasureFile,Var2!)
       If TreasureRecord.RingType=8 Then
          VarX=True
          Call Get.Ring.Hits(True,8)
       Endif
    Endif
    If VarX=False Then
       Var2!=UserRecord.Weapon(9).Index
       If Var2! Then
          Call Read.Record(TreasureFile,Var2!)
          If TreasureRecord.RingType=8 Then
             VarX=True
             Call Get.Ring.Hits(False,8)
          Endif
       Endif
    Endif
    If VarX=False Then
       Call Fumble
    Endif
 Endif
 ' verify teleport action exists
 VarQ=False
 For TempQ=1 To 5
    If ActionRecord.Teleport(TempQ)>SFalse Then
       If ActionRecord.Teleport(TempQ)<>Room Then
          VarQ=True
          Exit For
       Endif
    Endif
 Next
 ' check teleport action
 If VarQ Then
    ' check ring activity
    VarX=False
    Var2!=UserRecord.Weapon(4).Index
    If Var2! Then
       Call Read.Record(TreasureFile,Var2!)
       If TreasureRecord.RingType=9 Then
          VarX=True
          Call Get.Ring.Hits(True,9)
       Endif
    Endif
    If VarX=False Then
       Var2!=UserRecord.Weapon(9).Index
       If Var2! Then
          Call Read.Record(TreasureFile,Var2!)
          If TreasureRecord.RingType=9 Then
             VarX=True
             Call Get.Ring.Hits(False,9)
          Endif
       Endif
    Endif
    ' verify teleport percent
    If ActionRecord.TelePercent>False Then
       If Int(Rnd*100+1)>ActionRecord.TelePercent Then
          VarX=True
       Endif
    Endif
    If VarX=False Then
       ' find teleport room number
       VarZ=0
       Do
          ' check indefinite loop
          VarZ=VarZ+1
          If VarZ>1024 Then
             Action.Recurse=Option1
             Exit Do
          Endif
          ' get teleport room number
          VarY=Int(Rnd*5+1)
          If ActionRecord.Teleport(VarY)>SFalse Then
             If ActionRecord.Teleport(VarY)<>Room Then
                Exit Do
             Endif
          Endif
       Loop
       ' check teleport room number
       Action.Recurse=Action.Recurse+1
       If Action.Recurse>Option1 Then
          Strng="Action recurse error."
          Call IO.O
          Strng="You are teleported to a safe room!"
          Call IO.O
          If GuestLogin Then
             Next.Room=GuestRecord.GuestRoomResurrect
          Else
             Next.Room=Int(Val(Config3(24))+.5)
          Endif
          If Next.Room=0! Then
             Next.Room=1!
          Endif
          Call Teleport
          Action.Recurse=0
          Call Enter.Room
          Exit Sub
       Else
          Strng=Out3
          Call IO.O
          Strng="You are teleported elsewhere!"
          If Action.Recurse>0 Then
             Strng=Strng+" (recurse"+Str$(Action.Recurse)+")."
          Endif
          Call IO.O
          Next.Room=ActionRecord.Teleport(VarY)
          Call Teleport
          Call Enter.Room
          Exit Sub
       Endif
    Endif
 Endif
 ' check hits on player from action
 Temp2=ActionRecord.HitPoints
 If Temp2 Then
    Strng=Out3
    Call IO.O
    Strng=Out4
    Prefix2=Nul
    Out3="entering a room"
    Call Hit.Player(Temp2)
 Endif
 Exit Sub
Get.Config2:
 Option1=MaxRoomRecurse
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[TRAIN]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          If Ucase$(Var$)="[END]" Then
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Select Case Lcase$(Var2$)
             Case "max.room.recurse"
                If Int(Val(Var3$)+.5)>0 And Int(Val(Var3$)+.5)<=8 Then
                   Option1=Int(Val(Var3$)+.5)
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrorRsm58:
 Exit Sub
ErrorTrp58:
 Resume ErrorRsm58
End Sub

Sub Teleport
 On Local Error Goto ErrTrap49
 If Node>False Then
    Out2=UserRecord.CodeName
    Out2=Lcase$(Out2)
    Out2=Rtrim$(Out2)
    Out2=Out2+" was just teleported away!"
    Call Send.Mess(8,SFalse,Room,Out2)
 Endif
 Teleported=True
ErrResume49:
 Exit Sub
ErrTrap49:
 Resume ErrResume49
End Sub
