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

Lua [Creaturescript] Teleport problem and hidehealth error

Moj mistrz

Monster Creator
Joined
Feb 1, 2008
Messages
932
Solutions
10
Reaction score
296
Location
Poland
Hello, I've come here ask for a help in one script.
Code:
function onThink(cid)
    addEvent(Teleport, 10000, cid)
end

function Teleport (cid)
  local position = {
        [1] = {pos = {x=32955, y=32073, z=6}},
        [2] = {pos = {x=32962, y=32073, z=6}},
        [3] = {pos = {x=32962, y=32080, z=6}},
        [4] = {pos = {x=32955, y=32080, z=6}}
        }
  spawn = position[math.random(1,4)]
    doTeleportThing(cid, spawn.pos)
    doSendMagicEffect(getCreaturePosition(cid), 10)
    return TRUE
end
Basically it works fine, it starts after 10 seconds, but it teleports creature(after that 10s) faster than in a sec. It don't teleport creature after 10 seconds always as it should. Thanks for any help.

#edit:
Code:
function onThink(cid, words, param)
    local creature = Creature(cid)
    if creature ~= nil then
    local isGhost = not creature:isInGhostMode()
    local hp = (getCreatureHealth(cid)/getCreatureMaxHealth(cid))*100
    creature:setGhostMode(isGhost)
    if isGhost and (hp < 99.99) and getCreatureName(cid) == "Zavarash" and getCreatureCondition(cid, CONDITION_POISON) == FALSE then
    else
end
    return false
end
end
error:
jETh3I.png

Script should work like that - if creature gets damaged when in full health it goes invisible(no matter if damaged it will stay invisible) unless you put a poison field under it. Hope you get what I mean.
 
Last edited:
The reason your teleport script is waiting 10 seconds (as it should) and then teleporting really fast after that is because of the way you have it set onThink. Creatures think at a rate of 500ms so your script just keeps spamming that event. You will need to think of a way to detect if it has added that teleport event, and make it not execute again until its finished with the current teleport.
Something such as this might work:
Code:
local teleStorage = 1234 -- change this to an unused storage value
local position = { -- moved this table outside of the function (there is no need for the script to keep remaking the table since nothing is changing)
    [1] = {pos = {x=32955, y=32073, z=6}},
    [2] = {pos = {x=32962, y=32073, z=6}}, -- btw this is not needed "pos" unless you plan to add more things to the table later on.... i left it like that just in case
    [3] = {pos = {x=32962, y=32080, z=6}},
    [4] = {pos = {x=32955, y=32080, z=6}}
}

local function Teleport(cid) -- added local to this function
    if(not isCreature(cid)) then return true -- Added this to prevent console errors if creature dissapears before teleport is executed
    local spawn = position[math.random(4)] -- added local to this variable (you need to learn to use local variables its important)
    doTeleportThing(cid, spawn.pos)
    doSendMagicEffect(spawn.pos, 10) -- changed this to do the effect at the spawn position (no need to get the creatures position after teleport since we know where it will end up anyway)
    doCreatureSetStorage(cid, teleStorage, 0) -- this will flag the creature as teleported (so it can do it again)
    return true
end

function onThink(cid)
    if(getCreatureStorage(cid, teleStorage) <= 0) then
        doCreatureSetStorage(cid, teleStorage, 1) -- this will flag the creature as teleporting, so it will not happen again until the teleport is complete
        addEvent(Teleport, 10000, cid)
    end
    return true
end

It appears I set out to give you an example and ended up remaking the entire thing for you... oops. Well I added comments so you can maybe learn something from it at least.


As for the second one, I have no idea how setGhostMode works as I do not use tfs 1.0
 
Back
Top