Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 [3] 4 5 6

Author Topic: A (kludgey) workaround for the disappearing caravan bug  (Read 34986 times)

redsector

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #30 on: November 06, 2016, 07:33:13 am »

I had the same issues with the whole multicmd thingy to find out the caravan members' IDs. Just didn't work. Luckily, I had seasonal autosaves thanks to playing with LNP and was able to get their IDs from those. The IDs turned out to be in the 30000s range, so I would have probably given up before finding them through trial and error anyway.

* Find out if you have a backup save from before the bugged caravan arrived. If you don't know exactly when that happened, just load a bunch of old saves and check the stocks screen for those unowned red items on the map's edge. Find the last save that doesn't have them.
* Make an additional backup of that save!
* Load the save and let the game run until the caravan comes. The caravan bugging out seems to be a rare random occurrence, so they'll probably arrive just fine this time. If not, quit the game, restore your backup save, try again.
* Make sure every member of the caravan - merchants, guards, horses, wagons - is on the map. I waited until they were all at the trade depot to be sure.
* Use the "u"nits screen to zoom in on the caravan members one by one and type "teleport -showunitid" to get their ID (their IDs should be subsequent and they should appear in the list in descending order, I think, so you can double-check if you ID range is correct by counting how many units there are).

* Load up your bugged game.
* OPTIONAL: build an execution chamber safe containment room with a raised drawbridge so you can atomsmash the entire caravan into oblivion. After years of being stuck on the map, a few of them will go berserk. Prepare memorial slabs.
* Put the cursor where you want the merchants and use "teleport -unit <ID>" to move them. I think multicmd would work fine now as long as all (or most, see below) unit IDs are valid, but I teleported them one by one anyway. You can use the arrow-up key in the DFhack console to restore the last command you typed and just replace the numbers.
NOTE: there may still be some invalid IDs since, apparently, the caravan won't consist of exactly the same number of members every time, which seems to be determined only upon actually entering the map. In my case, the last three IDs I had determined from the backup save weren't there in the bugged game. To make sure I didn't miss anyone, I checked about 20 additional ID numbers at both ends of the range, but they were all non-existent.
* Let the game run for a few frames, wait until everyone's teleported in and do whatever you want to get rid of them.

Good luck, I hope it works for you!


EDIT: PatrikLundell beat me to it and his method is probably faster and easier  8) I'll leave mine here anyway just in case you need it.
« Last Edit: November 06, 2016, 07:37:02 am by redsector »
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #31 on: November 06, 2016, 08:59:10 am »

I hacked together a script that tries to select only merchants and seems to use the same basic logic as lethosor does (which I didn't see until posting). Since I don't know how to call other scripts I brute forced it by including the teleport script into it...


One way to run Lua scripts is dfhack.run_script('teleport','-unit', id, ...). (dfhack.run_command would also work for any type of command.) run_script might be faster, since it doesn't have to check for built-in/plugin commands first.

Were there issues with trying to move dead units? It looks like dfhack.units.isMerchant() just checks the merchant flag, not the dead flag.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #32 on: November 06, 2016, 09:44:42 am »

Thanks for the info, lethosor. No, I didn't have any trouble (nor any dead merchants to test with). I added the dead flag check in case you'd have dead merchants around (some players apparently like to target them, in particular elven ones), and so didn't want to teleport those (although my understanding of the derail battle in the FoTF threat indicates their bodies wouldn't be teleported anyway).
It wasn't an attempt to "improve" on your logic, but rather a concurrent effort (I wouldn't have started if your answer had been available when I did). I also made the assumption a dead check wouldn't hurt, since the stuck merchants shouldn't be dead (yet).
Logged

Kathe

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #33 on: November 06, 2016, 10:05:58 am »

