Để 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).
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.
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)
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)