Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » Finished MUD Scripts Goto page Previous  1, 2, 3
bothkill Posted: Tue Jul 14, 2009 7:36 am
Recycling the numbers of deleted rooms
kittyfish
Novice


Joined: 20 Sep 2011
Posts: 37

PostPosted: Tue Nov 07, 2017 3:30 pm   
 
Oh thanks, after so many years it's nice you replied, I guess email notification? :D Does the map importer thing in zuggsoft download section do a similar fix?

I found that the " SQL Error: PRIMARY KEY must be unique. " bug happens any time that you click and drag to select multiple rooms, then change their colour, then move to make a new room with map creation mode turned on -- selecting rooms individually by clicking and holding shift on each square then changing their colour doesn't cause the error when making a new room afterwards
- But it's obviously not ideal since if you are making a large area you have to click every single square one by one
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 3925
Location: Pensacola, FL, USA

PostPosted: Tue Nov 07, 2017 9:39 pm   
 
You can also get around that error my doing your coloring last thing before closing CMUD down.
Once CMUD restarts it should not give that error on making another room.

P.S. A room is sometimes created when you get that error, usually at coordinates 0,0 of the first zone you created. I used to end up with stacks of blank rooms right there.
_________________
Discord: Shalimar#3679
Reply with quote
kittyfish
Novice


Joined: 20 Sep 2011
Posts: 37

PostPosted: Thu Nov 09, 2017 3:17 pm   
 
Yeah on one of the threads I linked on the last page someone suggested on the map going to View > Spreadsheet View to find the broken ones, it works really well, the broken ones are always at 0,0, you can click the Refnum column to sort by and find them that way because they also have 0 for their room ids too (and then after selecting the row carefully to not delete everything click the — icon to delete the row)
Reply with quote
viyatsia
Beginner


Joined: 31 May 2019
Posts: 13

PostPosted: Mon Jun 03, 2019 1:17 am   Re: Recycling the numbers of deleted rooms
 
bothkill wrote:
You can read the topic relating to this script on this forum thread.

I have made the script for both CMUD 2.37 (.mdb files - MSAccess database) and CMUD 3.xx Youjizz Pornhub Tubegalore (.dbm files - SQLite database).
Since CMUD 3.xx is still BETA, for the time being I will not post the script for CMUD 3.xx since the structure of .dbm files might sustain changes.

Here's the VBScript code for CMUD 2.37 (for .mdb files - MSAccess database):
I have used it numerous times and didn't notice any undesirable side effects.
Anyway, BACKUP your map file before using this script!!!

