Modding Help Need help with patching

Discussion in 'Starbound Modding' started by raychaser, Jan 13, 2024.

  1. raychaser

    raychaser Intergalactic Tourist

    Greetings

    I want to make a mod, that will apply invisibility to player when he is in the dark
    I suppose i need to get player position to write script for light-cheking and patch player.config file, to add my script to player primary scripts.
    But here's one small issue
    I have no idea how i can do this

    I already read unpacked starbound code as an reference for several actions, but still can't understand what to do
     
  2. Rezetrx

    Rezetrx Void-Bound Voyager

    Add your own script to the player.

    player.config.patch
    Code:
    [
      {
        "op": "add",
        "path": "/genericScriptContexts/customplayercode",
        "value": "/stats/customplayercode.lua"
      }
    ]
    
    /stats/customplayercode.lua

    Code:
    require "/scripts/status.lua"
    require "/scripts/vec2.lua"
    
    function init()
        self.updatetimer = 0
        self.updatesequence = 1
    end
    
    function update(dt)
        -- Timer builds up
        self.updatetimer = self.updatetimer + dt
       
        -- Triggers every 1s
        if self.updatetimer >= self.updatesequence then
            --to something
            HandleInvisi()
            self.updatetimer = 0
        end
    end
    
    function HandleInvisi()
        local llevel = world.lightLevel(world.entityPosition(player.id()))
        if llevel < 0.3 then
           -- ray_invis_category can be any name for the effectcategory
            status.addPersistentEffect("ray_invis_category", "invisible")
        else
            status.clearPersistentEffects("ray_invis_category")
        end
    
    end
    
    This script checks every 1s if the light level is bellow your threshhold and if so, adds the status effect.

    Note: the function "world.lightLevel" requires recalculation of lighting, so it should be used sparingly
     

Share This Page