• 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 1.0 | onStepIn tile vocation with possible payment restrictions

Cornex

Web Developer
Staff member
Global Moderator
Joined
Jun 15, 2008
Messages
3,444
Solutions
5
Reaction score
1,166
Location
Sweden
Hello, an small script for TFS 1.0.. When you stepin on the tile, you need to be the vocation as presented in config. Enable or disable payment as well.

Wall of helpers:
@sn3ejk @Ninja @Evan

Movements.xml
Code:
<movevent event="StepIn" uniqueid="65535" script="test.lua"/>
- Remember to set the uniqueid on the tile.

test.lua
Code:
local config = {
    -- Where to teleport the player
    -- X , Y , Z
    position = Position(20, 323, 7),
    -- What vocation you need to enter?
    vocation = {1,2,3,4},
    -- Enable cost to enter?
    -- This is 10 Crystal coins.
    itemCostEnable = true,
    itemID = 2160,
    itemCount = 10
}

function onStepIn(cid, item, position, fromPosition)
    local player = Player(cid)
    if player then
        if isInArray(config.vocation, player:getVocation():getId()) then
            if config.itemCostEnable then
                if player:removeItem(config.itemID, config.itemCount) then
                    player:teleportTo(config.position,1)
                    config.position:sendMagicEffect(11)
                    return true
                else
                    player:sendTextMessage(4, 'You need '..config.itemCount..'x of '..ItemType(config.itemID):getName()..' to pass.')
                    player:teleportTo(fromPosition,1)
                    fromPosition:sendMagicEffect(16)
                    return false
                end
            end
            player:teleportTo(config.position,1)
            config.position:sendMagicEffect(11)
            return true
        else
            player:sendTextMessage(4,'You dont have the right vocation to enter here.')
            player:teleportTo(fromPosition,1)
            fromPosition:sendMagicEffect(16)
            return false
        end
    else
        return false
    end
    return true
end

Hope you enjoy it.
 
Last edited:
Updated main post, using TFS 1.0 metatables functionality.

I would also like to thank @Evan for introduce me to start with metatables and why it is a better practice for TFS 1.0.
 
@Evan , learn me metatables too :p
i want to start with tfs 1.0 too

Hes very short on time as far I know. Maybe we can push him to write an meta tutorial in the future. Would be amazing :)
 
Remove :isPlayer() (if player then is enough), use constant variables and you can use ItemType(itemId):getName() instead of getItemName. L30-32 should be inside the itemCostEnable statement.

Otherwise it's good :p
 
Remove :isPlayer() (if player then is enough), use constant variables and you can use ItemType(itemId):getName() instead of getItemName. L30-32 should be inside the itemCostEnable statement.

Good job otherwise :p

Thanks! Are you sure that L30-32 should be inside the itemCostEnable? I mean, that one should be executed if it is set to false. I really tried to think what you mean, but it don't make any sense.
 
My bad, didn't notice all those return true/false x)
 
My bad, didn't notice all those return true/false x)

Oh I see! Well, updated main post with the other you pointed out, thanks a lot for the feedback.
Feedback = Learning.
 
Last edited:
Here is better version of your script <untested>:
PHP:
local config = {
  position  = Position(100, 100, 7),
  vocations = {1, 2, 3, 4},
  itemId    = 2160, -- nil/false means disabled
  itemCount = 10
}


function onStepIn(cid, item, position, fromPosition)
  local player = Player(cid)
  if not player then
    return false
  end

  if isInArray(config.vocations, player:getVocation():getId()) then
    if not config.itemId or player:removeItem(config.itemId, config.itemCount) then
      player:teleportTo(config.position, true)
    else
      player:sendTextMessage(MESSAGE_STATUS_WARNING, 'You need ' .. config.itemCount .. 'x of ' .. ItemType(config.itemId):getName() .. ' to pass.')
      player:teleportTo(fromPosition, true)
    end
  else
    player:sendTextMessage(MESSAGE_STATUS_WARNING, 'You dont have the right vocation to enter here.')
    player:teleportTo(fromPosition, true)
  end
  return true
end

Also, don't publish scripts like that because it's buggy; you don't use constants, use variable when it doesn't exist (player); weak optimization
 
Here is better version of your script <untested>:
PHP:
local config = {
  position  = Position(100, 100, 7),
  vocations = {1, 2, 3, 4},
  itemId    = 2160, -- nil/false means disabled
  itemCount = 10
}


