Advertisement
Guest User

assumecontrol.lua

a guest
Mar 5th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. local utils = require 'gui'
  2.  
  3. function assumeControl(new,old)
  4. local actold
  5. for i,j in ipairs(df.global.world.units.all) do
  6. if j.id==df.global.world.units.active[0].id then
  7. actold=j.id
  8. break
  9. end
  10. end
  11. local old
  12. old=df.unit.find(actold)
  13. local new
  14. new=dfhack.gui.getSelectedUnit(true)
  15. if new==nil then
  16. qerror("Unable to Assume Control!")
  17. end
  18. local active=df.global.world.units.active
  19. local actnew
  20. for k,v in pairs(active) do
  21. if v==new then
  22. actnew=k
  23. break
  24. end
  25. end
  26. if actnew==nil then
  27. qerror("Attempt to Assume Control has failed?")
  28. end
  29. active[actnew]=active[0]
  30. active[0]=new
  31. local target = dfhack.units.getNemesis()
  32. if target then
  33. local nwnem=dfhack.units.getNemesis(new)
  34. local olnem=dfhack.units.getNemesis(old)
  35. if olnem then
  36. olnem.flags.ACTIVE_ADVENTURER=false
  37. olnem.flags.RETIRED_ADVENTURER=true
  38. olnem.unit.status.current_soul.personality.flags[1]=false
  39. end
  40. if nwem then
  41. nwem.flags.ACTIVE_ADVENTURER=true
  42. nwem.flags.RETIRED_ADVENTURER=false
  43. nwnem.flags.ADVENTURER=true
  44. nwnem.unit.status.current_soul.personality.flags[1]=true
  45. for k,v in pairs(df.global.world.nemesis.all) do
  46. if v.id==nwnem.id then
  47. df.global.ui_advmode.player_id=k
  48. end
  49. end
  50. else
  51. error("Assuming Direct Control! Current target may not last long!")
  52. end
  53. end
  54. end
  55. assumeControl(new,old)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement