Modding Help sending entity messages to player

Discussion in 'Starbound Modding' started by CTFJERK, Aug 28, 2017.

Tags:
  1. CTFJERK

    CTFJERK Intergalactic Tourist

    ok, in my mod i am trying to make npcs follow the player in response to a gui response. everything went well till the very last part where the recruitable code sends entity message to the player to request follow.
    You see, in the recuitable.lua i did the following:
    Code:
    function recruitable.init()
      ...
      message.setHandler("option_one",function()
      sb.logInfo("hooozahk")
      npc.say(entity.uniqueId())
      world.sendEntityMessage( entity.uniqueId(),"recruits.requestFollowi")
        end)
    (note: i took the parameters out cause i was checking whether it was a formatting problem or something)
    and in the player.lua i did the following
    Code:
    function init()
      ...
      message.setHandler("recruits.requestFollowi", function()
      sb.logInfo("tacks")
      local uniqueId = entity.uniqueId()
      local recruitUuid = recruitable.recruitUuid()
      local recruitInfo = recruitable.generateRecruitInfo()
    
      sb.logInfo(uniqueId)
      if not checkCrewLimits(recruitUuid) then
        world.sendEntityMessage(uniqueId, "recruit.interactBehavior", { sourceId = entity.id() })
        return
      end
      promises:add(world.sendEntityMessage(uniqueId, "recruit.confirmFollow"), function (success)
          recruitSpawner:recruitFollowing(onOwnShip(), recruitUuid, recruitInfo)
        end)
    end)
    "hooozahk" goes through, but tacks does not.

    also in case your wondering, i did do the functions like this;
    world.sendEntityMessage( entity.uniqueId(),"recruits.requestFollowi",entity.uniqueId(), recruitable.recruitUuid(),recruitable.generateRecruitInfo())
    and
    message.setHandler("recruits.requestFollowi", function(_,_,uniqueId,recruitUuid,recruitInfo)
    sb.logInfo("tacks")
    end)
    but still no dice.
     
  2. CTFJERK

    CTFJERK Intergalactic Tourist

    Alright! i found out that there is a function called recruitable.messageOwner(messagetype,args...) that allows messages to be sent to the player. Was really confused as i tried to differentiate what made making a return based message different from world.sendEntityMessage message.
    Still unsure why the other way didn't work, probably has something to do with the server-client relationship. Also still wondering how the whole "promise" thing works aswell. either way it works now.
     
    artguk likes this.

Share This Page