Modding Help Is it possible to get multiple drops from one ore? Continued in thread

Discussion in 'Starbound Modding' started by KindlesRune, Nov 29, 2022.

  1. KindlesRune

    KindlesRune Space Hobo


    Preface:


    I'll preface this by saying that I'm not a very good scripter. I know little about actual coding besides a few basic concepts and formatting.

    I've been trying to make a RuneScape mod recently and I've hit some snags. Mostly scripting issues. I won't bog down this post with the many issues I'm having but I'll cover enough information to explain the one issue I'm focused on now.


    Searching the web:


    I did some digging and can't find any that add multiple ore drops from a single ore (or even the ability to spawn a second ore on top of another one which I'm pretty sure is impossible to do (without heavy modification that is) looking at the .matmods in the /tiles/mods folder and browsing the files there).


    Other Mods:

    I've looked to other mods and took them apart to try to recreate something that works as of now. I found one particular mod, the RPG Growth mod, was very close to what I wanted to accomplish by adding a leveling system. I would plan on creating something based on the mod. This is because of the experience orb and level currency system it uses. However, I still need to ask permission before I finalize anything with RPG Growth's assets. Before I do that, I want to make sure that it's even possible to take a second item from an ore.


    The problem:

    I am trying to find a way to drop another item when an ore is mined (or some other method for leveling). Ideally, I would give it directly to the player. The only way I know how to do this as of now is by adding scripts to the miningtool the player uses. There's only one script I can see in there and that's beamaxe.lua, and with that I have attempted to create my hideously coded modification of the lua file.

    Here is the lua file contents:

    require "/scripts/util.lua"

    function init()
    self.radius = config.getParameter("blockRadius") / 2
    self.altRadius = config.getParameter("altBlockRadius") / 2

    self.notifyTime = config.getParameter("notifyEntityTime")
    self.notifyTimer = 0
    self.notifyDamage = config.getParameter("tileDamage") / config.getParameter("fireTime") * self.notifyTime
    self.notifyQueryParams = {
    includedTypes = {"vehicle"},
    boundMode = "position"
    }
    self.cooldownTime = config.getParameter("cooldownTime", .1)
    end


    function update(dt, fireMode, shifting)
    if fireMode == "primary" then
    self.notifyTimer = math.max(0, self.notifyTimer - dt)
    if self.notifyTimer == 0 then
    self.notifyTimer = self.notifyTime
    notifyEntities(shifting)
    end
    else
    self.notifyTimer = 0
    end
    end



    function notifyEntities(shifting)
    local entities = world.entityQuery(fireableItem.ownerAimPosition(), shifting and self.altRadius or self.radius, self.notifyQueryParams)
    local drops = world.itemDropQuery(fireableItem.ownerAimPosition(), shifting and self.altRadius or self.radius, self.notifyQueryParams)
    for _, entityId in ipairs(entities) do
    world.sendEntityMessage(entityId, "positionTileDamaged", self.notifyDamage)
    for _, dropId in ipairs(drops) do
    if dropId.name() == "XPtinore" then
    world.spawnitem("tinore", fireableItem.ownerAimPosition(), 1)
    world.spawnitem("miningexperienceorb", fireableItem.ownerAimPosition(), 3)
    elseif dropId.name() == "XPcopperore" then
    world.spawnitem("copperore", fireableItem.ownerAimPosition(), 1)
    world.spawnitem("miningexperienceorb", fireableItem.ownerAimPosition(), 3)
    end
    end
    end
    end

    function uninit()
    end





    I have gotten to a point where my code no longer gives me an error in the log files relating to itself, but it doesn't work as intended either. As of writing this I'm searching the docs, web, and wiki for more information and rereading the docs on items and entities as I have a hunch that's where the problem with my code is. If anyone could provide some insight or suggest something that would be much appreciated :)

    Edit: First off, world.spawnitem may have been case sensitive in which case world.spawnItem was the correct usage. With this mishap fixed I did some troubleshooting on each line of code and it looks like the culprit is this line of code here:

    for _, entityId in pairs(entities) do
    --world.spawnItem("copperore", fireableItem.ownerAimPosition(), 1)
    world.sendEntityMessage(entityId, "", self.notifyDamage)

    world.spawnItem never runs in this for loop, I'm not sure if the same can be said for world.sendEntityMessage but world.spawnItem works outside the for loop just fine. It may be a problem of the way I'm calling it I dunno. Further testing is required but for now I'm going to take a break from this...
     
    Last edited: Dec 1, 2022
  2. KindlesRune

    KindlesRune Space Hobo

    I'm not even sure whats different between the Lua tables: Entity, Item, and Object... but I assume that item drops are considered Entities until picked up, and Objects refer to anything that can be placed between the foreground and background?

    Edit: Looks like that is not the case.
     
    Last edited: Nov 29, 2022

Share This Page