Jump to content

Recommended Posts

I'm not very good at English. I used GPT to help translate all of this.


I want to make it so that when I press the 'X' key, the character repI'm not very good at English. I used GPT to help translate all of this.orts its status, and when I press 'F10', the character resets its level.

modmain
modmain.lua

character
cac.lua

level system

caclucklevel.lua

modmain.lua
 

Spoiler
GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_F10, function()
    if GLOBAL.ThePlayer and GLOBAL.ThePlayer.prefab == "cac" then
        GLOBAL.ThePlayer:PushEvent("reset_status")
    end
end)
 
GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_X, function()
    print("on key x:>")
    if GLOBAL.ThePlayer and GLOBAL.ThePlayer.prefab == "cac" then
        GLOBAL.ThePlayer:PushEvent("show_status")
    end
end)

 

character prefabs
 

Spoiler
local function ShowStatus(inst)
    print("Status of character:>")
    inst.components.caclucklevel:CheckLevel()
end
 
local function ResetCac(inst)
    print("reset level:>")
    inst.components.caclucklevel:ResetLevel()
end

local master_postinit = function(inst)

-- -- กด f11 รีเซ็ตสถานะ
    inst:ListenForEvent("reset_status",  ResetCac)
 
    -- -- กด x ดูสถานะตัวละคร
    inst:ListenForEvent("show_status", ShowStatus)
end

 

อ่า เพิ่งเจอคนไทยบนฟอรั่มครั้งแรก... สวัสดีฮะ ยินดีต้อนรับ

ขอตัวม็อดเต็มๆ ได้มั้ยฮะ เดี๋ยวถ้าผมว่างอะ ผมจะลองดูว่าทำไมมันกดแล้วไม่มีอะไรเกิดขึ้น เพราะเอาจริงๆ ดูจากโค้ดเผินๆ แล้วมันไม่ควรมีอะไรผิดไป...

ถ้าไม่ว่าอะไร แอดดิสได้ครับ (แอด ilaskus น่าจะเจอ ไม่ก็ถ้าอยู่ใน Klei Discord ก็ @ ผมได้ ชื่อเดียวกัน)

  • Like 1

I've fixed it now, thank you Baguettes!

modmain.lua
 

Spoiler
local function OnF10Pressed(player, ...)
    if player and player.prefab == "cac" then
        player:PushEvent("reset_status")
    end
end
 
local function OnXPressed(player, ...)
    if player and player.prefab == "cac" then
        player:PushEvent("show_status")
    end
end
 
AddModRPCHandler("cacluckmod", "reset_status", OnF10Pressed)
AddModRPCHandler("cacluckmod", "show_status", OnXPressed)
 
GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_F10, function()
    SendModRPCToServer(GetModRPC("cacluckmod", "reset_status"))
end)
 
GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_X, function()
    SendModRPCToServer(GetModRPC("cacluckmod", "show_status"))
end)

 

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...