• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

attempt to call global 'getDistanceToCreature' TRADER

Stanos

Veteran OT User
Joined
Jun 12, 2018
Messages
634
Solutions
7
Reaction score
372
Location
Europe
USING TFS1.2
Hello im trying to make working item trader so i'm using this trader from older tfs but probably my tfs dont have function like this so thats why im getting errors

Untitled.png

Can someone convert into TFS 1.2, so i could make other traders without any problems.
XML:
<npc name="Helmets Trader" script="helmets.lua" autowalk="25" floorchange="0" access="5" level="1" maglevel="1">
    <health now="150" max="150"/>
    <look type="453" head="132" body="79" legs="97" feet="132" corpse="2212"/>

</npc>
LUA:
local focus = 0
local talk_start = 0
local target = 0
local following = false
local attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
      if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
      end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
      return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
      msg = string.lower(msg)

      if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
          selfSay('Hello, ' .. getCreatureName(cid) .. '! I buy all helmets.')
          focus = cid
          talk_start = os.clock()

      elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
          selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk to you in a minute.')

    elseif focus == cid then
        talk_start = os.clock()

        if msgcontains(msg, 'sun glasses') then
            sell(cid,2461,1,200)

        elseif msgcontains(msg, 'eye mask') then
            sell(cid,2482,1,300)

        elseif msgcontains(msg, 'magic cap') then
            sell(cid,2481,1,500)

        elseif msgcontains(msg, 'hat') then
            sell(cid,2662,1,750)

       
        elseif msgcontains(msg, 'chibi gohan cap') then
            sell(cid,2343,1,10000)

       
        elseif msgcontains(msg, 'viking cap') then
            sell(cid,2663,1,1000)

        elseif msgcontains(msg, 'rr cap') then
            sell(cid,2665,1,1500)

        elseif msgcontains(msg, 'ninja helmet') then
            sell(cid,2459,1,2000)

        elseif msgcontains(msg, 'kuririn cap') then
            sell(cid,3972,1,3000)
       
        elseif msgcontains(msg, 'bandana') then
            sell(cid,2520,1,3000)

        elseif msgcontains(msg, 'red detector') then
            sell(cid,2457,1,2500)


        elseif msgcontains(msg, 'green detector') then
            sell(cid,2462,1,2500)

        elseif msgcontains(msg, 'soldier helmet') then
            sell(cid,2479,1,3000)

        elseif msgcontains(msg, 'pai pai helmet') then
            sell(cid,2480,1,5000)

       
        elseif msgcontains(msg, 'paul cap') then
            sell(cid,2474,1,7500)

        elseif msgcontains(msg, 'turban') then
            sell(cid,2502,1,10000)

       
        elseif msgcontains(msg, 'piccolo cap') then
            sell(cid,2475,1,30000)

        elseif msgcontains(msg, 'bardock bandana') then
            sell(cid,2471,1,50000)

        elseif msgcontains(msg, 'c19') then
            sell(cid,2436,1,50000)
       
        elseif msgcontains(msg, 'piccolo helmet') then
            sell(cid,2491,1,50000)

        elseif msgcontains(msg, 'frozen helmet') then
            sell(cid,2490,1,75000)
       
        elseif msgcontains(msg, 'brolly amulation') then
            sell(cid,2496,1,100000)
       
        elseif msgcontains(msg, 'great saiyan helmet') then
            sell(cid,2493,1,150000)
                       

        elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
            selfSay('Good bye, ' .. getCreatureName(cid) .. '!')
            focus = 0
            talk_start = 0
        end
    end
end

function onThink()
    doNpcSetCreatureFocus(focus)
      if (os.clock() - talk_start) > 45 then
          if focus > 0 then
              selfSay('Next Please...')
          end
              focus = 0
      end
    if focus ~= 0 then
        if getDistanceToCreature(focus) > 5 then
            selfSay('Good bye then.')
            focus = 0
        end
    end
end
 
Solution
Based on default Runes NPC:

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Helmets Trader" script="helmets.lua" walkinterval="25000" floorchange="0">
    <health now="100" max="100" />
    <look type="453" head="132" body="79" legs="97" feet="132" addons="1" />
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|! I buy all helmets." />
        <parameter key="message_decline" value="Is |TOTALCOST| gold coins too much for you? Get out of here!" />
    </parameters>
</npc>

helmets.lua
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid)...
Based on default Runes NPC:

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Helmets Trader" script="helmets.lua" walkinterval="25000" floorchange="0">
    <health now="100" max="100" />
    <look type="453" head="132" body="79" legs="97" feet="132" addons="1" />
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|! I buy all helmets." />
        <parameter key="message_decline" value="Is |TOTALCOST| gold coins too much for you? Get out of here!" />
    </parameters>
</npc>