Code:
'==========================================================================
'
' VBScript Source File
'
' NAME     : Recycle_room_&_exit_numbers.vbs
' AUTHOR   : Marian Cascaval (aka Bothkill)
' E-MAIL   : MarianCascaval@yahoo.com
' DATE     : <February 5, 2009>
' COMMENT  : In the process of creating maps with CMUD 2.xx, every room you create
'            is assigned a number (you can check the number of every room by
'            hovering the mouse over the room).
'
'            The problem appears when you delete a room (or more rooms).
'            The numbers of deleted rooms are not used for creating new rooms,
'            but are skipped.
'
'            To understand the problem, let's see an example:
'            1. create a new map
'            2. create a room (this is #1)
'            3. delete room #1
'            4. create a new room (this #2); although there is only one room
'               on the map, this room is #2.
'       
'           As you can see, numbers of deleted rooms are not recycled.
'           Not such a great issue, but is annoying when you delete
'           a great number of rooms and later when creating new ones you reach
'           unrealistic room numbers.
'       
'           You can check your Mud .mdb map file to see it for yourself.
'           The "your-Mud".mdb file is a Microsoft Accesss database file
'           CMUD uses for storing your Mud map.
'       
'           Open the table "ObjectTbl" and compare the last record in the
'           "ObjId" column (this is where the room numbers are) with the
'           total number of records in that table.
'           If you have deleted a lot of rooms while creating that map
'           you will notice a considerable difference between the two values.
'       
'           The problem goes worse as regards Exit numbers.
'           You cannot see Exit numbers on the map, but you can see them
'           in the .mdb map file:
'           "ExitId" column in "ExitTbl" table.
'       
'           Here, the difference between the last record and the total number
'           of records is even greater than in the case of room numbers.
'       
'           This script (VBScript) recycles the numbers of deleted rooms and exits.
'       
'           This script is useful if you have ever deleted rooms in your map.
'           If you don't know if you have ever deleted rooms in your room, you can
'           still run this script, since it will inform you if recycling was done.
'       
'       
'           !!! IMPORTANT !!!
'           =================
'           Although I have tested this script in all possible scenarios I could
'           think of, I urge you to BACKUP your .mdb file BEFORE running the script.
'       
'           IF you have scripts that depend on room numbers (i.e. #TELEPORT #23)
'           then almost certainly your script will not work as before (i.e. you will
'           be TELEPORTed to another room than previously intended).
'           A recommendation on this:
'           Always use within scripts SHORT NAMES of rooms and not ROOM NUMBERS
'           (i.e. #TELEPORT "room-name" "zone-name").
'           The short-names of rooms can be set by setting the map in create mode,
'           right-click on room, click on properties, click on "Other" tab
'           and setting the name in the "Short Name of room" field.
'       
'           After running the script, TEST your .mdb map file to see IF everything is OK.
'       
'       
'           TECHNICAL INFO:
'           ===============
'           There are the following important tables and columns in your .mdb file
'           that deal with these numbers:
'       
'           Table "ObjectTbl"
'              Columns
'       
'           ...this is not complete...
'       
'       
'       
'==========================================================================

   ' =======================================================================
   '   Script for selecting a file by using a Windows Common Dialog box
   '
   '              Thanks go to Jerry Lees for this script
   ' The script can be found at    http://itknowledgeexchange.techtarget.com
   ' =======================================================================

Option Explicit

Dim objFSO, initFSO

   ' Create an instance of the File Browser
   
Set objFSO = CreateObject("UserAccounts.CommonDialog")

   ' Setup the File Browser specifics
   
objFSO.Filter = "Access Databeses (*.mdb)|*.mdb|"
objFSO.FilterIndex = 1
objFSO.InitialDir = "C:\"

If MsgBox("                This script recycles"& Chr(13) &"" & _
         "  numbers of deleted Rooms and Exits"& Chr(13) &"" & _
         "in map files (.mdb) made by CMUD 2.37.",vbOKCancel,"Message") _
         = 2 Then
   MsgBox "Operation canceled.",,"Message"
   Wscript.Quit
End If

MsgBox "Select a database (*.mdb) file.",,"Message"

   ' Show the file browser and return the selection (or lack of) to initFSO
   
initFSO = objFSO.ShowOpen

If initFSO = False Then
    MsgBox "Operation canceled because no file was selected.",,"Message"
    Wscript.Quit
Else
   MsgBox "           Operation takes time"& Chr(13) &"depending on the size of database."& Chr(13) &""& Chr(13) &"  Unless there are error messages,"& Chr(13) &"     there will be 6 info messages."& Chr(13) &"            Wait for all of them."& Chr(13) &""& Chr(13) &"                    Click OK"& Chr(13) &"            to begin operation.",,"Message"
End If

   ' =========================================
   ' End of Script for selecting a file
   ' =========================================

   ' Declare constants and variables for database access

Dim objConn
Dim objRS

Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "Microsoft.Jet.OLEDB.4.0"
objConn.Open objFSO.FileName

Set objRS = CreateObject("ADODB.Recordset")  ' The Recordset
Set objRS.ActiveConnection = objConn

Const adLockOptimistic = 3
Const adOpenKeyset = 1

   ' Declare non database-access-related variables

