Công cụ thành viên

Công cụ trang web


developer_center:developer_editor:script:popdevshop

Cách hiển thị tin nhắn khi người chơi mua vật phẩm trong DevShop

Để hiện tin nhắn khi người chơi mua thứ gì đó trong cửa hàng developer (DevShop), ta dùng sự kiện Developer.BuyItem và đặt nó vào trong một hàm xử lý.

Sự kiện này trả về:

eventobjid: ID của người chơi thực hiện hành động mua.
itemid: ID của vật phẩm trong cửa hàng dev (khác với itemid của vật phẩm bình thường).

📜 Ví dụ: Gửi tin nhắn cảm ơn khi mua hàng

ScriptSupportEvent:registerEvent([=[Developer.BuyItem]=], function(e) 
 
    local playerid = e['eventobjid']
    local itembought = e['itemid']
 
    Chat:sendSystemMsg("#B Cảm ơn bạn đã mua hàng! :)", playerid)
 
end)
#B là mã màu để hiển thị chữ màu xanh dương, thay vì màu cam mặc định.

👤 Thêm tên người chơi vào tin nhắn

Nếu muốn chèn tên người chơi vào tin nhắn, ta dùng hàm Player:getNickname() để lấy tên. Hàm này trả về:

ErrorCode
nickname của người chơi
ScriptSupportEvent:registerEvent([=[Developer.BuyItem]=], function(e) 
 
    local playerid = e['eventobjid']
    local itembought = e['itemid']
 
    local _, playernick = Player:getNickname(playerid)
    Chat:sendSystemMsg("#B Cảm ơn bạn đã mua hàng, " .. playernick, playerid)   
 
end)

🧩 Tạo tin nhắn riêng cho từng vật phẩm

Bạn có thể tạo tin nhắn tùy biến cho từng vật phẩm dựa theo itemid của vật phẩm trong cửa hàng dev:

ScriptSupportEvent:registerEvent([=[Developer.BuyItem]=], function(e) 
 
    local playerid = e['eventobjid']
    local itembought = e['itemid']
 
    local _, playernick = Player:getNickname(playerid)
 
    if itembought == 4098 then
        Chat:sendSystemMsg("#B Cảm ơn bạn đã mua hàng, " .. playernick, playerid)
    end
 
    if itembought == 4097 then 
        Chat:sendSystemMsg("#B Cảm ơn bạn đã ủng hộ, " .. playernick, playerid) 
    end
 
end)

developer_center/developer_editor/script/popdevshop.txt · Sửa đổi lần cuối: 2025/05/10 15:34 bởi leo