Kuzyn
Excellent OT User
Hey. I'm using TFS 1.2 (official distro) on client 10.77 and I tried to add few scripts from ORTS. Unfortunately I've got some bugs:
First (spawning Horestis)
How can I run this script? I checked original map and those jars had these storages in action id field. I did the same but still not loading.
Second (set description)
Script for making statue of out a clay doesn't have description and I've got error in console about setting description:
Third (enchanting)
I can't enchant anything:
Fourth (NPC bug)
I can't spawn him (I've cut few dialog options because of post length):
First (spawning Horestis)
How can I run this script? I checked original map and those jars had these storages in action id field. I did the same but still not loading.
Code:
local config = {
jarPositions = {
Position(3722, 2244, 7),
Position(3725, 2244, 7),
Position(3725, 2247, 7),
Position(3725, 2251, 7),
Position(3722, 2251, 7)
},
time = 3600,
brokenJarId = 13495,
chance = 5,
randomText = {'Waaaaaah', 'You are too afraid to destroy this object'},
bossName = 'Horestis',
bossPosition = Position(3722, 2248, 7),
storages = {
[30003] = Storage.HorestisTomb.JarFloor1,
[30004] = Storage.HorestisTomb.JarFloor2,
[30005] = Storage.HorestisTomb.JarFloor3,
[30006] = Storage.HorestisTomb.JarFloor4,
[30007] = Storage.HorestisTomb.JarFloor5
}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.itemid ~= 13500 then
player:say('This jar is already broken!', TALKTYPE_MONSTER_SAY)
return true
end
local cStorage = config.storages[item.actionid]
if player:getStorageValue(cStorage) > os.time() then
player:say('You are too afraid to destroy this object', TALKTYPE_MONSTER_SAY)
return true
end
player:setStorageValue(cStorage, os.time() + config.time)
if math.random(100) > config.chance then
player:say(config.randomText[math.random(#config.randomText)], TALKTYPE_MONSTER_SAY)
return true
end
item:transform(config.brokenJarId)
local jarsBroken, jarItem = true
for i = 1, #config.jarPositions do
jarItem = Tile(config.jarPositions[i]):getItemById(config.brokenJarId)
if not jarItem then
jarsBroken = false
break
end
end
if not jarsBroken then
return true
end
Game.createMonster(config.bossName, config.bossPosition)
return true
end
Second (set description)
Script for making statue of out a clay doesn't have description and I've got error in console about setting description:
Code:
local config = {
{chance = {0.0, 1.1}, transformId = 11342, description = 'This little figurine of Brog, the raging Titan, was skillfully made by |PLAYERNAME|.', achievement = true},
{chance = {1.1, 10.52}, transformId = 11341, description = 'It was made by |PLAYERNAME| and is clearly a little figurine of.. hm, one does not recognise that yet.'},
{chance = {10.52, 35.38}, transformId = 11340, description = 'It was made by |PLAYERNAME|, whose potter skills could use some serious improvement.'},
{chance = {35.38, 100.0}, remove = true, sound = 'Aw man. That did not work out too well.'}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local random, tmpItem = math.random(0, 10000) * 0.01
for i = 1, #config do
tmpItem = config[i]
if random >= tmpItem.chance[1] and random < tmpItem.chance[2] then
item:getPosition():sendMagicEffect(CONST_ME_POFF)
if tmpItem.remove then
item:remove()
else
item:transform(tmpItem.transformId)
end
if tmpItem.sound then
player:say(tmpItem.sound, TALKTYPE_MONSTER_SAY, false, player)
end
if tmpItem.description then
item:setDescription(tmpItem.description:gsub('|PLAYERNAME|', player:getName()))
end
if tmpItem.achievement then
player:addAchievement('Clay Fighter')
player:addAchievementProgress('Clay to Fame', 5)
end
break
end
end
return true
end
Third (enchanting)
I can't enchant anything:
Code:
local config = {
manaCost = 300,
soulCost = 2,
}
local spheres = {
[7759] = {3, 7},
[7760] = {1, 5},
[7761] = {2, 6},
[7762] = {4, 8}
}
local enchantableGems = {2147, 2146, 2149, 2150}
local enchantableItems = {2383, 7383, 7384, 7406, 7402, 2429, 2430, 7389, 7380, 2454, 2423, 2445, 7415, 7392, 2391, 2544, 8905}
local enchantingAltars = {
{7504, 7505, 7506, 7507},
{7508, 7509, 7510, 7511},
{7516, 7517, 7518, 7519},
{7512, 7513, 7514, 7515}
}
local enchantedGems = {7760, 7759, 7761, 7762}
local enchantedItems = {
[2383] = {7744, 7763, 7854, 7869},
[7383] = {7745, 7764, 7855, 7870},
[7384] = {7746, 7765, 7856, 7871},
[7406] = {7747, 7766, 7857, 7872},
[7402] = {7748, 7767, 7858, 7873},
[2429] = {7749, 7768, 7859, 7874},
[2430] = {7750, 7769, 7860, 7875},
[7389] = {7751, 7770, 7861, 7876},
[7380] = {7752, 7771, 7862, 7877},
[2454] = {7753, 7772, 7863, 7878},
[2423] = {7754, 7773, 7864, 7879},
[2445] = {7755, 7774, 7865, 7880},
[7415] = {7756, 7775, 7866, 7881},
[7392] = {7757, 7776, 7867, 7882},
[2391] = {7758, 7777, 7868, 7883},
[2544] = {7840, 7839, 7850, 7838},
[8905] = {8906, 8907, 8909, 8908}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if isInArray({33268, 33269}, toPosition.x) and toPosition.y == 31830 and toPosition.z == 10 and player:getStorageValue(Storage.ElementalSphere.QuestLine) > 0 then
if not isInArray(spheres[item.itemid], player:getVocation():getId()) then
return false
elseif isInArray({7915, 7916}, target.itemid) then
player:say('Turn off the machine first.', TALKTYPE_MONSTER_SAY)
return true
else
player:setStorageValue(Storage.ElementalSphere.MachineGemCount, math.max(1, player:getStorageValue(Storage.ElementalSphere.MachineGemCount) + 1))
toPosition:sendMagicEffect(CONST_ME_PURPLEENERGY)
item:transform(item.itemid, item.type - 1)
return true
end
end
if item.itemid == 2147 and target.itemid == 2342 then
target:transform(2343)
target:decay()
item:remove(1)
toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
return true
end
if item.itemid == 7760 and isInArray({9934, 10022}, target.itemid) then
target:transform(9933)
item:remove(1)
toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
return true
end
if isInArray(enchantableGems, item.itemid) then
local subtype = item.type
if subtype == 0 then
subtype = 1
end
local mana = config.manaCost * subtype
if player:getMana() < mana then
player:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
return false
end
local soul = config.soulCost * subtype
if player:getSoul() < soul then
player:sendCancelMessage(RETURNVALUE_NOTENOUGHSOUL)
return false
end
local targetId = table.find(enchantableGems, item.itemid)
if not targetId or not isInArray(enchantingAltars[targetId], target.itemid) then
return false
end
player:addMana(-mana)
player:addSoul(-soul)
item:transform(enchantedGems[targetId])
player:addManaSpent(mana * configManager.getNumber(configKeys.RATE_MAGIC))
player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE)
return true
end
if item.itemid == 7761 and isInArray({9949, 9954}, target.itemid) then
target:transform(target.itemid - 1)
target:decay()
item:remove(1)
toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
return true
end
if isInArray(enchantedGems, item.itemid) then
if not isInArray(enchantableItems, target.itemid) then
fromPosition:sendMagicEffect(CONST_ME_POFF)
return false
end
local targetId = table.find(enchantedGems, item.itemid)
if not targetId then
return false
end
local subtype = target.type
if not isInArray({2544, 8905}, target.itemid) then
subtype = 1000
end
target:transform(enchantedItems[target.itemid][targetId], subtype)
target:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
item:remove(1)
return true
end
return false
end
Fourth (NPC bug)
I can't spawn him (I've cut few dialog options because of post length):
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local count = {}
local transfer = {}
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 voices = { {text = 'Our bank service is the best way to protect your savings! Visit Goldstein Brothers Bank!'} }
npcHandler:addModule(VoiceModule:new(voices))
local function greetCallback(cid)
count[cid], transfer[cid] = nil, nil
return true
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
---------------------------- help ------------------------
if msgcontains(msg, 'bank account') then
npcHandler:say({
'Every human has one. The big advantage is that you can access your money in every branch of the Goldstein Brothers Bank! ...',
'Would you like to know more about the {basic} functions of your bank account, the {advanced} functions, or are you already bored, perhaps?'
}, cid)
npcHandler.topic[cid] = 0
return true
---------------------------- balance ---------------------
elseif msgcontains(msg, 'balance') then
npcHandler.topic[cid] = 0
if player:getBankBalance() >= 100000000 then
npcHandler:say('I think you must be one of the richest inhabitants in the world! Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
return true
elseif player:getBankBalance() >= 10000000 then
npcHandler:say('You have made ten millions and it still grows! Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
return true
elseif player:getBankBalance() >= 1000000 then
npcHandler:say('Wow, you have reached the magic number of a million gp!!! Your account balance is ' .. player:getBankBalance() .. ' gold!', cid)
return true
elseif player:getBankBalance() >= 100000 then
npcHandler:say('You certainly have made a pretty penny. Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
return true
else
npcHandler:say('Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
return true
end
---------------------------- deposit ---------------------
elseif msgcontains(msg, 'deposit') then
count[cid] = player:getMoney()
if count[cid] < 1 then
npcHandler:say('You do not have enough gold.', cid)
npcHandler.topic[cid] = 0
return false
end
if msgcontains(msg, 'all') then
count[cid] = player:getMoney()
npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
npcHandler.topic[cid] = 2
return true
else
if string.match(msg,'%d+') then
count[cid] = getMoneyCount(msg)
if count[cid] < 1 then
npcHandler:say('You do not have enough gold.', cid)
npcHandler.topic[cid] = 0
return false
end
npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
npcHandler.topic[cid] = 2
return true
else
npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
npcHandler.topic[cid] = 1
return true
end
end
if not isValidMoney(count[cid]) then
npcHandler:say('Sorry, but you can\'t deposit that much.', cid)
npcHandler.topic[cid] = 0
return false
end
elseif npcHandler.topic[cid] == 1 then
count[cid] = getMoneyCount(msg)
if isValidMoney(count[cid]) then
npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
npcHandler.topic[cid] = 2
return true
else
npcHandler:say('You do not have enough gold.', cid)
npcHandler.topic[cid] = 0
return true
end
elseif npcHandler.topic[cid] == 2 then
if msgcontains(msg, 'yes') then
if player:getMoney() >= tonumber(count[cid]) then
player:depositMoney(count[cid])
npcHandler:say('Alright, we have added the amount of ' .. count[cid] .. ' gold to your {balance}. You can {withdraw} your money anytime you want to.', cid)
else
npcHandler:say('You do not have enough gold.', cid)
end
elseif msgcontains(msg, 'no') then
npcHandler:say('As you wish. Is there something else I can do for you?', cid)
end
npcHandler.topic[cid] = 0
return true
---------------------------- withdraw --------------------
elseif msgcontains(msg, 'withdraw') then
if string.match(msg,'%d+') then
count[cid] = getMoneyCount(msg)
if isValidMoney(count[cid]) then
npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
npcHandler.topic[cid] = 7
else
npcHandler:say('There is not enough gold on your account.', cid)
npcHandler.topic[cid] = 0
end
return true
else
npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
npcHandler.topic[cid] = 6
return true
end
elseif npcHandler.topic[cid] == 6 then
count[cid] = getMoneyCount(msg)
if isValidMoney(count[cid]) then
npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
npcHandler.topic[cid] = 7
else
npcHandler:say('There is not enough gold on your account.', cid)
npcHandler.topic[cid] = 0
end
return true
elseif npcHandler.topic[cid] == 7 then
if msgcontains(msg, 'yes') then
if player:getFreeCapacity() >= getMoneyWeight(count[cid]) then
if not player:withdrawMoney(count[cid]) then
npcHandler:say('There is not enough gold on your account.', cid)
else
npcHandler:say('Here you are, ' .. count[cid] .. ' gold. Please let me know if there is something else I can do for you.', cid)
end
else
npcHandler:say('Whoah, hold on, you have no room in your inventory to carry all those coins. I don\'t want you to drop it on the floor, maybe come back with a cart!', cid)
end
npcHandler.topic[cid] = 0
elseif msgcontains(msg, 'no') then
npcHandler:say('The customer is king! Come back anytime you want to if you wish to {withdraw} your money.', cid)
npcHandler.topic[cid] = 0
end
return true
---------------------------- transfer --------------------
elseif msgcontains(msg, 'transfer') then
npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
npcHandler.topic[cid] = 11
elseif npcHandler.topic[cid] == 11 then
count[cid] = getMoneyCount(msg)
if player:getBankBalance() < count[cid] then
npcHandler:say('There is not enough gold on your account.', cid)
npcHandler.topic[cid] = 0
return true
end
if isValidMoney(count[cid]) then
npcHandler:say('Who would you like transfer ' .. count[cid] .. ' gold to?', cid)
npcHandler.topic[cid] = 12
else
npcHandler:say('There is not enough gold on your account.', cid)
npcHandler.topic[cid] = 0
end
elseif npcHandler.topic[cid] == 12 then
transfer[cid] = msg
if player:getName() == transfer[cid] then
npcHandler:say('Fill in this field with person who receives your gold!', cid)
npcHandler.topic[cid] = 0
return true
end
if playerExists(transfer[cid]) then
npcHandler:say('So you would like to transfer ' .. count[cid] .. ' gold to ' .. transfer[cid] .. '?', cid)
npcHandler.topic[cid] = 13
else
npcHandler:say('This player does not exist.', cid)
npcHandler.topic[cid] = 0
end
elseif npcHandler.topic[cid] == 13 then
if msgcontains(msg, 'yes') then
if not player:transferMoneyTo(transfer[cid], count[cid]) then
npcHandler:say('You cannot transfer money to this account.', cid)
else
npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. transfer[cid] ..'.', cid)
transfer[cid] = nil
end
elseif msgcontains(msg, 'no') then
npcHandler:say('Alright, is there something else I can do for you?', cid)
end
npcHandler.topic[cid] = 0
---------------------------- money exchange --------------
elseif msgcontains(msg, 'change gold') then
npcHandler:say('How many platinum coins would you like to get?', cid)
npcHandler.topic[cid] = 14
elseif npcHandler.topic[cid] == 14 then
if getMoneyCount(msg) < 1 then
npcHandler:say('Sorry, you do not have enough gold coins.', cid)
npcHandler.topic[cid] = 0
else
count[cid] = getMoneyCount(msg)
npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your gold coins into ' .. count[cid] .. ' platinum coins?', cid)
npcHandler.topic[cid] = 15
end
elseif npcHandler.topic[cid] == 15 then
if msgcontains(msg, 'yes') then
if player:removeItem(2148, count[cid] * 100) then
player:addItem(2152, count[cid])
npcHandler:say('Here you are.', cid)
else
npcHandler:say('Sorry, you do not have enough gold coins.', cid)
end
else
npcHandler:say('Well, can I help you with something else?', cid)
end
npcHandler.topic[cid] = 0
elseif msgcontains(msg, 'change platinum') then
npcHandler:say('Would you like to change your platinum coins into gold or crystal?', cid)
npcHandler.topic[cid] = 16
elseif npcHandler.topic[cid] == 16 then
if msgcontains(msg, 'gold') then
npcHandler:say('How many platinum coins would you like to change into gold?', cid)
npcHandler.topic[cid] = 17
elseif msgcontains(msg, 'crystal') then
npcHandler:say('How many crystal coins would you like to get?', cid)
npcHandler.topic[cid] = 19
else
npcHandler:say('Well, can I help you with something else?', cid)
npcHandler.topic[cid] = 0
end
elseif npcHandler.topic[cid] == 17 then
if getMoneyCount(msg) < 1 then
npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
npcHandler.topic[cid] = 0
else
count[cid] = getMoneyCount(msg)
npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your platinum coins into ' .. count[cid] * 100 .. ' gold coins for you?', cid)
npcHandler.topic[cid] = 18
end
elseif npcHandler.topic[cid] == 18 then
if msgcontains(msg, 'yes') then
if player:removeItem(2152, count[cid]) then
player:addItem(2148, count[cid] * 100)
npcHandler:say('Here you are.', cid)
else
npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
end
else
npcHandler:say('Well, can I help you with something else?', cid)
end
npcHandler.topic[cid] = 0
elseif npcHandler.topic[cid] == 19 then
if getMoneyCount(msg) < 1 then
npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
npcHandler.topic[cid] = 0
else
count[cid] = getMoneyCount(msg)
npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your platinum coins into ' .. count[cid] .. ' crystal coins for you?', cid)
npcHandler.topic[cid] = 20
end
elseif npcHandler.topic[cid] == 20 then
if msgcontains(msg, 'yes') then
if player:removeItem(2152, count[cid] * 100) then
player:addItem(2160, count[cid])
npcHandler:say('Here you are.', cid)
else
npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
end
else
npcHandler:say('Well, can I help you with something else?', cid)
end
npcHandler.topic[cid] = 0
elseif msgcontains(msg, 'change crystal') then
npcHandler:say('How many crystal coins would you like to change into platinum?', cid)
npcHandler.topic[cid] = 21
elseif npcHandler.topic[cid] == 21 then
if getMoneyCount(msg) < 1 then
npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
npcHandler.topic[cid] = 0
else
count[cid] = getMoneyCount(msg)
npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your crystal coins into ' .. count[cid] * 100 .. ' platinum coins for you?', cid)
npcHandler.topic[cid] = 22
end
elseif npcHandler.topic[cid] == 22 then
if msgcontains(msg, 'yes') then
if player:removeItem(2160, count[cid]) then
player:addItem(2152, count[cid] * 100)
npcHandler:say('Here you are.', cid)
else
npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
end
else
npcHandler:say('Well, can I help you with something else?', cid)
end
npcHandler.topic[cid] = 0
end
return true
end
keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, text = 'You can check the {balance} of your bank account, {deposit} money or {withdraw} it. You can also {transfer} money to other characters, provided that they have a vocation.'})
keywordHandler:addKeyword({'functions'}, StdModule.say, {npcHandler = npcHandler, text = 'You can check the {balance} of your bank account, {deposit} money or {withdraw} it. You can also {transfer} money to other characters, provided that they have a vocation.'})
keywordHandler:addKeyword({'basic'}, StdModule.say, {npcHandler = npcHandler, text = 'You can check the {balance} of your bank account, {deposit} money or {withdraw} it. You can also {transfer} money to other characters, provided that they have a vocation.'})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, text = 'I work in this bank. I can change money for you and help you with your bank account.'})
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, text = "My name is Naji. My mother gave me that name because she knew a Paladin with that name. I'm a spare timer hunter by myself, you know! I want to join the {Paw and Fur - hunting elite}!"})
keywordHandler:addKeyword({'paw and fur'}, StdModule.say, {npcHandler = npcHandler, text = "The Paw and Fur - Hunting Elite is a newly founded hunting society in Port Hope. It is said that they send you on hunting mission. Sounds great if you ask me."})
npcHandler:setMessage(MESSAGE_GREET, 'Welcome to the Tibian {bank}, |PLAYERNAME|! What can I do for you?')
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())