Jump to content

Recommended Posts

Hello!
I'm trying to make my own mod for writing on papyrus. I added custom prefab for it and few actions. But it won't work for clients. The chatlog says when they're trying:

Spoiler

[01:08:13]: Invalid LeftClick RPC from (KU_voGjEE4r) kristal_milton    
[01:08:15]: Invalid UseItemFromInvTile RPC from (KU_voGjEE4r) kristal_milton


I have no idea what I am supposed to do with this information. Please give me some help on this. Here's my modmain.lua, I think prefab file will be useless for this problem.
 

Spoiler
-- Crazy's Written Papyrus Mod
local _G = GLOBAL
 
-- Import necessary modules
local Recipe = _G.Recipe
local Ingredient = _G.Ingredient
local RECIPETABS = _G.RECIPETABS
local TECH = _G.TECH
local STRINGS = _G.STRINGS
local ACTIONS = _G.ACTIONS
local Action = _G.Action
local BufferedAction = _G.BufferedAction
local ActionHandler = _G.ActionHandler
local State = _G.State
local TheInput = _G.TheInput
local Vector3 = _G.Vector3
local RPC = _G.RPC
 
-- Mod RPC Namespace
local MOD_RPC_NAMESPACE = "CRAZY_WRITTEN_PAPYRUS_MOD"
 
-- Assets and Prefabs
Assets = {
    Asset("ATLAS", "images/inventoryimages/written_papyrus.xml"),
    Asset("IMAGE", "images/inventoryimages/written_papyrus.tex")
}
 
PrefabFiles = {
    "written_papyrus"
}
 
-- Strings and Descriptions
local NAMES = STRINGS.NAMES
local CHARACTERS = STRINGS.CHARACTERS
 
NAMES.WRITTEN_PAPYRUS = "Written Papyrus"
 
-- Helper function to add character descriptions
local function AddDescription(character, item, description)
    if CHARACTERS[character] and CHARACTERS[character].DESCRIBE then
        CHARACTERS[character].DESCRIBE[item] = description
    end
end
 
-- Add recipe for written papyrus
AddRecipe("written_papyrus",
    {Ingredient("papyrus", 1)},
    RECIPETABS.TOOLS,
    TECH.NONE,
    nil, nil, nil, nil, nil,
    "images/inventoryimages/written_papyrus.xml")
 
-- Add description for all characters
local characters = {"GENERIC", "WILLOW", "WOLFGANG", "WENDY", "WX78", "WICKERBOTTOM", "WOODIE", "MAXWELL", "WIGFRID", "WEBBER", "WINONA", "WARLY", "WORTOX", "WORMWOOD", "WURT", "WALTER", "WANDA"}
 
for _, character in ipairs(characters) do
    AddDescription(character, "WRITTEN_PAPYRUS", "I should probably try to write something on this one.")
end
 
-- Create WRITE action
ACTIONS.WRITE = Action()
ACTIONS.WRITE.id = "WRITE"
STRINGS.ACTIONS.WRITE = "Write"
 
-- Comprehensive Write Action Function
ACTIONS.WRITE.fn = function(act)
    local target = act.target
    local invobject = act.invobject
    local doer = act.doer
 
    if not doer or not doer:IsValid() then
        return false
    end
 
    -- Determine the writeable object (either target or inventory object)
    local writeableObj = target or invobject
   
    if not writeableObj or not writeableObj:IsValid() then
        return false
    end
 
    -- Check if object has writeable component and is not already written
    if writeableObj.components and
       writeableObj.components.writeable and
       not writeableObj.components.writeable:IsWritten() then
       
        -- Begin writing
        writeableObj.components.writeable:BeginWriting(doer)
        return true
    end
 
    return false
end
 
-- Action string function
ACTIONS.WRITE.strfn = function(act)
    return STRINGS.ACTIONS.WRITE
end
 
-- RPC Handlers for inventory and world interactions
local function OnUseItemFromInvTile(player, itemid)
    -- Get the actual item from the itemid
    local item = _G.Ents[itemid]
   
    if not item or not item:IsValid() then return end
 
    if item.components and
       item.components.writeable and
       not item.components.writeable:IsWritten() then
        local writeAction = BufferedAction(player, item, ACTIONS.WRITE)
        player:PushBufferedAction(writeAction)
    end
end
 
local function OnLeftClick(player, target)
    if not target or not target:IsValid() then return end
 
    if target.components and
       target.components.writeable and
       not target.components.writeable:IsWritten() then
        local writeAction = BufferedAction(player, target, ACTIONS.WRITE)
        player:PushBufferedAction(writeAction)
    end
end
 
-- Register RPC Handlers
AddModRPCHandler(MOD_RPC_NAMESPACE, "UseItemFromInvTile", OnUseItemFromInvTile)
AddModRPCHandler(MOD_RPC_NAMESPACE, "LeftClick", OnLeftClick)
 
-- Component Actions for Inventory and Scene
AddComponentAction("SCENE", "writeable", function(inst, doer, actions, right)
    if inst.components.writeable and
       not inst.components.writeable:IsWritten() then
        table.insert(actions, ACTIONS.WRITE)
    end
end)
 
AddComponentAction("INVENTORY", "writeable", function(inst, doer, actions, right)
    if inst.components.writeable and
       not inst.components.writeable:IsWritten() then
        table.insert(actions, ACTIONS.WRITE)
    end
end)
 
-- State Graph Modifications
AddStategraphActionHandler("wilson", ActionHandler(ACTIONS.WRITE, "domediumaction"))
AddStategraphActionHandler("wilson_client", ActionHandler(ACTIONS.WRITE, "domediumaction"))
 
-- Writeables layout
local writeables = require "writeables"
local SignGenerator = require "signgenerator"
 
writeables.AddLayout("written_papyrus", {
    prompt = STRINGS.SIGNS.MENU.PROMPT,
    animbank = "ui_board_5x3",
    animbuild = "ui_board_5x3",
    menuoffset = Vector3(6, -70, 0),
 
    cancelbtn = { text = STRINGS.SIGNS.MENU.CANCEL, cb = nil, control = CONTROL_CANCEL },
    middlebtn = { text = STRINGS.SIGNS.MENU.RANDOM, cb = function(inst, doer, widget)
            widget:OverrideText(SignGenerator(inst, doer))
        end, control = CONTROL_MENU_MISC_2 },
    acceptbtn = { text = STRINGS.SIGNS.MENU.ACCEPT, cb = nil, control = CONTROL_ACCEPT },
})

Maybe the problem is that I'm using the components for adding action, but in replica of writeable component there's simply no IsWritten() function, and even GetText()! So please, everyone, I will be really happy if one of you could help me.

Edited by Mr.CrazyPotato
brainrot

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...