function onStepIn(cid, item, position, fromPosition)
  local player = Player(cid)
  if not player then
    return false
  end

  if isInArray(config.vocations, player:getVocation():getId()) then
    if not config.itemId or player:removeItem(config.itemId, config.itemCount) then
      player:teleportTo(config.position, true)
    else
      player:sendTextMessage(MESSAGE_STATUS_WARNING, 'You need ' .. config.itemCount .. 'x of ' .. ItemType(config.itemId):getName() .. ' to pass.')
      player:teleportTo(fromPosition, true)
    end
  else
    player:sendTextMessage(MESSAGE_STATUS_WARNING, 'You dont have the right vocation to enter here.')
    player:teleportTo(fromPosition, true)
  end
  return true
end

Also, don't publish scripts like that because it's buggy; you don't use constants, use variable when it doesn't exist (player); weak optimization

First of all, don't tell people to "Not publish scripts like that".. People like you make this community fall. Next time, instead of tell me to don't publish scripts like this you can just put an answer how to improve it. I hate such attitude, for real.

Next, this script is not buggy. It is an short and simple script, how can it be buggy because I don't use constants? An buggy script for me is an script which not work, this works just fine.
 
@Cornex; seems criticism hurts you. I think that people like you make this community fall; somebody releases a script that doesn't work correctly or is non-optimized, other users use it and later they got problem with their servers (bugs).

Furthermore, you haven't read whole message - the most important piece:
use variable when it doesn't exist (player)
PHP:
local config = {
    -- Where to teleport the player
    -- X , Y , Z
    position = Position(20, 323, 7),
    -- What vocation you need to enter?
    vocation = {1,2,3,4},
    -- Enable cost to enter?
    -- This is 10 Crystal coins.
    itemCostEnable = true,
    itemID = 2160,
    itemCount = 10
}

function onStepIn(cid, item, position, fromPosition)
    local player = Player(cid)
    if player then
        if isInArray(config.vocation, player:getVocation():getId()) then
            if config.itemCostEnable then
                if player:removeItem(config.itemID, config.itemCount) then
                    player:teleportTo(config.position,1)
                    config.position:sendMagicEffect(11)
                    return true
                else
                    player:sendTextMessage(4, 'You need '..config.itemCount..'x of '..ItemType(config.itemID):getName()..' to pass.')
                    player:teleportTo(fromPosition,1)
                    fromPosition:sendMagicEffect(16)
                    return false
                end
            end
            player:teleportTo(config.position,1)
            config.position:sendMagicEffect(11)
            return true
        else
            player:sendTextMessage(4,'You dont have the right vocation to enter here.')
            player:teleportTo(fromPosition,1)
            fromPosition:sendMagicEffect(16)
            return false
        end
    else
      -- variable player is equal to nil or false here and you're going to use it
      -- really?
        player:teleportTo(fromPosition,1)
        fromPosition:sendMagicEffect(16)
    end
    return true
end
 
@Cornex; seems criticism hurts you. I think that people like you make this community fall; somebody releases a script that doesn't work correctly or is non-optimized, other users use it and later they got problem with their servers (bugs).

Furthermore, you haven't read whole message - the most important piece:

PHP:
local config = {
    -- Where to teleport the player
    -- X , Y , Z
    position = Position(20, 323, 7),
    -- What vocation you need to enter?
    vocation = {1,2,3,4},
    -- Enable cost to enter?
    -- This is 10 Crystal coins.
    itemCostEnable = true,
    itemID = 2160,
    itemCount = 10
}

function onStepIn(cid, item, position, fromPosition)
    local player = Player(cid)
    if player then
        if isInArray(config.vocation, player:getVocation():getId()) then
            if config.itemCostEnable then
                if player:removeItem(config.itemID, config.itemCount) then
                    player:teleportTo(config.position,1)
                    config.position:sendMagicEffect(11)
                    return true
                else
                    player:sendTextMessage(4, 'You need '..config.itemCount..'x of '..ItemType(config.itemID):getName()..' to pass.')
                    player:teleportTo(fromPosition,1)
                    fromPosition:sendMagicEffect(16)
                    return false
                end
            end
            player:teleportTo(config.position,1)
            config.position:sendMagicEffect(11)
            return true
        else
            player:sendTextMessage(4,'You dont have the right vocation to enter here.')
            player:teleportTo(fromPosition,1)
            fromPosition:sendMagicEffect(16)
            return false
        end
    else
      -- variable player is equal to nil or false here and you're going to use it
      -- really?
        player:teleportTo(fromPosition,1)
        fromPosition:sendMagicEffect(16)
    end
    return true
end

You seems to not understand English properly. Well, criticism do not hurt me. I like it. But do you think "Do not publish scripts like this" make anyone keep try to script something and release it here? I rather see 100 of bugged scripts that community helps to get better than 1 pro scripted.