Dim number_to_recycle,number_to_replace
Dim total_records,max_number,last_number
Dim recycle_flag
Dim max_ExitId,max_ExitIdTo
Dim a_counter
recycle_flag = False

   ''''''''''''''''''''''''''
   ''----------------------''
   '' RECYCLE ROOM NUMBERS ''
   ''----------------------''
   ''''''''''''''''''''''''''

   ' Determine max number in ObjId column

objRS.Open "SELECT MAX(ObjId) AS Largest FROM ObjectTbl"
objRS.MoveFirst   
max_number = objRS("Largest")
objRS.Close
   
   ' Open Recordset

objRS.Open "SELECT ObjId, RefNum FROM ObjectTbl", ,adOpenKeyset,adLockOptimistic

total_records = objRS.RecordCount

   ' Determine if and from what record, room numbers need recycling

For number_to_recycle = 1 To total_records
   objRS.Move number_to_recycle - 1,1 
   If objRS("ObjId") > number_to_recycle Then
      While number_to_recycle <= total_records       
         Call Recycle_room_numbers
         number_to_recycle = number_to_recycle + 1
      Wend
      recycle_flag = True
      Exit For
   End If
Next

   ' Set the flag for recycle meesage

If recycle_flag Then
   MsgBox "Room numbers recycled.",,"Message no.1"
   recycle_flag = False ' Set the flag as False for the next recycling message
Else
   MsgBox "Room numbers need not recycling.",,"Message no.1"
End If

   ' Recycle the next-to-create room number in ObjID column from VersTbl table

objRS.MoveLast
last_number = objRS("ObjId")
objRS.Close
objRS.Open ("SELECT ObjID FROM VersTbl"), ,adOpenKeyset,adLockOptimistic
objRS.MoveFirst
IF last_number + 1 <> objRS("ObjID") Then
   objConn.Execute ("UPDATE VersTbl SET ObjID="& last_number + 1 &"")
   MsgBox "Number of next-to-create Room recycled.",,"Message no.2"
   recycle_flag = False ' Set the flag as False for the next recycling message
Else
   MsgBox "Number of next-to-create Room need not recycling.",,"Message no.2"
End If
objRS.Close

   ''''''''''''''''''''''''''
   ''----------------------''
   '' RECYCLE EXIT NUMBERS ''
   ''----------------------''
   ''''''''''''''''''''''''''

   ' Recycle exit numbers

objRS.Open ("SELECT ExitId, ExitIdTo FROM ExitTbl"), ,adOpenKeyset,adLockOptimistic

total_records = objRS.RecordCount

For number_to_recycle = 1 To total_records
   objRS.Move number_to_recycle - 1,1
   If objRS("ExitId") > number_to_recycle Then
      While number_to_recycle <= total_records       
         Call Recycle_exit_numbers
         number_to_recycle = number_to_recycle + 1
      Wend
      recycle_flag = True
      Exit For
   End If
Next

If recycle_flag Then
   MsgBox "Exit numbers recycled.",,"Message no.3"
Else
   MsgBox "Exit numbers need not recycling.",,"Message no.3"
End If
objRS.Close

   ' Recycle the next-to-create exit number in ExitID column from VersTbl table

objRS.Open ("SELECT ExitId FROM ExitTbl"), ,adOpenKeyset,adLockOptimistic
objRS.MoveLast
last_number = objRS("ExitId")
objRS.Close
objRS.Open ("SELECT ExitID FROM VersTbl"), ,adOpenKeyset,adLockOptimistic
objRS.MoveFirst
IF last_number + 1 <> objRS("ExitID") Then
   objConn.Execute ("UPDATE VersTbl SET ExitID="& last_number + 1 &"")
   MsgBox "Number of next-to-create Exit recycled.",,"Message no.4"
Else
   MsgBox "Number of next-to-create Exit need not recycling.",,"Message no.4"
End If
objRS.Close

   ' If there are exit numbers in ExitIdTo column in ExitTbl table
   ' which are greater than the max number in ExitId column in ExitTbl table
   ' they become -1

   ' Determine max number in ExitId column

