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

TFS 0.X tfs 0.4 help with lua

Solution
try this
@edit should be
Code:
and not isInRange
Edit

Just realised it should be or not and in this spot. lol
We want to check if either of them are false, not if both are false.
Lua:
function onLogin(cid)
    addEvent(pzAutoLeveler, 1000, cid, 0)
    return true
end

local function pzAutoLeveler(cid, count)
    if not isPlayer(cid)
        return false
    end
 
    if getTilePzInfo(getPlayerPosition(cid)) == false and not isInRange(getThingPos(cid), config.fromPos, config.toPos) then
        addEvent(pzAutoLeveler, 1000, cid, 0)
        return true
    end

    if counter == 60 then
        doPlayerAddLevel(cid, 1)
        doPlayerSendTextMessage(cid, 19, "Omm, server gifted you 1 level!")
        return true
    end...
Checks every 1 second if player is standing on a pz tile.
Very slight possible abuse if player walks outside of pz, then back into pz inbetween checks, the counter will still continue.


When 60 successful pz checks have been made, the player will advance 1 level.

Make sure to register in creaturescripts.xml and also login.lua near bottom.
Lua:
local function pzAutoLeveler(cid, counter)
    if isPlayer(cid) then
        if not getTilePzInfo(getPlayerPosition(cid)) then
            addEvent(pzAutoLeveler, 1000, cid, 0)
        else
            if counter == 60 then
                counter = 0
                doPlayerAddLevel(cid, 1)
            end
            addEvent(pzAutoLeveler, 1000, cid, counter + 1)
        end
    end
end

function onLogin(cid)
    addEvent(pzAutoLeveler, 1000, cid, 0)
    return true
end
 
I allowed myself to slightly edit the script and unfortunately it does not work.
Code:
local config = {
    fromPos = {x=999,y=998,z=7},
    toPos =    {x=1005,y=1003,z=7},
}

local function pzAutoLeveler(cid, counter)
    if isPlayer(cid) then
    if(isInRange(getThingPos(cid), config.fromPos, config.toPos)) then
    doPlayerSendTextMessage(cid, 19, "Omm, you are in the place!")
    else
    doPlayerSendTextMessage(cid, 19, "Omm, you are not in the place!")
    end
        if not getTilePzInfo(getPlayerPosition(cid)) < 1 then
            addEvent(pzAutoLeveler, 1000, cid, 0)
        else
            if counter == 60 then
                counter = 0
                doPlayerAddLevel(cid, 1)
        doPlayerSendTextMessage(cid, 19, "Omm, server gifted you 1 level!")
            end
            addEvent(pzAutoLeveler, 1000, cid, counter + 1)
        end
    end
end

function onLogin(cid)
    addEvent(pzAutoLeveler, 1000, cid, 0)
    return true
end
 
Last edited:
try this

Lua:
local config = {
    fromPos = {x=999,y=998,z=7},
    toPos = {x=1005,y=1003,z=7},
}

local function pzAutoLeveler(cid, counter)
    if isPlayer(cid) then
        if getTilePzInfo(getPlayerPosition(cid)) == false and not isInRange(getThingPos(cid), config.fromPos, config.toPos) then
            addEvent(pzAutoLeveler, 1000, cid, 0)
        else
            if counter == 60 then
                counter = 0
                doPlayerAddLevel(cid, 1)
                doPlayerSendTextMessage(cid, 19, "Omm, server gifted you 1 level!")
            end
            addEvent(pzAutoLeveler, 1000, cid, counter + 1)
        end
    end
end

function onLogin(cid)
    addEvent(pzAutoLeveler, 1000, cid, 0)
    return true
end

@edit should be
Code:
and not isInRange
 
Last edited:
Lua:
function onLogin(cid)
    addEvent(pzAutoLeveler, 1000, cid, 0)
    return true
end

local function pzAutoLeveler(cid, count)
    if not isPlayer(cid)
        return false
    end
  
    if getTilePzInfo(getPlayerPosition(cid)) == false and not isInRange(getThingPos(cid), config.fromPos, config.toPos) then
        addEvent(pzAutoLeveler, 1000, cid, 0)
        return true
    end

    if counter == 60 then
        doPlayerAddLevel(cid, 1)
        doPlayerSendTextMessage(cid, 19, "Omm, server gifted you 1 level!")
        return true
    end

    addEvent(pzAutoLeveler, 1000, cid, count + 1)
    return true
end

Easier to read imo
 
Last edited:
Lua:
function onLogin(cid)
    addEvent(pzAutoLeveler, 1000, cid, 0)
    return true
end

local function pzAutoLeveler(cid, count)
    if not isPlayer(cid)
        return false
    end
 
    if getTilePzInfo(getPlayerPosition(cid)) == false and not isInRange(getThingPos(cid), config.fromPos, config.toPos) then
        addEvent(pzAutoLeveler, 1000, cid, 0)
        return true
    end

    if counter == 60 then
        doPlayerAddLevel(cid, 1)
        doPlayerSendTextMessage(cid, 19, "Omm, server gifted you 1 level!")
        return true
    end

    addEvent(pzAutoLeveler, 1000, cid, count + 1)
    return true
end

Easier to read imo
what about ur mom
 
try this
@edit should be
Code:
and not isInRange
Edit

Just realised it should be or not and in this spot. lol
We want to check if either of them are false, not if both are false.
Lua:
function onLogin(cid)
    addEvent(pzAutoLeveler, 1000, cid, 0)
    return true
end

local function pzAutoLeveler(cid, count)
    if not isPlayer(cid)
        return false
    end
 
    if getTilePzInfo(getPlayerPosition(cid)) == false and not isInRange(getThingPos(cid), config.fromPos, config.toPos) then
        addEvent(pzAutoLeveler, 1000, cid, 0)
        return true
    end

    if counter == 60 then
        doPlayerAddLevel(cid, 1)
        doPlayerSendTextMessage(cid, 19, "Omm, server gifted you 1 level!")
        return true
    end

    addEvent(pzAutoLeveler, 1000, cid, count + 1)
    return true
end

Easier to read imo
You are ending the script prematurely and it won't loop.
Need to remove the second last return true.

Ok thanks all and how to add messages when player joined to the place and leave?
You can add another value and check your script against that value.
Lua:
local config = {
    fromPos = {x = 999, y = 998, z = 7},
    toPos = {x = 1005, y = 1003, z = 7}
}

local function pzAutoLeveler(cid, counter, msg_check)
    if isPlayer(cid) then
        local cid_pos = getThingPosition(cid)
        if getTilePzInfo(cid_pos) == false or not isInRange(cid_pos, config.fromPos, config.toPos) then
            if msg_check ~= 0 then
               doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You are no longer in a pz zone.")
            end
            addEvent(pzAutoLeveler, 1000, cid, 0, 0)
        else
            if msg_check ~= 1 then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You are now in a pz zone.")
            end
            if counter == 60 then
                counter = 0
                doPlayerAddLevel(cid, 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "Omm, server gifted you 1 level!")
            end
            addEvent(pzAutoLeveler, 1000, cid, counter + 1, 1)
        end
    end
end

function onLogin(cid)
    addEvent(pzAutoLeveler, 1000, cid, 0, 2)
    return true
end
 
Last edited:
Solution
Back
Top