So far I've tried the brute force approach (up to id n 48.000). No merchants teleported, but every other unit on the map did (including 3 demons from hell).
Then I tried PatrikLundell's approach, and I just need a clarification on if I did it right. I replaced the text in the dfhack default "teleport" script in the scripts folder of dfhack with PatrikLundell's, then ran "teleport" through the dfhack command console. Correct? Anyway, nothing happened :/
Now, being a dfhack layman and only having a basic understanding of scripts, how do I implement lethosor's solution to see if that works? If it doesn't, I'll go back to the brute force methods with redsector's approach.
Thanks in advance for any help.
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #34 on: November 06, 2016, 01:09:47 pm »

Mine is a single command you can copy and paste into the console.

You probably should have made an existing script instead of replacing your teleport script, although I don't think it would make a difference.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #35 on: November 06, 2016, 04:45:46 pm »

Mine is a single command you can copy and paste into the console.

You probably should have made an existing script instead of replacing your teleport script, although I don't think it would make a difference.
It depends on the situation. If it's a one time problem, looking it up and pasting it is easier. If it happens multiple times it's easier to looking it up, save a script and call the same script every time.
Also, I didn't replace the teleport script: I copied the contents of it into mine, but yes, Kathe should have saved it into teleportmerchants.lua (or something, although it doesn't matter technically, as you say).

For Kathe: I'd start with lethosor's command, but you need to restore the teleport script first, as his command line uses it. Using his method is extremely easy, as he said after your question: just copy and paste.

When you used my script, you say "nothing happened": does it mean you typed the command in the DFHack console and you just got a prompt back, or did it output an error message? If you haven't selected a target location (with loo'k') it should print an error message saying you need to specify a target location.
If you just got a prompt back I suspect there aren't actually any stuck merchants (but I'd try lethosor's command anyway, just to make sure). If that's the case, you actually have one of the other situations where you don't get any merchants.

In case you don't have an easy backup of teleport.lua (you should have the archive where you installed from), this is what it looks like in the current 0.43.03 LNP:
Code: [Select]
-- teleports a unit to a location
-- author Putnam
-- edited by expwnent
--[====[

teleport
========
Teleports a unit to given coordinates.  Examples:

:teleport -showunitid:  prints unitid beneath cursor
:teleport -showpos:     prints coordinates beneath cursor
:teleport -unit 1234 -x 56 -y 115 -z 26:
                        teleports unit 1234 to 56,115,26

]====]

function teleport(unit,pos)
 local unitoccupancy = dfhack.maps.getTileBlock(unit.pos).occupancy[unit.pos.x%16][unit.pos.y%16]
 local newoccupancy = dfhack.maps.getTileBlock(pos).occupancy[pos.x%16][pos.y%16]
 if newoccupancy.unit then
  unit.flags1.on_ground=true
 end
 unit.pos.x = pos.x
 unit.pos.y = pos.y
 unit.pos.z = pos.z
 if not unit.flags1.on_ground then unitoccupancy.unit = false else unitoccupancy.unit_grounded = false end
end

utils = require('utils')

validArgs = validArgs or utils.invert({
 'unit',
 'x',
 'y',
 'z',
 'showunitid',
 'showpos'
})

if moduleMode then
 return
end

local args = utils.processArgs({...}, validArgs)

if args.showunitid or args.showpos then
 if args.showunitid then
  print(dfhack.gui.getSelectedUnit(true).id)
 else
  printall(df.global.cursor)
 end
else
 local unit = args.unit and df.unit.find(args.unit) or dfhack.gui.getSelectedUnit(true)
 local pos = not(not args.x or not args.y or not args.z) and {x=args.x,y=args.y,z=args.z} or {x=df.global.cursor.x,y=df.global.cursor.y,z=df.global.cursor.z}
 if not unit then qerror('A unit needs to be selected or specified. Use teleport -showunitid to get a unit\'s ID.') end
 if not pos.x or pos.x==-30000 then qerror('A position needs to be highlighted or specified. Use teleport -showpos to get a position\'s exact xyz values.') end
 teleport(unit,pos)
end
Logged

Kathe

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #36 on: November 07, 2016, 12:06:47 pm »

Yes, I should have been clearer:
I tried creating a new script named teleportmerchants with Patrik's text and then wrote teleportmerchants in the console to call it, and nothing happened (I had "k" on the desired teleport location), no error texts appeared;
failing that, I tried replacing the standard teleport's text with Patrik's (same result).
Then I restored the standard teleport script.