helmets.lua
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'sun glasses'}, 2461, 200, 'sun glasses')
shopModule:addBuyableItem({'eye mask'}, 2482, 300, 'eye mask')
shopModule:addBuyableItem({'magic cap'}, 2481, 500, 'magic cap')
shopModule:addBuyableItem({'hat'}, 2662, 750, 'hat')
shopModule:addBuyableItem({'chibi gohan cap'}, 2343, 10000, 'chibi gohan cap')
shopModule:addBuyableItem({'viking cap'}, 2663, 1000, 'viking cap')
shopModule:addBuyableItem({'rr cap'}, 2665, 1500, 'rr cap')
shopModule:addBuyableItem({'ninja helmet'}, 2459, 2000, 'ninja helmet')
shopModule:addBuyableItem({'kuririn cap'}, 3972, 3000, 'kuririn cap')
shopModule:addBuyableItem({'bandana'}, 2520, 3000, 'bandana')
shopModule:addBuyableItem({'red detector'}, 2457, 2500, 'red detector')
shopModule:addBuyableItem({'green detector'}, 2462, 2500, 'green detector')
shopModule:addBuyableItem({'soldier helmet'}, 2479, 3000, 'soldier helmet')
shopModule:addBuyableItem({'pai pai helmet'}, 2480, 5000, 'pai pai helmet')
shopModule:addBuyableItem({'paul cap'}, 2474, 7500, 'paul cap')
shopModule:addBuyableItem({'turban'}, 2502, 10000, 'turban')
shopModule:addBuyableItem({'piccolo cap'}, 2475, 30000, 'piccolo cap')
shopModule:addBuyableItem({'bardock bandana'}, 2471, 50000, 'bardock bandana')
shopModule:addBuyableItem({'c19'}, 2436, 50000, 'c19')
shopModule:addBuyableItem({'piccolo helmet'}, 2491, 50000, 'piccolo helmet')
shopModule:addBuyableItem({'frozen helmet'}, 2490, 75000, 'frozen helmet')
shopModule:addBuyableItem({'brolly amulation'}, 2496, 100000, 'brolly amulation')
shopModule:addBuyableItem({'great saiyan helmet'}, 2493, 150000, 'great saiyan helmet')

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Why don't you just make npc for 1.2 instead of copying some old ass scripts...
Trade npc are the easiest you can do on 1.2.
otland/forgottenserver
It show default.lua but it locates to scripts folder.
Based on default Runes NPC:

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Helmets Trader" script="helmets.lua" walkinterval="25000" floorchange="0">
    <health now="100" max="100" />
    <look type="453" head="132" body="79" legs="97" feet="132" addons="1" />
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|! I buy all helmets." />
        <parameter key="message_decline" value="Is |TOTALCOST| gold coins too much for you? Get out of here!" />
    </parameters>
</npc>

helmets.lua
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'sun glasses'}, 2461, 200, 'sun glasses')
shopModule:addBuyableItem({'eye mask'}, 2482, 300, 'eye mask')
shopModule:addBuyableItem({'magic cap'}, 2481, 500, 'magic cap')
shopModule:addBuyableItem({'hat'}, 2662, 750, 'hat')
shopModule:addBuyableItem({'chibi gohan cap'}, 2343, 10000, 'chibi gohan cap')
shopModule:addBuyableItem({'viking cap'}, 2663, 1000, 'viking cap')
shopModule:addBuyableItem({'rr cap'}, 2665, 1500, 'rr cap')
shopModule:addBuyableItem({'ninja helmet'}, 2459, 2000, 'ninja helmet')
shopModule:addBuyableItem({'kuririn cap'}, 3972, 3000, 'kuririn cap')
shopModule:addBuyableItem({'bandana'}, 2520, 3000, 'bandana')
shopModule:addBuyableItem({'red detector'}, 2457, 2500, 'red detector')
shopModule:addBuyableItem({'green detector'}, 2462, 2500, 'green detector')
shopModule:addBuyableItem({'soldier helmet'}, 2479, 3000, 'soldier helmet')
shopModule:addBuyableItem({'pai pai helmet'}, 2480, 5000, 'pai pai helmet')
shopModule:addBuyableItem({'paul cap'}, 2474, 7500, 'paul cap')
shopModule:addBuyableItem({'turban'}, 2502, 10000, 'turban')
shopModule:addBuyableItem({'piccolo cap'}, 2475, 30000, 'piccolo cap')
shopModule:addBuyableItem({'bardock bandana'}, 2471, 50000, 'bardock bandana')
shopModule:addBuyableItem({'c19'}, 2436, 50000, 'c19')
shopModule:addBuyableItem({'piccolo helmet'}, 2491, 50000, 'piccolo helmet')
shopModule:addBuyableItem({'frozen helmet'}, 2490, 75000, 'frozen helmet')
shopModule:addBuyableItem({'brolly amulation'}, 2496, 100000, 'brolly amulation')
shopModule:addBuyableItem({'great saiyan helmet'}, 2493, 150000, 'great saiyan helmet')

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Thanks but this is buyable not sellable i think.
 
Back
Top