Other than that, you seems to me like an "I'm the best, world suck" guy. Next time, try to help in a more friendly way than the first post.
 
You seems to not understand English properly. Well, criticism do not hurt me. I like it. But do you think "Do not publish scripts like this" make anyone keep try to script something and release it here? I rather see 100 of bugged scripts that community helps to get better than 1 pro scripted.

Other than that, you seems to me like an "I'm the best, world suck" guy. Next time, try to help in a more friendly way than the first post.
Seems you don't understand me. "Do not publish scripts like this" - it means don't release script that can throw error or is too risky in use. It's okay that you want to share your works but it should work properly because people can use it for their servers.

If you aren't sure that your script works properly you can send it to more advanced scripters/programmers (for example @Ninja).

Also is better to use actionid instead of uniqueid in this case because some players can use this tile more than one time and as far as I remember uniqueid can be used only once.
 
Seems you don't understand me. "Do not publish scripts like this" - it means don't release script that can throw error or is too risky in use. It's okay that you want to share your works but it should work properly because people can use it for their servers.

If you aren't sure that your script works properly you can send it to more advanced scripters/programmers (for example @Ninja).

Also is better to use actionid instead of uniqueid in this case because some players can use this tile more than one time and as far as I remember uniqueid can be used only once.

I have tried this script and it works just fine as it is now. Probably not the best script since I'm biggest noob in LUA at Otland.
I use Uniqueid, yes. But I can use this tile more than once.

And I ALWAYS try the scripts before I put them on OTland. If you think this script is to dangerous to use, please tell me in deeper detail please.
 
I have tried this script and it works just fine as it is now. Probably not the best script since I'm biggest noob in LUA at Otland.
I use Uniqueid, yes. But I can use this tile more than once.

And I ALWAYS try the scripts before I put them on OTland. If you think this script is to dangerous to use, please tell me in deeper detail please.
"But I can use this tile more than once." - do you mean that you can create more than one tile per map and both work correctly?

Just fix that with reference to nil (check last code that I have sent) and try to optimize it (less conditional statements). Also you can try to keep your code dry (http://en.wikipedia.org/wiki/Don't_repeat_yourself). I'm glad you're trying to practice and it would be great to have more advanced scripters here but you have to remember about hosters whose don't know how to fix small bugs in scripts.
 
"But I can use this tile more than once." - do you mean that you can create more than one tile per map and both work correctly?

Hmm that's and good question. I'm gonna have to try it later.
 
"But I can use this tile more than once." - do you mean that you can create more than one tile per map and both work correctly?

Just fix that with reference to nil (check last code that I have sent) and try to optimize it (less conditional statements). Also you can try to keep your code dry (http://en.wikipedia.org/wiki/Don't_repeat_yourself). I'm glad you're trying to practice and it would be great to have more advanced scripters here but you have to remember about hosters whose don't know how to fix small bugs in scripts.
Well the script works for 2 different tiles with the same uniqueid but it'll throw an error in console something like "Duplicated uniqueid xxx" @sn3ejk

Keep practicing Cornex, you're on the right way.
Just keep re reading your scripts after you finish them and try to debug them, trust me stuff like that happens to me quite often aswell, however if you do as mentioned you'll get better and better :)
 
Here is better version of your script <untested>:
PHP:
local config = {
  position  = Position(100, 100, 7),
  vocations = {1, 2, 3, 4},
  itemId    = 2160, -- nil/false means disabled
  itemCount = 10
}


function onStepIn(cid, item, position, fromPosition)
  local player = Player(cid)
  if not player then
    return false
  end

  if isInArray(config.vocations, player:getVocation():getId()) then
    if not config.itemId or player:removeItem(config.itemId, config.itemCount) then
      player:teleportTo(config.position, true)
    else
      player:sendTextMessage(MESSAGE_STATUS_WARNING, 'You need ' .. config.itemCount .. 'x of ' .. ItemType(config.itemId):getName() .. ' to pass.')
      player:teleportTo(fromPosition, true)
    end
  else
    player:sendTextMessage(MESSAGE_STATUS_WARNING, 'You dont have the right vocation to enter here.')
    player:teleportTo(fromPosition, true)
  end
  return true
end

Also, don't publish scripts like that because it's buggy; you don't use constants, use variable when it doesn't exist (player); weak optimization

Its still a good script and it better that uses releases things like this then what I hate the most atm, the rlmap project(not trying to start a discussion) but this won't increase the download and run servers and will make it easier for other users to find what they serach for(if new users even does that now adays)...
Still I don't get why you seem to hate on uses releasing things like this script? Its a script that can help the community even if its not the best.
And PLEASE use code tags insted of php tags...
 
Back
Top