• 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!

Solved Help with this function

samuelsami

New Member
Joined
Oct 27, 2010
Messages
77
Reaction score
1
Code:
   local myPos = getCreaturePosition(getNpcCid())
   local nPos = {X = 936, Y = 1028, Z = 12}
     if (owner == 0) then
     doTeleportThing(getNpcCid(), nPos)
return
   end

Well, help with this function.
What does it? (the full script is a npc that is like a pet, works with a 'owner' system) so, when the owner disappear (logout) the npc (pet) should be teleported to the nPos, but it doesn't work.
There's not error on console.
should works like this function:
Code:
function onThink()
   if (owner == 0) then
     findOwner()
     return
   end
 
I don't get it, is it supposed to teleport to a certin position(that you indexed - npos) or is it supposed to teleport to the players position?
Can you send us the full script? What does owner mean? And you can remove myPos if its not used in any other part of the script.
 
Ok, there is, it's supposed that when owner logs out, npc (pet) gets teleported to a certain position (nPos)

Code:
-- Load spell area's data.
dofile(getDataDir() .. "spells/lib/spells.lua")

-- Basic Config
local basic = {
    ownerName = "Meeow" -- Your character name.
}

-- Healer Config
local healer = {
    enabled = TRUE,
    sayWord = TRUE,
    healthToHeal = 4000,
    min = 700,
    max = 1200
}
-- Mana Restore Config
local manaRestore = {
    enabled = TRUE,
    manaToRestore = 800,
    min = 150,
    max = 300
}
-- Rune Config
local rune = {
    enabled = TRUE,
    lastShoot = os.clock(), -- Don't touch!
    delay = 1,
    effect = CONST_ME_MORTAREA,
    shootEffect = CONST_ANI_SUDDENDEATH,
    combat = COMBAT_DEATHDAMAGE,
    min = 750,
    max = 1100
}
-- Spell Config
local spell = {
    enabled = TRUE,
    sayWord = TRUE,
    lastCast = os.clock(), -- Don't touch!
    delay = 3,
    combat = COMBAT_ICEDAMAGE,
    area = createCombatArea(AREA_CROSS5X5),
    word = "Exevo Gran Mas Frigo",
    effect = CONST_ME_ICETORNADO,
    min = 700,
    max = 1000
}
-- Anty Paralyze
local antyPara = {
    enabled = TRUE
}

-- Don't touch below!
local owner = 0
local target = FALSE

