Modding Help issue with adding script to 'primaryScriptSources'

Discussion in 'Starbound Modding' started by tehhash, Mar 20, 2017.

  1. tehhash

    tehhash Intergalactic Tourist

    Hello, I am having a very strange issue with a mod I've been working with. Simply, whenever I add a script to the array 'primaryScriptSources' in player.config via .patch, the game loads and everything works as expected except for one issue. My energy doesn't regenerate and I take no damage.

    What I was trying to do was add a script to apply a custom status effect to the player. The status effect will slow the rate at which you lose 'food' while in shipworld by regenerating the player's 'food'.

    Here's the content of my files:
    {"op" : "add", "path" : "/statusControllerSettings/primaryScriptSources/-", "value" : "/scripts/stasis.lua"}

        "name" : "nourish",
        "effectConfig" : {
            "rate" : 0.04
        "defaultDuration" : 1,
        "scripts" : [
      "label" : "Nourished",
      "icon" : "/interface/statuses/nourish.png"

    function init()
    function update(dt)
        local foodRate = config.getParameter("rate", 0.04) / effect.duration()
        status.modifyResource("food", foodRate * dt)
    function uninit()

    function init()
    function update(dt)
        if world.getProperty("invinciblePlayers") then
    function uninit()

    [03:44:11.932] [Info] Root: Preparing Root...
    [03:44:11.933] [Info] Root: Done preparing Root.
    [03:44:11.933] [Info] Client Version 1.2.3b (windows i386) Source ID: 69bc1c906122a1c61453c6cff15aa088b613db78 Protocol: 729
    [03:44:11.933] [Info] Root: Scanning for asset sources in directory '..\assets\'
    [03:44:12.758] [Info] Root: Scanning for asset sources in directory '..\mods\'
    [03:44:12.759] [Info] Root: Detected asset source named 'base' at '..\assets\packed.pak'
    [03:44:12.759] [Info] Root: Detected unnamed asset source at '..\mods\testmod.pak'
    [03:44:12.759] [Info] Loading assets from: '..\assets\packed.pak'
    [03:44:13.739] [Info] Loading assets from: '..\mods\testmod.pak'
    [03:44:15.080] [Info] Assets digest is dac6fef0204a98c03366b9ae6b5a026425891456c92a7a4b84760cd0b0184be1
    [03:44:15.080] [Info] Root: Loaded Assets in 3.14687 seconds
    [03:44:15.087] [Info] Application: Initializing SDL Video
    [03:44:15.093] [Info] Application: Initializing SDL Joystick
    [03:44:15.195] [Info] Application: Initializing SDL Sound
    [03:44:15.308] [Info] Failed to initialize Steam platform services
    [03:44:15.308] [Info] Application: No platform services available
    [03:44:15.308] [Info] Application: Creating SDL Window
    [03:44:15.518] [Info] Application: Enabling VSync with late swap tearing
    [03:44:15.543] [Info] Application: Opened default audio device with 44.1khz / 16 bit stereo audio, 2048 sample size buffer
    [03:44:15.557] [Info] OpenGL version: '4.5.0 NVIDIA 375.70' vendor: 'NVIDIA Corporation' renderer: 'GeForce GTX 660/PCIe/SSE2' shader: '4.50 NVIDIA'
    [03:44:15.561] [Info] Application: initialization...
    [03:44:15.563] [Info] Root: Loaded Configuration in 0.0015601 seconds
    [03:44:15.566] [Info] Application: renderer initialization...
    [03:44:15.569] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 128
    [03:44:15.569] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 64
    [03:44:15.572] [Info] Root: Loaded ImageMetadataDatabase in 2.63086e-06 seconds
    [03:44:15.600] [Info] Application: main update loop...
    [03:44:15.663] [Info] Root: Loaded NameGenerator in 0.0604471 seconds
    [03:44:15.707] [Error] OpenGL errors this frame: GL_INVALID_VALUE
    [03:44:15.822] [Info] Root: Loaded PlantDatabase in 0.1591 seconds
    [03:44:16.253] [Info] Root: Loaded ObjectDatabase in 0.615204 seconds
    [03:44:16.559] [Info] Root: Loaded MonsterDatabase in 0.305716 seconds
    [03:44:16.629] [Info] Root: Loaded NpcDatabase in 0.0704976 seconds
    [03:44:16.631] [Info] Root: Loaded StagehandDatabase in 0.00179293 seconds
    [03:44:16.636] [Info] Root: Loaded VehicleDatabase in 0.00458558 seconds
    [03:44:16.642] [Info] Root: Loaded PlayerFactory in 0.00629366 seconds
    [03:44:16.675] [Info] Root: Loaded ProjectileDatabase in 0.852684 seconds
    [03:44:16.676] [Info] Root: Loaded VersioningDatabase in 0.00101091 seconds
    [03:44:16.676] [Info] Root: Loaded EntityFactory in 0.0335759 seconds
    [03:44:16.741] [Info] Root: Loaded ParticleDatabase in 0.0645736 seconds
    [03:44:17.174] [Info] Root: Loaded MaterialDatabase in 0.497917 seconds
    [03:44:17.182] [Info] Root: Loaded TerrainDatabase in 0.0079261 seconds
    [03:44:17.239] [Info] Root: Loaded BiomeDatabase in 0.0574762 seconds
    [03:44:17.241] [Info] Root: Loaded LiquidsDatabase in 0.00133845 seconds
    [03:44:17.252] [Info] Root: Loaded StatusEffectDatabase in 0.0107382 seconds
    [03:44:17.739] [Info] Root: Loaded DamageDatabase in 0.487715 seconds
    [03:44:17.747] [Info] Root: Loaded EffectSourceDatabase in 0.00792709 seconds
    [03:44:17.753] [Info] Root: Loaded FunctionDatabase in 0.0056616 seconds
    [03:44:17.796] [Info] Root: Loaded TreasureDatabase in 0.0425356 seconds
    [03:44:18.241] [Info] Root: Loaded DungeonDefinitions in 0.444584 seconds
    [03:44:18.242] [Info] Root: Loaded TilesetDatabase in 3.88051e-05 seconds
    [03:44:18.245] [Info] Root: Loaded StatisticsDatabase in 0.00362926 seconds
    [03:44:18.245] [Info] Root: Loaded EmoteProcessor in 0.000127925 seconds
    [03:44:18.257] [Info] Root: Loaded SpeciesDatabase in 0.0115642 seconds
    [03:44:18.282] [Info] Root: Loaded QuestTemplateDatabase in 0.0249586 seconds
    [03:44:18.285] [Info] Root: Loaded AiDatabase in 0.0023431 seconds
    [03:44:18.286] [Info] Root: Loaded TechDatabase in 0.00143217 seconds
    [03:44:18.295] [Info] Root: Loaded CodexDatabase in 0.0085141 seconds
    [03:44:18.910] [Info] Root: Loaded BehaviorDatabase in 0.615561 seconds
    [03:44:18.917] [Info] Root: Loaded DanceDatabase in 0.00617987 seconds
    [03:44:18.928] [Info] Root: Loaded SpawnTypeDatabase in 0.0110193 seconds
    [03:44:18.933] [Info] Root: Loaded RadioMessageDatabase in 0.00475592 seconds
    [03:44:20.091] [Info] Root: Writing runtime configuration to '..\storage\starbound.config'
    [03:44:21.071] [Info] Root: Loaded ItemDatabase in 4.39573 seconds
    [03:44:21.355] [Info] Root: Loaded CollectionDatabase in 2.42245 seconds
    [03:44:23.029] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 256
    [03:44:27.374] [Info] UniverseServer: Acquiring universe lock file
    [03:44:27.376] [Info] UniverseServer: Loading settings
    [03:44:27.378] [Info] UniverseServer: Starting UniverseServer with UUID: e54bae0117a80f42d8f46230b411a1a1
    [03:44:27.396] [Info] UniverseServer: Logged in player 'Junoji' locally
    [03:44:27.396] [Info] UniverseServer: Logged in account '<anonymous>' as player 'Junoji' from address local
    [03:44:27.433] [Info] UniverseServer: Reviving player at ClientShipWorld:a5615141372bd6923286c6c3f45ae5b3
    [03:44:27.433] [Info] UniverseServer: Client 'Junoji' <1> (local) connected
    [03:44:27.444] [Info] UniverseClient: Joined server as client 1
    [03:44:27.525] [Info] UniverseServer: Loading client ship world ClientShipWorld:a5615141372bd6923286c6c3f45ae5b3
    [03:44:27.878] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 64
    [03:44:27.878] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 128
    [03:44:27.889] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 256
    [03:44:27.889] [Info] detected supported OpenGL texture size 16384, using atlasNumCells 256
    [03:44:27.925] [Info] UniverseServer: listening for incoming TCP connections on
    [03:44:29.795] [Info] UniverseServer: Warping player 1 to ClientShipWorld:a5615141372bd6923286c6c3f45ae5b3=1072.75.1024
    [03:44:50.220] [Info] UniverseClient: Client disconnecting...
    [03:44:50.255] [Info] Client received world stop packet, leaving: Removed
    [03:44:51.078] [Info] UniverseServer: Client 'Junoji' <1> (local) disconnected for reason:
    [03:44:51.079] [Info] UniverseServer: Stopping idle world ClientShipWorld:a5615141372bd6923286c6c3f45ae5b3
    [03:44:52.170] [Info] UniverseServer: Stopping UniverseServer
    [03:44:52.170] [Info] UniverseServer: Stopping TCP Server
    [03:44:56.028] [Info] Application: quit requested
    [03:44:56.029] [Info] Application: quitting...
    [03:44:56.029] [Info] Application: shutdown...
    [03:44:56.159] [Info] Root: Shutting down Root
    [03:44:56.592] [Info] Application: Destroying SDL Window
    [03:44:56.715] [Info] Application: stopped gracefully

    I have tried several different things, but no luck. I even tried adding a blank script to 'primaryScriptSources' and still no energy regen or damage. It seems as if I add anything to 'primaryScriptSources' this issue occurs... Are we not able to insert scripts into 'primaryScriptSources' or maybe I'm missing something... I have searched the wiki and forum up and down to no avail.. Any help will be much appreciated!
  2. TheElderScroller

    TheElderScroller Big Damn Hero

    Add your code to the existing script player_primary.lua. Either a patch to primaryScriptSources will cause trouble or only the last script in the table gets updated.
  3. tehhash

    tehhash Intergalactic Tourist

    Thank you for the quick reply! I did some testing and came up with a few things, but I'm still not positive how it works. It seems as if any custom script is inserted after player_primary.lua casuses it to have issues. Any other order seems to be fine as long as player_primary.lua is after any custom added scripts. Also, when I tested this my script only worked when it was added to the end of the array.

    Adding the code directly to player_primary.lua did indeed do the trick though! Thank you so much!

    If anyone can figure out the issue to my initial problem, be my guest haha! I would rather not replace any existing files if not necessary, but this will have to work for now. :)
  4. bk3k

    bk3k Black Hole Surfer

    If you're suggesting a replacement script with a little code added... no please don't do that because you'll break every mod that does hook this. Hook the script instead.

    edit: and no, that won't cause trouble. Many mods - Frackin Universe and my own mods included - do exactly the thing you insist not be done. It only causes trouble when done incorrectly.

    Replacement /scripts/stasis.lua

    tehhash = {
      update = update
        --I'm copying the old function, and will call it later
    function update(dt)
      if world.getProperty("invinciblePlayers") then
    If you want to know what you did wrong originally, you actually replaced init, update, and uninit with your own copies. Functions are a lua value type just like numbers, strings, tables, etc. You CAN replace them, copy them, etc. That is also how you hook them. That code copies update and then replaces update with your code. Only the replacement code calls the copied (old) function so you don't loose out on whatever work it did.

    This is important because others can - and do - hook the player environment too. Without hooking as I demonstrated, you're replacing any code that should have loaded before your own. The things they do won't be done. You'll break FU, some of my mods, and others.
    IHart, Cyel and The | Suit like this.
  5. tehhash

    tehhash Intergalactic Tourist

    Ohhh wow, ok I get it now. First of all I guess the file I thought was blank wasn't, it also had an update func...
    I applied the suggested changes to the lua code, low and behold! It worked! Was hung up for hours trying to figure out was going on and it was such a simple fix haha :)
    Just started messing with the lua code for the first time a few days ago so I'm still very green. I knew there had to be a way, because yes a lot of mods will hook the player as you stated. This was exactly what I was looking for, thanks a lot man!!!
  6. The | Suit

    The | Suit Agent S. Forum Moderator

    Cyel likes this.

Share This Page