Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: I'm trying to install a script and I'm unsure of what to do now:  (Read 557 times)

Urist McColeTheo

  • Bay Watcher
    • View Profile

I'm attempting to install a script for "instant transmission" so that I'm capable of teleporting my adventurer. I saved the link to the source code on the github page as a .lua file and it downloaded fine enough, and it will show up in the script list when you type "ls" but it will show "no help available" for it's description, and when I attempt to use it it shows me an error.

Spoiler (click to show/hide)

I'm not really sure what to make of it. Is there something I forgot to do?
Logged

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: I'm trying to install a script and I'm unsure of what to do now:
« Reply #1 on: July 18, 2016, 06:25:15 pm »

It's a syntax error, but no one can tell you more than that without a copy of the script. Post a copy here inside CODE tags.
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

Urist McColeTheo

  • Bay Watcher
    • View Profile
Re: I'm trying to install a script and I'm unsure of what to do now:
« Reply #2 on: July 18, 2016, 06:40:03 pm »

Code: [Select]
-- Allows instant transmission.

if df.global.gamemode~=1 then
    qerror("Adventure mode only (for now). Sorry!")
end

function getTileType(x,y,z)
    local block = dfhack.maps.getTileBlock(x,y,z)
    if block then
        return block.tiletype[x%16][y%16]
    else
        return 0
    end
end

function getPowerLevel(unit)
    local speed = 1000/dfhack.units.computeMovementSpeed(unit)
    local strength = unit.body.physical_attrs.STRENGTH.value/3550
    local endurance = unit.body.physical_attrs.ENDURANCE.value/1000
    local toughness = unit.body.physical_attrs.TOUGHNESS.value/2250
    local spatialsense = unit.status.current_soul.mental_attrs.SPATIAL_SENSE.value/1500
    local kinestheticsense = unit.status.current_soul.mental_attrs.KINESTHETIC_SENSE.value/1000
    local willpower = unit.status.current_soul.mental_attrs.WILLPOWER.value/1000
    local bodysize = (unit.body.blood_count/100)^2
    local powerlevel = bodysize*speed*((strength*endurance*toughness*spatialsense*kinestheticsense*willpower)^(1/6))
    return powerlevel
end

local function positionIsValid(x,y,z)
    local occupancy = dfhack.maps.getTileBlock(x,y,z).occupancy[x%16][y%16]
    local tiletype = getTileType(x,y,z)
    local attrs = df.tiletype.attrs[tiletype]
    if occupancy.building~=0 or occupancy.unit or not dfhack.maps.isValidTilePos(x,y,z) or attrs.shape == df.tiletype_shape.WALL  then return false else return true end
end

local dialog = require('gui.dialogs')

local function teleport(player,unitID)
    local unit = df.global.world.units.all[unitID]
    local playeroccupancy = dfhack.maps.getTileBlock(player.pos).occupancy[player.pos.x%16][player.pos.y%16]
    local teleportToPosX = unit.pos.x
    local teleportToPosY = unit.pos.y
    local timesTried = 0
    teleportToPosY = unit.pos.y - 1
    repeat
        if timesTried > 4 then qerror("Failed to teleport.") end
        local hasNotTried = true
        if teleportToPosY < unit.pos.y and hasNotTried then
            teleportToPosY = unit.pos.y
            teleportToPosX = unit.pos.x-1
            hasNotTried = false
        end
        if teleportToPosX < unit.pos.x and hasNotTried then
            teleportToPosX = unit.pos.x
            teleportToPosY = unit.pos.y+1
            hasNotTried = false
        end
        if teleportToPosY > unit.pos.y and hasNotTried then
            teleportToPosY = unit.pos.y
            teleportToPosX = unit.pos.x+1
            hasNotTried = false
        end
        if teleportToPosX > unit.pos.x and hasNotTried then
            teleportToPosX = unit.pos.x
            teleportToPosY = unit.pos.y-1
            hasNotTried = false
        end
        timesTried = timesTried + 1
    until positionIsValid(teleportToPosX,teleportToPosY,unit.pos.z)
    dfhack.gui.showAnnouncement("You put two fingers up to your head and concentrate...",11)
    player.pos.x = teleportToPosX
    player.pos.y = teleportToPosY
    player.pos.z = unit.pos.z
    if not player.flags1.on_ground then playeroccupancy.unit = false else playeroccupancy.unit_grounded = false end
end

function selectUnit() --taken straight from here, but edited so I can understand it better: https://gist.github.com/warmist/4061959/... again. Also edited for syndromeTrigger, but in a completely different way.
    local creatures=df.global.world.units.all
    local tbl={}
    local tunit=df.global.world.units.active[0]
    for k,creature in ipairs(creatures) do
        local plevel=math.ceil(getPowerLevel(creature))
        local racename=df.creature_raw.find(creature.race).caste[creature.caste].caste_name[0]
        table.insert(tbl,{racename.." "..plevel.." ".. (creature==tunit and "(You!)" or ""),nil,k})
    end
    local f=function(name,C)
        teleport(tunit,C[3])
    end
    dialog.showListPrompt("Left is species, right is power level.","Choose creature to teleport to:",COLOR_WHITE,tbl,f)
end

selectUnit()


I got it from the github page thst I was linked to after clicking the "instant transmission" link on the DFHack/scripts page.
Logged