Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 38 39 [40] 41 42

Author Topic: [DFHack] Roses' Script Collection Updated 5/4/15  (Read 118991 times)

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #585 on: April 07, 2015, 10:39:17 pm »

So I am going to have a little bit of time on my hands this weekend while I am flying and figured it would be a good time to update all of my stuff to use the new "scripts as libraries" thing. And am wondering just how I should go about that, I found this old post
Quote from: Roses
so uh

you gonna update this to use the scripts-as-libraries feature in 0.40.24-r2
I should, I'm not sure all what I would have to do to update them though.

Move your hack/lua files to raw/scripts/library and use dfhack.script_environment("library/blah").function(args) for basic usage. See LUA API.rst for details.
[/quote]

Is that still all there is to it?
Logged

Boltgun

  • Bay Watcher
  • [UTTERANCES]
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #586 on: April 08, 2015, 02:04:43 am »

Pretty much, yes.

Your script will run when calling script_environment so if it does something immediatly, like when called from the console, you'll have to handle this.

I think I saw a method checking for the conditions a script is called, must be in the modtools somewhere.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #587 on: April 08, 2015, 02:25:51 am »

I think pretty much all my scripts only have things like checking for required arguments outside of the function, everything else is inside. Actually, the X = require 'Y' is out of the function, will that be a problem? Also, if I have two functions in the same .lua file, and one references the other, do I need to change it to a script_environment call, or is it only for when you have to call different .lua files?
Logged

Boltgun

  • Bay Watcher
  • [UTTERANCES]
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #588 on: April 08, 2015, 04:31:50 am »

No problem with that, it will assign the library to your variable and stays like this while you call functions.

There is no issues calling one function from another within the script. Environment is used to call functions from other lua files.

Edit: To check if a script is called as a module or not.
Code: [Select]

if not moduleMode then
    -- Stuff to do when called from the console
end
« Last Edit: April 08, 2015, 04:42:33 am by Boltgun »
Logged

SMASH!

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #589 on: April 08, 2015, 10:33:45 am »

Why it isn't working? Trying to trigger goblin siege, 40.24 dfhack-r2.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #590 on: April 08, 2015, 03:17:02 pm »

You can't force a siege in the current version of DF.

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #591 on: April 13, 2015, 07:43:12 pm »

So just to make absolutely sure I am doing this right, I am going to be replacing this
Code: [Select]
isSelected = require 'wrapper.isSelected'
returnedValue = isSelected([args])
With
Code: [Select]
returnedValue = dfhack.script_environment('wrapper/isSelected').isSelected([args])Where I have moved the corresponding lua file from "DF/hack/lua/wrapper" to "DF/raw/scripts/wrapper"?

Does script_environment() check the same places entering a script on command line checks? (i.e. save/raw/scripts, DF/raw/script, and DF/hack/scripts)
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #592 on: April 13, 2015, 07:47:25 pm »

Or:

Code: [Select]
isSelected = dfhack.script_environment('wrapper/isSelected').isSelected

returnedValue=isSelected([args])

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #593 on: April 13, 2015, 08:04:22 pm »

Or:

Code: [Select]
isSelected = dfhack.script_environment('wrapper/isSelected').isSelected

returnedValue=isSelected([args])

Right. So with this system would it be better for me to condense my wrapper scripts into a single file? For instance, right now I have
Code: [Select]
-- Physical Attributes Check
  if physical ~= 'NONE' and selected[i] then
   selected[i],announcement[i] = dfhack.script_environment('wrapper/checkAttributes').checkAttributes(unitCheck,physical,false,unitSelf)
  end

-- Mental Attributes Check
  if mental ~= 'NONE' and selected[i] then
   selected[i],announcement[i] = dfhack.script_environment('wrapper/checkAttributes').checkAttributes(unitCheck,mental,true,unitSelf)
  end

-- Skill Level Check
  if skill ~= 'NONE' and selected[i] then
   selected[i],announcement[i] = dfhack.script_environment('wrapper/checkSkills').checkSkills(unitCheck,skill,unitSelf)
  end

But I could change it to
Code: [Select]
wrapper = dfhack.script_environment('wrapper')
-- Physical Attributes Check
  if physical ~= 'NONE' and selected[i] then
   selected[i],announcement[i] = wrapper.checkAttributes(unitCheck,physical,false,unitSelf)
  end