Now trying lethosor's solution...

Aaaaand everyone teleported but there are no merchants. That's the same result as the brute method approach I tried first (ids 0 to 48000). But the demons are different this time. Instead of 3, it's just 1 and of a different type.

The thing is, if merchants aren't actually stuck at two separate locations at the map's edge, then why are there red highlighted items that are usually traded by merchants in the stocks screen, pointing to those 2 locations (I'm guessing one is the human and the other the dwarven caravan; we've never had elves because they're too far)? Also, no merchants have arrived for the past 2 years, but I got a human diplomat at least this year (don't remember if also in the last one), but strangely all he had to say was that "Everything is the same in the world". Usually they vomit 2-10 pages of news of displaced groups and invasions.
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #37 on: November 07, 2016, 03:12:28 pm »

Mine should only teleport merchants. If it teleported everyone, something is wrong. Maybe you ran the wrong command or everyone in your save is treated as a merchant somehow. Try running this with a unit selected:

:lua ~dfhack.units.isMerchant(dfhack.gui.getSelectedUnit())

It should print "false".

I might be a little unclear on the problem here - is it that merchants are present on the map but invisible somehow? Anyone have a save with the problem?
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #38 on: November 07, 2016, 04:49:35 pm »

Both lethosor's method and mine should give the same result, i.e. teleporting of merchants only. If there are no merchants nothing should be printed and nothing should happen. If there are merchants my script should state that it's teleporting each merchant, as well as its ID.

A sanity question: are you using any mods that could confuse the matter?
Further: Are the red items in the stocks screen visible at the indicated positions? If that's the case they may have been dropped by merchants fleeing (they'll drop their goods and flee at the sight of half a goblin tooth). The fleeing merchant will then bring the rest of the caravan with him.

However, as lethosor said, a save would help.
Logged

Dunamisdeos

  • Bay Watcher
  • Duggin was the hero we needed.
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #39 on: November 07, 2016, 05:05:23 pm »

I am bad at all of this. The merchants-only script did not seem to teleport anything.

I ran Lethosor's script (   :lua for _, unit in pairs(df.global.world.units.active) do dfhack.run_script('teleport','-unit',unit.id)   ) end in DFhack by pasting it right up into the terminal. Is this wrong? It teleported all the citizens/livestock of my fort and a couple crundles and cave blobs.

No merchants came along for the ride and it ignored demons and FB's and such. I assume that I do have this bug because the items zoom to the edge of the map and are not visible there.

:lua ~dfhack.units.isMerchant(dfhack.gui.getSelectedUnit()) ---- this returned false.

Also, thanks for your attention and help.
« Last Edit: November 07, 2016, 05:13:34 pm by Dunamisdeos »
Logged
FACT I: Post note art is best art.
FACT II: Dunamisdeos is a forum-certified wordsmith.
FACT III: "All life begins with Post-it notes and ends with Post-it notes. This is the truth! This is my belief!...At least for now."
FACT IV: SPEECHO THE TRUSTWORM IS YOUR FRIEND or BEHOLD: THE FRUIT ENGINE 3.0

Kathe

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #40 on: November 07, 2016, 05:13:47 pm »

Welp, this looks worse and worse...Alright, first of all, I'm on LNP 43.03, with dfhack activated and no other mods. I usually run Soundsense and DT but haven't bothered booting them since the start of all this. Just to be clear :P

Second, I tried to check if normal dwarves are treated like merchants with lethosor's last lua, but: when I run it with a unit under the k cursor, nothing happens. It doesn't print anything in the console. If I run it when in a unit's details screen (Thoughts, health, relationships, etc), it says no unit is selected in the UI, plus a bunch of stuff I don't understand about luas, fields and functions. I suppose the first method is the intended one.

