OTcreator
Well-Known Member
- Joined
- Feb 14, 2022
- Messages
- 483
- Solutions
- 1
- Reaction score
- 53
Hello!
I need re-write this code to TFS 1.4.2.
I found this code for TFS 1.X but on 1.4.2 not working.
I need re-write this code to TFS 1.4.2.
I found this code for TFS 1.X but on 1.4.2 not working.
LUA:
-- Collecting items missions by Limos
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
local missions = {
[1] = {items = {
{id = 2413, count = 1} -- broad sword
},
message = "Now bring me those",
level = 20,
rewardexp = 20000
},
[2] = {items = {
{id = 2430, count = 1} -- knight axe
},
message = "Thank you! Now bring me those",
level = 30,
rewardexp = 50000
},
[3] = {items = {
{id = 3961, count = 1} -- lich staff
},
message = "Awesome, bring me those",
level = 40,
rewardexp = 70000
},
[4] = {items = {
{id = 2438, count = 1} -- epee
},
message = "Thanks, now bring me those",
level = 60,
rewardexp = 90000
},
[5] = {items = {
{id = 7427, count = 1} -- chaos mace
},
message = "Awesome, now bring me those",
level = 80,
rewardexp = 150000
},
[6] = {items = {
{id = 2414, count = 1} -- dragon lance
},
message = "Extra, bring me those",
level = 100,
rewardexp = 200000
},
[7] = {items = {
{id = 2393, count = 1} -- giant sword
},
message = "Great, now bring me those",
level = 110,
rewardexp = 230000
},
[8] = {items = {
{id = 2454, count = 1} -- war axe
},
message = "Awesome! Bring me those",
level = 120,
rewardexp = 250000
},
[9] = {items = {
{id = 2452, count = 1} -- heavy mace
},
message = "Nice! This is last mission from me. I upgrade your weapons if you bring me ",
level = 150,
rewarditem = {id = 8717, count = 5},
rewardexp = 350000
}
}
local storage = 45552
local function getItemsFromTable(itemtable)
local text = ""
for v = 1, #itemtable do
count, info = itemtable[v].count, getItemInfo(itemtable[v].id)
local ret = ", "
if v == 1 then
ret = ""
elseif v == #itemtable then
ret = " and "
end
text = text .. ret
text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
end
return text
end
function creatureSayCallback(cid, type, msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if(msgcontains(msg, 'upgradable bags')) then
selfSay('Do you want to give me {50 demonic essence} for 1 upgradable bags?', cid)
talkState[talkUser] = 10
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 10) then
if getPlayerStorageValue(cid,storage) >= 9 then
if(getPlayerItemCount(cid, 6500) >= 50) then
if(doPlayerRemoveItem(cid, 6500, 50)) then
doPlayerAddItem(cid, 8717, 1)
selfSay('Here you are. Good luck in upgrade!', cid)
else
selfSay('Sorry, you don\'t have done weapons mission.', cid)
end
else
selfSay('Sorry, you don\'t have {50 demonic essence} to exchange.', cid)
end
else
selfSay('Sorry, you don\'t have done {weapons missions}.', cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local xstorage = getPlayerStorageValue(cid, storage)
local x = missions[xstorage]
if not npcHandler:isFocused(cid) then
return false
end
if msgcontains(msg, 'help') then
if xstorage == -1 then
selfSay("I need a lot of weapons to upgrade. Can you help me? If you done all mission I upgrade your weapons. Say {yes}!", cid)
talkState[talkUser] = 1
elseif x then
if getPlayerLevel(cid) >= x.level then
selfSay("You are bring me this {weapons}? Great! talk to me {yes}.", cid)
talkState[talkUser] = 1
else
selfSay("You don't have "..x.level.." level, come back later.", cid)
end
else
selfSay("Thanks, but you already give me all weapons.", cid)
npcHandler:releaseFocus(cid)
end
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
if xstorage == -1 then
setPlayerStorageValue(cid, storage, 1)
local x = missions[getPlayerStorageValue(cid, storage)]
selfSay(x.message.." {"..getItemsFromTable(x.items).."}.", cid)
elseif x then
local amount = 0
for i = 1, #x.items do
if getPlayerItemCount(cid, x.items[i].id) >= x.items[i].count then
amount = amount + 1
end
end
if amount == #x.items then
for i = 1, #x.items do
doPlayerRemoveItem(cid, x.items[i].id, x.items[i].count)
end
if x.rewarditem then
local count, info = x.rewarditem.count, getItemInfo(x.rewarditem.id)
doPlayerAddItem(cid, x.rewarditem.id, count)
selfSay("You received {"..(count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name).."}.",cid)
end
if x.rewardexp then
doPlayerAddExp(cid, x.rewardexp)
selfSay("You received {"..x.rewardexp.." experience}.",cid)
end
setPlayerStorageValue(cid, storage, xstorage + 1)
local x = missions[getPlayerStorageValue(cid, storage)]
if x then
selfSay(x.message.." {"..getItemsFromTable(x.items).."}.", cid)
else
selfSay("Thanks alot! I can finish upgrade! Take 3 upgradable bags. Use on your weapons.", cid)
end
else
local n = 0
for i = 1, #x.items do
if getPlayerItemCount(cid, x.items[i].id) < x.items[i].count then
n = n + 1
end
end
local text = ""
local c = 0
for v = 1, #x.items do
count, info = x.items[v].count - getPlayerItemCount(cid, x.items[v].id), getItemInfo(x.items[v].id)
if getPlayerItemCount(cid, x.items[v].id) < x.items[v].count then
c = c + 1
local ret = ", "
if c == 1 then
ret = ""
elseif c == n then
ret = " and "
end
text = text .. ret
text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
end
end
selfSay("You don't have all items, you still need to get {"..text.."}.", cid)
end
end
talkState[talkUser] = 0
elseif msgcontains(msg, 'weapons') and x then
selfSay("Now I need this weapons: {"..getItemsFromTable(x.items).."}.", cid)
elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
selfSay("Oh well...", cid)
end
return true
end
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Come back, help me.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())