-- Mental Attributes Check
  if mental ~= 'NONE' and selected[i] then
   selected[i],announcement[i] = wrapper.checkAttributes(unitCheck,mental,true,unitSelf)
  end

-- Skill Level Check
  if skill ~= 'NONE' and selected[i] then
   selected[i],announcement[i] = wrapper.checkSkills(unitCheck,skill,unitSelf)
  end
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #594 on: April 13, 2015, 08:08:34 pm »

Yeah, probably.

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #595 on: April 13, 2015, 11:08:18 pm »

So I have changed all the foo = require 'bar' to the corresponding dfhack.script_environment('bar'). And left all of the dfhack.run_script as is. I have started to test the scripts to make sure they all work, but is there anything else I should do to make them more standard? (I also changed all the ! requirements to \)
Logged

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #596 on: April 14, 2015, 09:04:59 am »

Either of those should be fine.
Logged

Max™

  • Bay Watcher
  • [CULL:SQUARE]
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #597 on: April 14, 2015, 06:47:07 pm »

oh it breaks on unit selection I found the workaround to this by altering the unit target to be just for the Adventurer but when I attempted to do a at pointer run speed of projectile I didn't write a function that aim the player so I kept flying in the bottom right per jump.
Well, Rumrusher started the translation and I fleshed out what they were doing while learning more about the various structures with gm-editor and surprisingly enough I was able to make it work well, if dangerously.

Code: [Select]
function jump(unitSource,unitTarget)

local curpos
if df.global.ui_advmode.menu==1 then
curpos=df.global.cursor
else
print ("No cursor located!  You would have slammed into the ground and exploded.")
return
end


 local count=0
 local l = df.global.world.proj_list
 local lastlist=l
 l=l.next
 while l do
  count=count+1
  if l.next==nil then
   lastlist=l
  end
  l = l.next
 end

resultx = curpos.x - unitSource.pos.x
resulty = curpos.y - unitSource.pos.y
resultz = curpos.z - unitSource.pos.z


 newlist = df.proj_list_link:new()
 lastlist.next=newlist
 newlist.prev=lastlist
 proj = df.proj_unitst:new()
 newlist.item=proj
 proj.link=newlist
 proj.id=df.global.proj_next_id
 df.global.proj_next_id=df.global.proj_next_id+1
 proj.unit=unitSource
 proj.origin_pos.x=unitSource.pos.x
 proj.origin_pos.y=unitSource.pos.y
 proj.origin_pos.z=unitSource.pos.z
 proj.target_pos.x=curpos.x
 proj.target_pos.y=curpos.y
 proj.target_pos.z=curpos.z
 proj.prev_pos.x=unitSource.pos.x
 proj.prev_pos.y=unitSource.pos.y
 proj.prev_pos.z=unitSource.pos.z
 proj.cur_pos.x=unitSource.pos.x
 proj.cur_pos.y=unitSource.pos.y
 proj.cur_pos.z=unitSource.pos.z
 proj.flags.no_impact_destroy=true
 proj.flags.piercing=true
 proj.flags.high_flying=true
 proj.flags.parabolic=true
 proj.flags.no_collide=true
 proj.flags.unk9=true
 proj.speed_x=resultx*10000
 proj.speed_y=resulty*10000
 proj.speed_z=resultz*10000
 unitoccupancy = dfhack.maps.ensureTileBlock(unitSource.pos).occupancy[unitSource.pos.x%16][unitSource.pos.y%16]
 if not unitSource.flags1.on_ground then
  unitoccupancy.unit = false
 else
  unitoccupancy.unit_grounded = false
 end
 unitSource.flags1.projectile=true
 unitSource.flags1.on_ground=false
 end

unitTarget = curpos
unitSource = df.global.world.units.active[0]

jump(unitSource,unitTarget)
Had to add a check and error so it wouldn't try to use x/y/z = -30000 for targeting and speed because it kills your ass so dead that one time my icon didn't change after I slammed completely through a wall into a building.

