Modding Help Editing ship pets and their action queue. PetBehaviour.lua

Discussion in 'Starbound Modding' started by ViralHatred, May 11, 2018.

  1. ViralHatred

    ViralHatred Void-Bound Voyager

    As part of my modding I am attempting to change the functionality of how pets work.

    Based on my current level of understanding it appears that ship pets work by the following:

    1) Timers are triggered to accumulate a score for each of the resources a pet has; Hunger, Curiosity, Fun, Sleepy

    2) The possible actions a pet can perform are scored by a value; Beg, Eat, Sleep, Pounce, Follow, Inspect

    3) Each action removes a value from the resource associated with it.

    4) Pet will pick an action related to whichever status is the highest and repeat as necessary.


    What I'm trying to do is reverse the system. So what I'd like to achieve is to have the pet perform the LOWEST scoring option. And I know the segment of code that relates to it is the one below. However attempts to change values such as <=0 to >=100 and so on have had no effect except to either break the pet entirely so it repeatedly flicks between being visible and invisible or to cause the pet to perform no actions at all except walking around.

    Code:
      --Pick the first valid option
      for _,action in pairs(petBehavior.actionQueue) do
        if action.score <= 0 or action.score <= self.currentActionScore + self.actionInterruptThreshold then break end
    
        local picked = false
        if not self.actionParams[action.type] or action.score > self.actionParams[action.type].minScore then
          if petBehavior.actionStates[action.type] and self.actionState.stateDesc() ~= petBehavior.actionStates[action.type] then
            if (action.args and self.actionState.pickState(action.args)) then
              picked = true
            elseif(petBehavior.actionStates[action.type] and self.actionState.pickState({[petBehavior.actionStates[action.type]] = true})) then
              picked = true
            end
          elseif petBehavior.actions[action.type] and petBehavior.performAction(action.type) then
            picked = true
          end
        end
    
        if picked then
          self.currentActionScore = action.score
          break
        end
      end
    
      petBehavior.actionQueue = {}
    end
    I have already modified the actions to provide positive values rather than negative ones, changed the delta timers to negatives so they decrease steadily and also made it set all the pet's resources to 100 on initialisation.

    If someone could help me break down this chunk of code I'd really appreciate the help. Thanks.
     

Share This Page