local function findOwner()
    local list = getSpectators(getNpcPos(), 9, 9, false)
    if (#list > 0) then
        for i = 1, #list do
            local _target = list[i]
            if (_target ~= 0) then
                if (getCreatureName(_target) == basic.ownerName) then
                    selfSay("Hi ".. basic.ownerName .."!")
                    selfFollow(_target)
                    owner = _target
                end
            end
        end
    end
end

local function doHealOwner()
    if (getCreatureHealth(owner) < healer.healthToHeal) then
        if (healer.sayWord) then
            doCreatureSay(getNpcCid(), "Exura Sio \"".. basic.ownerName, TALKTYPE_ORANGE_1)
        end
        doCreatureAddHealth(owner, math.random(healer.min, healer.max))
        doSendMagicEffect(getCreaturePosition(getNpcCid()), CONST_ME_MAGIC_BLUE)
        doSendMagicEffect(getCreaturePosition(owner), CONST_ME_MAGIC_GREEN)
    end
end

local function doRestoreMana()
    if (getPlayerMana(owner) < manaRestore.manaToRestore) then
        doPlayerAddMana(owner, math.random(manaRestore.min, manaRestore.max))
        doSendMagicEffect(getCreaturePosition(owner), CONST_ME_MAGIC_BLUE)
    end
end

local function doUseRune()
    target = FALSE
    local shooted = FALSE
    local r_list = getSpectators(getNpcPos(), 9, 9, false)
    if (#r_list > 0) then
        for i = 1, #r_list do
            local r_target = r_list[i]
            if (isPlayer(r_target) == FALSE and isNpc(r_target) == FALSE and getNpcCid() ~= r_target and shooted == FALSE) then
                local tPos = getCreaturePosition(r_target)
                doSendMagicEffect(tPos, rune.effect)
                doSendDistanceShoot(getCreaturePosition(getNpcCid()), tPos, rune.shootEffect)
                doTargetCombatHealth(getNpcCid(), r_target, rune.combat, -rune.min, -rune.max, rune.effect)
                shooted = TRUE
                target = TRUE
            end
        end
    end
end

local function doCastSpell()
    if (spell.sayWord) then
        doCreatureSay(getNpcCid(), spell.word, TALKTYPE_ORANGE_1)
    end

    doAreaCombatHealth(getNpcCid(), spell.combat, getCreaturePosition(getNpcCid()), spell.area, -spell.min, -spell.max, spell.effect)
end

local function doRemovePara()
    if (hasCondition(owner, CONDITION_PARALYZE)) then
        doRemoveCondition(owner, CONDITION_PARALYZE)
        doSendMagicEffect(getCreaturePosition(owner), CONST_ME_MAGIC_GREEN)
    end
end

function onCreatureDisappear(cid)
    if (cid == owner) then
        owner = 0
    end
end

function onCreatureSay(cid, type, msg)
    if (cid == owner) then
        if  (msg == "disappear") then
            selfSay("Good bye ;)")
            doHealOwner()
            doRestoreMana()
            doRemoveCreature(getNpcCid())
        elseif (msg == "kick") then
            doRemoveCreature(cid)
        end
    end
end

function onThink()
    -- Try to find owner, if he's not already found.
    if (owner == 0) then
        findOwner()
        return
    end

    -- Update following
    selfFollow(owner)

    -- On floor change ;)
    local myPos = getCreaturePosition(getNpcCid())
    local ownerPos = getCreaturePosition(owner)
    if (myPos.z ~= ownerPos.z) then
        doSendMagicEffect(myPos, CONST_ME_POFF)
        doTeleportThing(getNpcCid(), ownerPos)
        doSendMagicEffect(ownerPos, CONST_ME_TELEPORT)
    end

    -- Healer
    if (healer.enabled) then
        doHealOwner()
    end

    -- Mana Restore
    if (manaRestore.enabled) then
        doRestoreMana()
    end

    -- Shoot Rune
    if (rune.enabled and rune.lastShoot < os.clock()) then
        rune.lastShoot = (os.clock()+rune.delay)
        doUseRune()
    end

    -- Cast Spell
    if (spell.enabled and target ~= FALSE and spell.lastCast < os.clock()) then
        spell.lastCast = (os.clock()+spell.delay)
        doCastSpell()
    end

    -- Anty Paralyze
    if (antyPara.enabled) then
        doRemovePara()
    end
end
 
case sensitive:
Code:
local nPos = {X = 936, Y = 1028, Z = 12}
to:
Code:
local nPos = {x = 936, y = 1028, z = 12}
 
isn't working yet, please check it again in full script
Code:
local myPos = getCreaturePosition(getNpcCid())
local nPos = {x = 936, y = 1028, z = 12}
if (owner == 0) then
doTeleportThing(getNpcCid(), nPos)
return
end

Code:
-- Load spell area's data.
dofile(getDataDir() .. "spells/lib/spells.lua")

-- Basic Config
local basic = {
    ownerName = "Meeow" -- Your character name.
}

-- Healer Config
local healer = {
    enabled = TRUE,
    sayWord = TRUE,
    healthToHeal = 4000,
    min = 700,
    max = 1200
}
-- Mana Restore Config
local manaRestore = {
    enabled = TRUE,
    manaToRestore = 800,
    min = 150,
    max = 300
}
-- Rune Config
local rune = {
    enabled = TRUE,
    lastShoot = os.clock(), -- Don't touch!
    delay = 1,
    effect = CONST_ME_MORTAREA,
    shootEffect = CONST_ANI_SUDDENDEATH,
    combat = COMBAT_DEATHDAMAGE,
    min = 750,
    max = 1100
}
-- Spell Config
local spell = {
    enabled = TRUE,
    sayWord = TRUE,
    lastCast = os.clock(), -- Don't touch!
    delay = 3,
    combat = COMBAT_ICEDAMAGE,
    area = createCombatArea(AREA_CROSS5X5),
    word = "Exevo Gran Mas Frigo",
    effect = CONST_ME_ICETORNADO,
    min = 700,
    max = 1000
}
-- Anty Paralyze
local antyPara = {
    enabled = TRUE
}

-- Don't touch below!
local owner = 0
local target = FALSE

local function findOwner()
    local list = getSpectators(getNpcPos(), 9, 9, false)
    if (#list > 0) then
        for i = 1, #list do
            local _target = list[i]
            if (_target ~= 0) then
                if (getCreatureName(_target) == basic.ownerName) then
                    selfSay("Hi ".. basic.ownerName .."!")
                    selfFollow(_target)
                    owner = _target
                end
            end
        end
    end
end

local function doHealOwner()
    if (getCreatureHealth(owner) < healer.healthToHeal) then
        if (healer.sayWord) then
            doCreatureSay(getNpcCid(), "Exura Sio \"".. basic.ownerName, TALKTYPE_ORANGE_1)
        end
        doCreatureAddHealth(owner, math.random(healer.min, healer.max))
        doSendMagicEffect(getCreaturePosition(getNpcCid()), CONST_ME_MAGIC_BLUE)
        doSendMagicEffect(getCreaturePosition(owner), CONST_ME_MAGIC_GREEN)
    end
end

local function doRestoreMana()
    if (getPlayerMana(owner) < manaRestore.manaToRestore) then
        doPlayerAddMana(owner, math.random(manaRestore.min, manaRestore.max))
        doSendMagicEffect(getCreaturePosition(owner), CONST_ME_MAGIC_BLUE)
    end
end

local function doUseRune()
    target = FALSE
    local shooted = FALSE
    local r_list = getSpectators(getNpcPos(), 9, 9, false)
    if (#r_list > 0) then
        for i = 1, #r_list do
            local r_target = r_list[i]
            if (isPlayer(r_target) == FALSE and isNpc(r_target) == FALSE and getNpcCid() ~= r_target and shooted == FALSE) then
                local tPos = getCreaturePosition(r_target)
                doSendMagicEffect(tPos, rune.effect)
                doSendDistanceShoot(getCreaturePosition(getNpcCid()), tPos, rune.shootEffect)
                doTargetCombatHealth(getNpcCid(), r_target, rune.combat, -rune.min, -rune.max, rune.effect)
                shooted = TRUE
                target = TRUE
            end
        end
    end
end

local function doCastSpell()
    if (spell.sayWord) then
        doCreatureSay(getNpcCid(), spell.word, TALKTYPE_ORANGE_1)
    end

    doAreaCombatHealth(getNpcCid(), spell.combat, getCreaturePosition(getNpcCid()), spell.area, -spell.min, -spell.max, spell.effect)
end

local function doRemovePara()
    if (hasCondition(owner, CONDITION_PARALYZE)) then
        doRemoveCondition(owner, CONDITION_PARALYZE)
        doSendMagicEffect(getCreaturePosition(owner), CONST_ME_MAGIC_GREEN)
    end
end

function onCreatureDisappear(cid)
    if (cid == owner) then
        owner = 0
    end
end

function onCreatureSay(cid, type, msg)
    if (cid == owner) then
        if  (msg == "disappear") then
            selfSay("Good bye ;)")
            doHealOwner()
            doRestoreMana()
            doRemoveCreature(getNpcCid())
        elseif (msg == "kick") then
            doRemoveCreature(cid)
        end
    end
end

function onThink()
    -- Try to find owner, if he's not already found.
    if (owner == 0) then
        findOwner()
        return
    end

    -- Update following
    selfFollow(owner)

   -- On logout teleport
   local myPos = getCreaturePosition(getNpcCid())
   local nPos = {x = 936, y = 1028, z = 12}
   if (owner == 0) then
       doTeleportThing(getNpcCid(), nPos)
   return
       end

    -- On floor change ;)
    local myPos = getCreaturePosition(getNpcCid())
    local ownerPos = getCreaturePosition(owner)
    if (myPos.z ~= ownerPos.z) then
        doSendMagicEffect(myPos, CONST_ME_POFF)
        doTeleportThing(getNpcCid(), ownerPos)
        doSendMagicEffect(ownerPos, CONST_ME_TELEPORT)
    end

    -- Healer
    if (healer.enabled) then
        doHealOwner()
    end

    -- Mana Restore
    if (manaRestore.enabled) then
        doRestoreMana()
    end

    -- Shoot Rune
    if (rune.enabled and rune.lastShoot < os.clock()) then
        rune.lastShoot = (os.clock()+rune.delay)
        doUseRune()
    end

    -- Cast Spell
    if (spell.enabled and target ~= FALSE and spell.lastCast < os.clock()) then
        spell.lastCast = (os.clock()+spell.delay)
        doCastSpell()
    end

    -- Anty Paralyze
    if (antyPara.enabled) then
        doRemovePara()
    end
end
 
try this:
Code:
-- Load spell area's data.
dofile(getDataDir() .. "spells/lib/spells.lua")
local npc_sleep = {}

-- Basic Config
local basic = {
  ownerName = "Meeow" -- Your character name.
}

-- Healer Config
local healer = {
  enabled = TRUE,
  sayWord = TRUE,
  healthToHeal = 4000,
  min = 700,
  max = 1200
}
-- Mana Restore Config
local manaRestore = {
  enabled = TRUE,
  manaToRestore = 800,
  min = 150,
  max = 300
}
-- Rune Config
local rune = {
  enabled = TRUE,
  lastShoot = os.clock(), -- Don't touch!
  delay = 1,
  effect = CONST_ME_MORTAREA,
  shootEffect = CONST_ANI_SUDDENDEATH,
  combat = COMBAT_DEATHDAMAGE,
  min = 750,
  max = 1100
}
-- Spell Config
local spell = {
  enabled = TRUE,
  sayWord = TRUE,
  lastCast = os.clock(), -- Don't touch!
  delay = 3,
  combat = COMBAT_ICEDAMAGE,
  area = createCombatArea(AREA_CROSS5X5),
  word = "Exevo Gran Mas Frigo",
  effect = CONST_ME_ICETORNADO,
  min = 700,
  max = 1000
}
-- Anty Paralyze
local antyPara = {
  enabled = TRUE
}

-- Don't touch below!
local owner = 0
local target = FALSE

local function findOwner()
  local list = getSpectators(getNpcPos(), 9, 9, false)
   local ret = false
  if (#list > 0) then
  for i = 1, #list do
  local _target = list[i]
  if (_target ~= 0) then
  if (getCreatureName(_target) == basic.ownerName) then
  selfSay("Hi ".. basic.ownerName .."!")
  selfFollow(_target)
  owner = _target
           ret = true
           npc_sleep[getNpcCid()] = false
  end
  end
  end
  end
   return ret
end

local function doHealOwner()
  if (getCreatureHealth(owner) < healer.healthToHeal) then
  if (healer.sayWord) then
  doCreatureSay(getNpcCid(), "Exura Sio \"".. basic.ownerName, TALKTYPE_ORANGE_1)
  end
  doCreatureAddHealth(owner, math.random(healer.min, healer.max))
  doSendMagicEffect(getCreaturePosition(getNpcCid()), CONST_ME_MAGIC_BLUE)
  doSendMagicEffect(getCreaturePosition(owner), CONST_ME_MAGIC_GREEN)
  end
end

local function doRestoreMana()
  if (getPlayerMana(owner) < manaRestore.manaToRestore) then
  doPlayerAddMana(owner, math.random(manaRestore.min, manaRestore.max))
  doSendMagicEffect(getCreaturePosition(owner), CONST_ME_MAGIC_BLUE)
  end
end

local function doUseRune()
  target = FALSE
  local shooted = FALSE
  local r_list = getSpectators(getNpcPos(), 9, 9, false)
  if (#r_list > 0) then
  for i = 1, #r_list do
  local r_target = r_list[i]
  if (isPlayer(r_target) == FALSE and isNpc(r_target) == FALSE and getNpcCid() ~= r_target and shooted == FALSE) then
  local tPos = getCreaturePosition(r_target)
  doSendMagicEffect(tPos, rune.effect)
  doSendDistanceShoot(getCreaturePosition(getNpcCid()), tPos, rune.shootEffect)
  doTargetCombatHealth(getNpcCid(), r_target, rune.combat, -rune.min, -rune.max, rune.effect)
  shooted = TRUE
  target = TRUE
  end
  end
  end
end

local function doCastSpell()
  if (spell.sayWord) then
  doCreatureSay(getNpcCid(), spell.word, TALKTYPE_ORANGE_1)
  end

  doAreaCombatHealth(getNpcCid(), spell.combat, getCreaturePosition(getNpcCid()), spell.area, -spell.min, -spell.max, spell.effect)
end

local function doRemovePara()
  if (hasCondition(owner, CONDITION_PARALYZE)) then
  doRemoveCondition(owner, CONDITION_PARALYZE)
  doSendMagicEffect(getCreaturePosition(owner), CONST_ME_MAGIC_GREEN)
  end
end

function onCreatureDisappear(cid)
  if (cid == owner) then
  owner = 0
  end
end

function onCreatureSay(cid, type, msg)
  if (cid == owner) then
  if  (msg == "disappear") then
  selfSay("Good bye ;)")
  doHealOwner()
  doRestoreMana()
  doRemoveCreature(getNpcCid())
  elseif (msg == "kick") then
  doRemoveCreature(cid)
  end
  end
end

function onThink()
  -- Try to find owner, if he's not already found.
   local nPos = {x = 936, y = 1028, z = 12}
  if (owner == 0) then
  if not findOwner() then
       if not npc_sleep[getNpcCid()] then
         doTeleportThing(getNpcCid(), nPos)
         npc_sleep[getNpcCid()] = true -- means if the owner logged out we teleport the npc away and set him to sleep until the owner returns.
       end
     end
     return
  end

  -- Update following
  selfFollow(owner)

  -- On floor change ;)
  local myPos = getCreaturePosition(getNpcCid())
  local ownerPos = getCreaturePosition(owner)
  if (myPos.z ~= ownerPos.z) then
  doSendMagicEffect(myPos, CONST_ME_POFF)
  doTeleportThing(getNpcCid(), ownerPos)
  doSendMagicEffect(ownerPos, CONST_ME_TELEPORT)
  end

  -- Healer
  if (healer.enabled) then
  doHealOwner()
  end

  -- Mana Restore
  if (manaRestore.enabled) then
  doRestoreMana()
  end

  -- Shoot Rune
  if (rune.enabled and rune.lastShoot < os.clock()) then
  rune.lastShoot = (os.clock()+rune.delay)
  doUseRune()
  end

  -- Cast Spell
  if (spell.enabled and target ~= FALSE and spell.lastCast < os.clock()) then
  spell.lastCast = (os.clock()+spell.delay)
  doCastSpell()
  end

  -- Anty Paralyze
  if (antyPara.enabled) then
  doRemovePara()
  end
end
 
Back
Top