Rumrusher worked out that part of the problem in adventurer mode was not having enough speed for the projectile to move you enough. I did some science, by which I mean I tackled some unsuspecting creatures and checked the proj_list with gm-editor and noticed that the speeds were all in the tens of thousands (and of course simply designated as being away from where you tackled them, so negative values) and then managed to alter the trajectory of a kea I had tackled in mid-air to make it start heading upwards.

To get the same effect I jacked up the *200 multiplier Rum was testing and it looks like 10k will let you make shorter jumps without failing to travel far enough, but it is the difference of the unit position and cursor position times 10k, so make sure you have a free hand and a tree to grab if you're trying to jump across the screen, else you will be severely wounded or killed!

Oh, I technically didn't have to reverse the unitsource/target and they should be switchable back to the same arrangement as propel used but I kept typing the wrong one because I was trying to move from the unit pos to the cursor pos so I just find/replaced em.

Dear god it is fun, incidentally.
« Last Edit: April 14, 2015, 06:50:26 pm by Max™ »
Logged

Max™

  • Bay Watcher
  • [CULL:SQUARE]
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #598 on: April 19, 2015, 02:52:00 pm »

Well, he did it, he blew them all up, Rumrusher worked out how to grab someone else and have the script target them and then default to you if not wrestling... so adventure mode now has dorf tossing, accordingly I suggested the name be launch.lua to fit better with propel.lua and avoid confusion with the built-in jump.
Code: (launch.lua) [Select]
function launch(unitSource,unitTarget)

local curpos
if df.global.ui_advmode.menu==1 then
curpos=df.global.cursor
else
print ("No cursor located!  You would have slammed into the ground and exploded.")
return
end


 local count=0
 local l = df.global.world.proj_list
 local lastlist=l
 l=l.next
 while l do
  count=count+1
  if l.next==nil then
   lastlist=l
  end
  l = l.next
 end

resultx = curpos.x - unitSource.pos.x
resulty = curpos.y - unitSource.pos.y
resultz = curpos.z - unitSource.pos.z


 newlist = df.proj_list_link:new()
 lastlist.next=newlist
 newlist.prev=lastlist
 proj = df.proj_unitst:new()
 newlist.item=proj
 proj.link=newlist
 proj.id=df.global.proj_next_id
 df.global.proj_next_id=df.global.proj_next_id+1
 proj.unit=unitSource
 proj.origin_pos.x=unitSource.pos.x
 proj.origin_pos.y=unitSource.pos.y
 proj.origin_pos.z=unitSource.pos.z
 proj.target_pos.x=curpos.x
 proj.target_pos.y=curpos.y
 proj.target_pos.z=curpos.z
 proj.prev_pos.x=unitSource.pos.x
 proj.prev_pos.y=unitSource.pos.y
 proj.prev_pos.z=unitSource.pos.z
 proj.cur_pos.x=unitSource.pos.x
 proj.cur_pos.y=unitSource.pos.y
 proj.cur_pos.z=unitSource.pos.z
 proj.flags.no_impact_destroy=true
 proj.flags.piercing=true
 proj.flags.high_flying=true
 proj.flags.parabolic=true
 proj.flags.no_collide=true
 proj.flags.unk9=true
 proj.speed_x=resultx*10000
 proj.speed_y=resulty*10000
 proj.speed_z=resultz*10000
 unitoccupancy = dfhack.maps.ensureTileBlock(unitSource.pos).occupancy[unitSource.pos.x%16][unitSource.pos.y%16]
 if not unitSource.flags1.on_ground then
  unitoccupancy.unit = false
 else
  unitoccupancy.unit_grounded = false
 end
 unitSource.flags1.projectile=true
 unitSource.flags1.on_ground=false
 end

unitTarget = curpos
if df.global.world.units.active[0].job.hunt_target==nil then
unitSource = df.global.world.units.active[0]
else
unitSource = df.global.world.units.active[0].job.hunt_target
end
 
launch(unitSource,unitTarget)
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 2/21/15
« Reply #599 on: May 01, 2015, 04:50:08 pm »

That looks really interesting.

In terms of progress update, I have changed all of my scripts to use the dfhack.script_environment system instead of require and tested them. Everything seems to be working well. I will put up an update this weekend.
Logged
Pages: 1 ... 38 39 [40] 41 42