Modding Help (SOLVED) Custom "debuff" that grants negative hunger regen (not working)

Discussion in 'Starbound Modding' started by SkyeTheTerribleBeastie, Apr 22, 2018.

  1. SkyeTheTerribleBeastie

    SkyeTheTerribleBeastie Pangalactic Porcupine

    Hi, ran into issues with making a debuff, that, yeah.
    In theory, should give the player the debuff Munchies (which it does), and detract hunger if hunger is more than empty (not working, will tweak once I get it working)

    Code:
    [19:58:04.230] [Info] Root: Preparing Root...
    [19:58:04.231] [Info] Root: Done preparing Root.
    [19:58:04.231] [Info] Client Version 1.3.2 (windows x86_64) Source ID: 4d70cfed23093a8e5abe06d662c6a5610fefc596 Protocol: 743
    [19:58:04.231] [Info] Root: Scanning for asset sources in directory '..\assets\'
    [19:58:06.413] [Info] Root: Scanning for asset sources in directory '..\mods\'
    [19:58:06.428] [Info] Root: Detected asset source named 'base' at '..\assets\packed.pak'
    [19:58:06.428] [Info] Root: Detected asset source named 'Hemp+' at '..\mods\Hemp+'
    [19:58:06.428] [Info] Root: Detected asset source named 'spelltomes' at '..\mods\Spell Tomes'
    [19:58:06.428] [Info] Root: Detected unnamed asset source at '..\assets\user'
    [19:58:06.428] [Info] Loading assets from: '..\assets\packed.pak'
    [19:58:08.751] [Info] Loading assets from: '..\mods\Hemp+'
    [19:58:08.765] [Info] Loading assets from: '..\mods\Spell Tomes'
    [19:58:08.781] [Info] Loading assets from: '..\assets\user'
    [19:58:11.177] [Info] Assets digest is 14670b2194c5e44ebd74281ee4542df952995068931b1628330497bf616e6131
    [19:58:11.178] [Info] Root: Loaded Assets in 6.94676 seconds
    [19:58:11.193] [Info] Application: Initializing SDL Video
    [19:58:11.201] [Info] Application: Initializing SDL Joystick
    [19:58:11.252] [Info] Application: Initializing SDL Sound
    [19:58:11.263] [Info] Initialized Steam services
    [19:58:11.263] [Info] Application: Creating SDL Window
    [19:58:11.368] [Info] Application: Enabling VSync with late swap tearing
    [19:58:11.900] [Info] Application: Opened default audio device with 44.1khz / 16 bit stereo audio, 2048 sample size buffer
    [19:58:11.918] [Info] OpenGL version: '4.4.0 - Build 20.19.15.4568' vendor: 'Intel' renderer: 'Intel(R) HD Graphics 400' shader: '4.40 - Build 20.19.15.4568'
    [19:58:11.929] [Info] Application: initialization...
    [19:58:11.932] [Info] Root: Loaded Configuration in 0.00284937 seconds
    [19:58:11.935] [Info] Application: Disabling VSync
    [19:58:11.980] [Info] Application: renderer initialization...
    [19:58:12.000] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 128
    [19:58:12.000] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 64
    [19:58:12.006] [Info] Root: Loaded ImageMetadataDatabase in 3.84013e-06 seconds
    [19:58:12.100] [Info] Application: main update loop...
    [19:58:12.102] [Info] No subscribed user generated content
    [19:58:12.135] [Info] Root: Loaded NameGenerator in 0.0270121 seconds
    [19:58:12.632] [Info] Root: Loaded PlantDatabase in 0.488494 seconds
    [19:58:14.570] [Info] Root: Loaded ObjectDatabase in 2.43422 seconds
    [19:58:15.191] [Info] Root: Loaded ProjectileDatabase in 2.55871 seconds
    [19:58:15.578] [Info] Root: Loaded NpcDatabase in 0.38691 seconds
    [19:58:15.587] [Info] Root: Loaded StagehandDatabase in 0.00759257 seconds
    [19:58:15.597] [Info] Root: Loaded MonsterDatabase in 1.02753 seconds
    [19:58:15.605] [Info] Root: Loaded VehicleDatabase in 0.0144408 seconds
    [19:58:15.625] [Info] Root: Loaded PlayerFactory in 0.0202023 seconds
    [19:58:15.629] [Info] Root: Loaded VersioningDatabase in 0.00382029 seconds
    [19:58:15.629] [Info] Root: Loaded EntityFactory in 0.0157138 seconds
    [19:58:15.925] [Info] Root: Loaded ParticleDatabase in 0.295121 seconds
    [19:58:16.222] [Info] Root: Writing runtime configuration to '..\storage\starbound.config'
    [19:58:17.006] [Info] Root: Loaded MaterialDatabase in 1.3765 seconds
    [19:58:17.069] [Info] Root: Loaded TerrainDatabase in 0.0333938 seconds
    [19:58:17.304] [Info] Root: Loaded BiomeDatabase in 0.235052 seconds
    [19:58:17.325] [Info] Root: Loaded LiquidsDatabase in 0.0213274 seconds
    [19:58:17.390] [Info] Root: Loaded StatusEffectDatabase in 0.0646697 seconds
    [19:58:19.117] [Info] Root: Loaded DamageDatabase in 1.72614 seconds
    [19:58:19.198] [Info] Root: Loaded EffectSourceDatabase in 0.0810497 seconds
    [19:58:19.217] [Info] Root: Loaded FunctionDatabase in 0.0193453 seconds
    [19:58:19.438] [Info] Root: Loaded TreasureDatabase in 0.220709 seconds
    [19:58:20.773] [Info] Root: Loaded DungeonDefinitions in 1.33509 seconds
    [19:58:20.774] [Info] Root: Loaded TilesetDatabase in 0.000106884 seconds
    [19:58:20.788] [Info] Root: Loaded StatisticsDatabase in 0.0138616 seconds
    [19:58:20.788] [Info] Root: Loaded EmoteProcessor in 0.000178566 seconds
    [19:58:20.830] [Info] Root: Loaded SpeciesDatabase in 0.0413569 seconds
    [19:58:20.965] [Info] Root: Loaded QuestTemplateDatabase in 0.135401 seconds
    [19:58:20.971] [Info] Root: Loaded AiDatabase in 0.00562963 seconds
    [19:58:20.980] [Info] Root: Loaded TechDatabase in 0.00910494 seconds
    [19:58:21.018] [Info] Root: Loaded CodexDatabase in 0.0377542 seconds
    [19:58:22.473] [Info] Root: Loaded BehaviorDatabase in 1.45397 seconds
    [19:58:22.503] [Info] Root: Loaded DanceDatabase in 0.0299216 seconds
    [19:58:22.533] [Info] Root: Loaded SpawnTypeDatabase in 0.0297495 seconds
    [19:58:22.544] [Info] Root: Loaded RadioMessageDatabase in 0.0107799 seconds
    [19:58:27.288] [Info] Root: Loaded ItemDatabase in 11.6622 seconds
    [19:58:27.720] [Info] Root: Loaded CollectionDatabase in 5.1763 seconds
    [19:58:29.293] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 128
    [19:58:46.581] [Info] UniverseServer: Acquiring universe lock file
    [19:58:46.585] [Info] UniverseServer: Loading settings
    [19:58:46.594] [Info] UniverseServer: Starting UniverseServer with UUID: 76e49d850f43873b4188b1aa957181e2
    [19:58:46.606] [Info] UniverseServer: Logged in player 'Skye' locally
    [19:58:46.606] [Info] UniverseServer: Logged in account '<anonymous>' as player 'Skye' from address local
    [19:58:46.670] [Info] UniverseServer: Loading system world (-74701158, 904242160, 34869245) from disk storage
    [19:58:46.717] [Info] UniverseClient: Joined server as client 1
    [19:58:46.856] [Info] UniverseServer: Reviving player at ClientShipWorld:46d5db7938ad475591d19f913fab2454
    [19:58:46.857] [Info] UniverseServer: Client 'Skye' <1> (local) connected
    [19:58:46.859] [Info] UniverseServer: Loading client ship world ClientShipWorld:46d5db7938ad475591d19f913fab2454
    [19:58:47.247] [Info] Protected dungeonIds for world set to (65524)
    [19:58:47.980] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 64
    [19:58:47.980] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 128
    [19:58:47.999] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 128
    [19:58:47.999] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 128
    [19:58:48.002] [Info] UniverseServer: listening for incoming TCP connections on 0.0.0.0:21025
    [19:58:48.018] [Info] UniverseServer: Warping player 1 to ClientShipWorld:46d5db7938ad475591d19f913fab2454=1041.46.1024
    [19:58:48.892] [Error] Exception while calling script init: (LuaException) Error code 2, [string "/stats/effects/cannabis/munchies.lua"]:2: attempt to compare two nil values
    stack traceback:
        [C]: in metamethod '__lt'
        [string "/stats/effects/cannabis/munchies.lua"]:2: in function <[string "/stats/effects/cannabis/munchies.lua"]:1>
    [0] 7ff627eb7153 Star::captureStack
    [1] 7ff627eb5ede Star::StarException::StarException
    [2] 7ff627e8a4c1 Star::LuaEngine::handleError
    [3] 7ff62807931b Star::LuaEngine::callFunction<>
    [4] 7ff62807c712 Star::LuaFunction::invoke<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [5] 7ff628522273 Star::LuaContext::invokePath<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [6] 7ff628523e0b Star::LuaBaseComponent::init
    [7] 7ff6282e0adc Star::StatusController::init
    [8] 7ff6281b719e Star::Player::init
    [9] 7ff6283f8e8d Star::WorldClient::initWorld
    [10] 7ff6283f6e57 Star::WorldClient::handleIncomingPackets
    [11] 7ff62836a1df Star::UniverseClient::handlePackets
    [12] 7ff62836b69f Star::UniverseClient::update
    [13] 7ff627dfe557 Star::ClientApplication::updateRunning
    [14] 7ff627dfce4f Star::ClientApplication::update
    [15] 7ff6285faa72 Star::SdlPlatform::run
    [16] 7ff6285fac2d Star::runMainApplication
    [17] 7ff627dfff76 WinMain
    [18] 7ff6287e8daf __scrt_common_main_seh
    [19] 7ffb35611fe4 BaseThreadInitThunk
    [20] 7ffb370ff061 RtlUserThreadStart
    [19:58:56.905] [Error] Exception while calling script init: (LuaException) Error code 2, [string "/stats/effects/cannabis/munchies.lua"]:2: attempt to compare two nil values
    stack traceback:
        [C]: in metamethod '__lt'
        [string "/stats/effects/cannabis/munchies.lua"]:2: in function <[string "/stats/effects/cannabis/munchies.lua"]:1>
    [0] 7ff627eb7153 Star::captureStack
    [1] 7ff627eb5ede Star::StarException::StarException
    [2] 7ff627e8a4c1 Star::LuaEngine::handleError
    [3] 7ff62807931b Star::LuaEngine::callFunction<>
    [4] 7ff62807c712 Star::LuaFunction::invoke<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [5] 7ff628522273 Star::LuaContext::invokePath<Star::Variant<Star::Empty,bool,__int64,double,Star::String,Star::LuaTable,Star::LuaFunction,Star::LuaThread,Star::LuaUserData> >
    [6] 7ff628523e0b Star::LuaBaseComponent::init
    [7] 7ff6282dc056 Star::StatusController::addUniqueEffect
    [8] 7ff6282db91b Star::StatusController::addEphemeralEffects
    [9] 7ff6284d2322 Star::ConsumableItem::triggerEffects
    [10] 7ff6284d1fe9 Star::ConsumableItem::fireTriggered
    [11] 7ff6284b17d0 Star::FireableItem::update
    [12] 7ff6284d2625 Star::ConsumableItem::update
    [13] 7ff62835c780 Star::ToolUser::tick
    [14] 7ff6281c3221 Star::Player::update
    [15] 7ff6283ea178 <lambda_9fc580ae40b93070d912cafafa15880e>::operator()
    [16] 7ff62800a5d7 Star::EntityMap::updateAllEntities
    [17] 7ff628402659 Star::WorldClient::update
    [18] 7ff62836b753 Star::UniverseClient::update
    [19] 7ff627dfe557 Star::ClientApplication::updateRunning
    [20] 7ff627dfce4f Star::ClientApplication::update
    [21] 7ff6285faa72 Star::SdlPlatform::run
    [22] 7ff6285fac2d Star::runMainApplication
    [23] 7ff627dfff76 WinMain
    [24] 7ff6287e8daf __scrt_common_main_seh
    [25] 7ffb35611fe4 BaseThreadInitThunk
    [26] 7ffb370ff061 RtlUserThreadStart
    [19:59:47.150] [Info] UniverseClient: Client disconnecting...
    [19:59:47.219] [Info] Client received world stop packet, leaving: Removed
    [19:59:47.618] [Info] UniverseServer: Client 'Skye' <1> (local) disconnected for reason:
    [19:59:47.619] [Info] UniverseServer: Stopping idle world ClientShipWorld:46d5db7938ad475591d19f913fab2454
    [19:59:48.078] [Info] UniverseServer: Stopping UniverseServer
    [19:59:48.079] [Info] UniverseServer: Stopping TCP Server
    [19:59:49.982] [Info] Application: quit requested
    [19:59:49.982] [Info] Application: quitting...
    [19:59:49.982] [Info] Application: shutdown...
    [19:59:50.311] [Info] Root: Shutting down Root
    [19:59:50.912] [Error] OpenGL errors during shutdown:  GL_INVALID_VALUE
    [19:59:50.913] [Info] Application: Destroying SDL Window
    [19:59:51.134] [Info] Application: stopped gracefully
    
    Code:
    function init()
        if (hungerLevel > hungerMin) then
        self.tickTimerPenalty = self.tickTimePenalty
    end
    end
    function update(dt)
      status.modifyResource("hunger", self.hungerRate * dt)
    end
    
    function uninit()
     
    end
    Code:
    {
        "name" : "munchies",
        "effectConfig" : { "foodAmount" : 25, "emissionRate" : 25 },
        "defaultDuration" : 120,
        "scripts" : [ "munchies.lua" ],
        "label" : "The munchies",
        "icon" : "/interface/statuses/hungry.png"
    }
    
     
  2. DraikNova

    DraikNova Spaceman Spiff

    Pretty sure you're not initializing hungerLevel and hungerMin properly. The function currently doesn't have any way to know that what those two mean are values used by the player.
     
  3. SkyeTheTerribleBeastie

    SkyeTheTerribleBeastie Pangalactic Porcupine

    So that'd mean... I'd have to turn it into a damage that affects Hunger instead of Health?
    I'm completely new to all this, so I wouldn't know where to start.
     
  4. DraikNova

    DraikNova Spaceman Spiff

    What you need to do is something so it knows where to get the values, so either initialize or replace hungerMin and hungerLevel with the appropriate values. I'm assuming hungerMin is supposed to be the foodAmount in effectConfig, right? For that one, you would need to do something like config.getParameter("foodAmount", 25) (the first is what your parameter in the effectConfig is, the number after it is what you want the default to be in case it for some reason does not have a valid parameter there). As for the hungerLevel, you want status.resourcePercentage("food"). Also, your code uses status.modifyResourcePercentage("hunger", stuff) where you should be using "food" instead of "hunger".
     
    Last edited: Apr 22, 2018
  5. SkyeTheTerribleBeastie

    SkyeTheTerribleBeastie Pangalactic Porcupine

    Eep, ok, lot to take in and decompress there- misnames like hunger->food happen from cross-mod checking, and checking against outdated mods, so I'll make sure to compare to original assets more than other mods.

    So, the changes should be:
    Replace "hunger" with "food" where applicable, otherwise change to correct value
    Change init to get food parameter
    Change update to "If food is above 25, 5x food degen until 25"

    Of that, I've figured out it should look more like this:
    Code:
    function init()
        config.getParameter("foodAmount", 25)
    end
    
    function update(dt)
        if status.resourcePercentage("food") > ("foodAmount") then
        status.modifyResource("food", self.foodRate * dt)
        end
    end
    
    function uninit()
    end
    

    but I'm pretty sure there's something I'm missing or doing wrong, as I get back this:
    Code:
    [23:28:07.082] [Error] Exception while invoking lua function 'update'. (LuaException) Error code 2, [string "/stats/effects/cannabis/munchies.lua"]:6: attempt to compare string with number
    stack traceback:
        [C]: in metamethod '__lt'
        [string "/stats/effects/cannabis/munchies.lua"]:6: in function <[string "/stats/effects/cannabis/munchies.lua"]:5>
     
  6. DraikNova

    DraikNova Spaceman Spiff

    if status.resourcePercentage("food") > ("foodAmount") then
    should be
    if status.resourcePercentage("food") > config.getParameter("foodAmount", 25) then
    and without the config.getParameter("foodAmount", 25) in the init. Or, otherwise, do self.hungerLevel = config.getParameter("foodAmount", 25) in the init and do
    if status.resourcePercentage("food") > self.hungerLevel then

    Also, I recommend you join the Starbound discord's modding channel: https://discordapp.com/channels/176434793674833920/176662557199695883
    You can get really rapid responses and feedback there.
     
  7. SkyeTheTerribleBeastie

    SkyeTheTerribleBeastie Pangalactic Porcupine

    Oooh, right, gotcha, duh.
    With that change, it has stopped erroring!
    ...But it still doesn't drain the food bar any faster, I assume that's in the next segment after 'then'.

    And thanks for the link, I wouldn't have thought to look for a livechat for modding assistance- I'll do the thing with it.

    So, currently doesn't error, effect shows up with name, effect drains at basically the same time as the primary effects, but doesn't DO anything.
    Code:
    function init()
    
    end
    
    function update(dt)
        if status.resourcePercentage("food") > config.getParameter("foodAmount", 25) then
        status.modifyResource("food", self.foodRate * dt)
        end
    end
    
    function uninit()
    
    end
     
  8. DraikNova

    DraikNova Spaceman Spiff

    Have you actually defined self.foodRate? Because you don't seem to have done so. Also, I think you want status.consumeResource, rather than status.modifyResource. modifyResource, according to the starbounder wiki, adds the amount specified in its second parameter, while what you want is to try and remove that amount.
     
  9. SkyeTheTerribleBeastie

    SkyeTheTerribleBeastie Pangalactic Porcupine

    No, I haven't- I have no idea what it means to do so, either. I did fix modify->consume, though.
     
  10. DraikNova

    DraikNova Spaceman Spiff

    You need to initialize self.foodRate: so, in init, either do the same thing with config.getParameter (if you decide to put foodRate into your statuseffect file's effectconfig) as with "foodAmount" and add self.foodRate = config.getParameter("foodRate",<default value>) to the init, or alternatively just add self.foodRate = <value you want to give it> to the init.
     
  11. SkyeTheTerribleBeastie

    SkyeTheTerribleBeastie Pangalactic Porcupine

    Alright, got help from the peeps over on the Discord server- it now works EXACTLY how I wanted!
    vo.3 releasing soon
     
    DrPvtSkittles likes this.

Share This Page