OTcreator
Well-Known Member
- Joined
- Feb 14, 2022
- Messages
- 503
- Solutions
- 1
- Reaction score
- 57
Hi,
I tried to write a script where we will have to give a random amount of items to an NPC from a table.
In return, we will also receive random rewards.
But something doesn't work for me here, it doesn't work. Error in the console regarding the table.
I have never worked on such tables hence I assisted with GPT.
In the next steps, I was to add rewards and the possibility of cancelling a given task and a new one could be started only after an hour.
Code for TFS 1.4.
I tried to write a script where we will have to give a random amount of items to an NPC from a table.
In return, we will also receive random rewards.
But something doesn't work for me here, it doesn't work. Error in the console regarding the table.
I have never worked on such tables hence I assisted with GPT.
In the next steps, I was to add rewards and the possibility of cancelling a given task and a new one could be started only after an hour.
Code for TFS 1.4.
LUA:
local missions = {
{itemId = 2160, count = math.random(1, 10)},
{itemId = 2152, count = math.random(1, 10)},
{itemId = 2148, count = math.random(1, 10)},
{itemId = 7590, count = math.random(1, 10)},
{itemId = 7412, count = math.random(1, 10)},
}
local currentMission = nil
function onCreatureSay(cid, type, msg)
if msg:lower() == "mission" then
if currentMission == nil or getPlayerStorageValue(cid, 10000) >= 1 then
currentMission = missions[math.random(#missions)]
setPlayerStorageValue(cid, 10000, 0)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Mission: Bring me " .. currentMission.count .. "x " .. getItemName(currentMission.itemId) .. ".")
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You have already mission. Bring me " .. currentMission.count .. "x " .. getItemName(currentMission.itemId) .. ".")
end
end
if msg:lower() == "done" then
if currentMission and getPlayerItemCount(cid, currentMission.itemId) >= currentMission.count then
doPlayerRemoveItem(cid, currentMission.itemId, currentMission.count)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Thank you! Already have " .. currentMission.count .. "x " .. getItemName(currentMission.itemId) .. "!")
setPlayerStorageValue(cid, 10000, 1)
currentMission = nil
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You don't have items.")
end
end
end
local npcHandler = NpcHandler:new()
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onCreatureSay)
npcHandler:setCallback(CALLBACK_ONCHANGEOUTFIT, onCreatureChangeOutfit)
npcHandler:addModule(FocusModule:new())