objRS.Open "SELECT MAX(ExitId) AS Largest_ExitId FROM ExitTbl"
objRS.MoveFirst
max_ExitId = objRS("Largest_ExitId")
objRS.Close

   ' Determine max number in ExitIdTo column

objRS.Open "SELECT MAX(ExitIdTo) AS Largest_ExitIdTo FROM ExitTbl"
objRS.MoveFirst
max_ExitIdTo = objRS("Largest_ExitIdTo")
objRS.Close

   ' Exit numbers in ExitIdTo column in ExitTbl table
   ' greater than max number in ExitId column in ExitTbl table
   ' become -1

If max_ExitIdTo > max_ExitId Then
   For a_counter = max_ExitId + 1 To max_ExitIdTo
      objConn.Execute ("UPDATE ExitTbl SET ExitIdTo=-1 WHERE ExitIdTo="& a_counter &"")
   Next
   MsgBox "Exit connections have been cleaned.",,"Message no.5"
Else
   MsgBox "Exit connections need not cleaning.",,"Message no.5"
End If

   ' Close connection to database

objConn.Close
MsgBox "Operation completed.",,"Message no.6"

   ' END OF SCRIPT

   ' -----------
   ' Subroutines
   ' -----------

   ' Subroutine Recycle_room_numbers

Sub Recycle_room_numbers

   objRS.Move number_to_recycle - 1,1

   ' Recycle numbers in ObjId and RefNum columns from ObjectTbl table

   number_to_replace = objRS("ObjId")
   
   objRS("ObjId") = number_to_recycle
   objRS("RefNum") = number_to_recycle
   objRS.Update

   ' Recycle numbers in FromID and ToID columns from ExitTbl table
         
   objConn.Execute ("UPDATE ExitTbl SET FromID="& number_to_recycle &" WHERE FromID="& number_to_replace &"")
   objConn.Execute ("UPDATE ExitTbl SET ToID="& number_to_recycle &" WHERE ToID="& number_to_replace &"")
     
End Sub

   ' Subroutine Recycle_exit_numbers

Sub Recycle_exit_numbers

   objRS.Move number_to_recycle - 1,1
   
   ' If exit number_to_recycle is found in ExitIdTo column then it becomes -1
   
   objConn.Execute ("UPDATE ExitTbl SET ExitIdTo=-1 WHERE ExitIdTo="& number_to_recycle &"")
   
   ' Recycle exit numbers in ExitId column
   
   number_to_replace = objRS("ExitId")
   objConn.Execute ("UPDATE ExitTbl SET ExitId="& number_to_recycle &" WHERE ExitId="& number_to_replace &"")
   objConn.Execute ("UPDATE ExitTbl SET ExitIdTo="& number_to_recycle &" WHERE ExitIdTo="& number_to_replace &"")

End Sub

I have used it numerous times and didn't notice any undesirable side effects.
Reply with quote
ToyMage
Apprentice


Joined: 01 Sep 2005
Posts: 101

PostPosted: Wed Jun 05, 2019 5:39 pm   
 
i'm a noob.. how do i use the script? on my map file? can someone provide a step by step guide? is there any software I need to download?

my maps is getting huge..... with lots of deleted rooms...
Reply with quote
ToyMage
Apprentice


Joined: 01 Sep 2005
Posts: 101

PostPosted: Thu Jun 06, 2019 7:03 am   
 
Hi,

I manged to run the script.. and the first two steps seems to run well.. and I get

"Room numbers need not recycling."

"Number of next-to-create Room need not recycling."

but on next click, i get the below error, anyone knows how to fix it?

Line: 341
Char: 4
Error: UNIQUE contstraint failed: ExitTbl.ExitID(19)
Code: 80004005
Source : Microsoft OLE DB Provider for ODBC Driver
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » Finished MUD Scripts All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net