The problem is: none of the red-listed items listed in the stocks are visible on the map. They are not hidden, I've checked. And there are no merchants coming, either from humans or dwarves, plus the dwarven liaison. Human diplomat arrived just fine.
Oh, and to top it off, my legendary broker died shortly after the last merchants arrived, so I had to appoint a new one, with 0 appraisal skill, so now nothing has an indicated value anymore -_-

Anyway, I'm baffled as to why your scripts teleported EVERYONE, including demons from hell, except those supposedly invisible merchants bordering the map :P

Will try to upload a save tomorrow, at least to prove that I'm still sane.


P.S.
Ok, I found out why lethosor's method teleported everyone -_- , it's because I ran

:lua for _, unit in pairs(df.global.world.units.active) do dfhack.run_script('teleport','-unit',unit.id) end

and not

:lua for _, unit in pairs(df.global.world.units.active) do if dfhack.units.isMerchant(unit) then dfhack.run_script('teleport','-unit',unit.id) end end

which anyway gives no reslut (nothing is moved, nothing is printed on the console.

I guess my sanity really is slipping away at this point.
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #41 on: November 07, 2016, 05:17:30 pm »

I ran Lethosor's script (   :lua for _, unit in pairs(df.global.world.units.active) do dfhack.run_script('teleport','-unit',unit.id)   ) end in DFhack by pasting it right up into the terminal. Is this wrong? It teleported all the citizens/livestock of my fort and a couple crundles and cave blobs.

Yes, that's wrong. That's not the script I posted. Here it is again (note the "isMerchant" part in the middle that somehow got lost):

This may work for teleporting just merchants in theory, but it's completely untested:
Code: [Select]
:lua for _, unit in pairs(df.global.world.units.active) do if dfhack.units.isMerchant(unit) then dfhack.run_script('teleport','-unit',unit.id) end end
This definitely won't work in DFHack versions before 0.40.24-r2, though.

Edit: missed that reply somehow (oops). If that doesn't move any merchants, then there probably aren't any. You can try this, though, for diagnostic purposes, and see if it prints anything:

:lua for _, unit in pairs(df.global.world.units.active) do if dfhack.units.isMerchant(unit) then print('merchant',unit.id) end end
« Last Edit: November 07, 2016, 05:19:01 pm by lethosor »
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #42 on: November 07, 2016, 05:32:20 pm »

Well, the correct application of lethosor's command and my script both results in no merchants being present. It's good the methods agree, but unfortunate no merchants are found.
The save is probably needed to progress.
We're talking about computer programs where doing the same thing twice is expected to yield different results ("turn it off and then back on to see if it helps"), so sanity should not be in danger except as the result of a frustration induced stroke.

@lethosor: Perhaps the bugged merchants are in the "all" list, rather than the "active" one?
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #43 on: November 07, 2016, 05:41:16 pm »

Yeah, that's possible. You could try replacing "active" with "all" and see if that does anything. "active" should contain all of the units on the map, though (I think).
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

Dunamisdeos

  • Bay Watcher
  • Duggin was the hero we needed.
    • View Profile
Re: A (kludgey) workaround for the disappearing caravan bug
« Reply #44 on: November 07, 2016, 06:03:17 pm »

:lua for _, unit in pairs(df.global.world.units.active) do if dfhack.units.isMerchant(unit) then print('merchant',unit.id) end end

This printed the ID's for four merchants.

Here's something interesting. I was unable to teleport those units even after I had the unit ID's in front of me. It did not return an error. Nothing happened at all. It acted like I had teleported something, but did not.

I tried them individually using teleport -unit #. It did work for other, visible units in my fort.

Maybe the fault is it not with lethosor's script (maybe it's not even with me!).

« Last Edit: November 07, 2016, 06:09:53 pm by Dunamisdeos »
Logged
FACT I: Post note art is best art.
FACT II: Dunamisdeos is a forum-certified wordsmith.
FACT III: "All life begins with Post-it notes and ends with Post-it notes. This is the truth! This is my belief!...At least for now."
FACT IV: SPEECHO THE TRUSTWORM IS YOUR FRIEND or BEHOLD: THE FRUIT ENGINE 3.0
Pages: 1 2 [3] 4 5 6