vitorelias1
New Member
- Joined
- Sep 27, 2022
- Messages
- 27
- Reaction score
- 2
hi guys good nightI have this script but I don't know what's going on where I'm going wrongI will summarize the npc the player needs 1 crystal coin in exchange the npc adds a look to the item a serial.the script works removes the crystal coin but does not add the serial to the item
when the player looks at the item, it has to appear like this on the item
serialItem:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "This item has been registered by the player " .. player:getName() .. " in day " .. os.date("%d/%m/%Y - %X") .. " Serial: " .. serial .. ".")
when the player looks at the item, it has to appear like this on the item
serialItem:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "This item has been registered by the player " .. player:getName() .. " in day " .. os.date("%d/%m/%Y - %X") .. " Serial: " .. serial .. ".")
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid)
npcHandler:onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)
npcHandler:onCreatureSay(cid, type, msg)
end
function onThink()
npcHandler:onThink()
end
function onCreatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid) -- Get the Player Object
if msgcontains(msg, "serial") then
if player:getItemCount(2160) >= 1 then -- Check if the player has at least 1 Crystal Coin
selfSay("I can provide a serial record for one of your items. In exchange, I need 1 Crystal Coin. Do you have an item you want to register?", cid)
talkState[cid] = 1
else
selfSay("Sorry, but you need to have at least 1 Crystal Coin to use this service.", cid)
end
elseif talkState[cid] == 1 and (msgcontains(msg, "yes") or msgcontains(msg, "sim")) then
local serialItem = player:getItemById(ITEMID_WILDCARD, true) -- Search for an item in the Backpack or Set
if serialItem and serialItem:isItem() then
if player:removeItem(2160, 1) then -- Remove 1 Crystal Coin from the player
local serial = os.time() -- Generate time-based serial
serialItem:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "This item has been registered by the player " .. player:getName() .. " in day " .. os.date("%d/%m/%Y - %X") .. " Serial: " .. serial .. ".")
selfSay("Your item has been successfully registered. He now has the following serial: " .. serial .. ".", cid)
else
selfSay("Sorry, there was an error removing the Crystal Coin. Please try again.", cid)
end
else
selfSay("Sorry, but you don't have an item to register.", cid)
end
talkState[cid] = 0
else
selfSay("That's fine, come back when you're interested in registering an item.", cid)
talkState[cid] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onCreatureSayCallback)
npcHandler:addModule(FocusModule:new())