• 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 I got through 11 missions of my quest I'm working on to be stumped..

XiolenceOT

New Member
Joined
Jun 5, 2023
Messages
42
Reaction score
4
On something as simple as a StepIn function, could anyone tell me how to fix this, I'm trying to make it so a player steps on a certain tile (in this case four tiles all doing the same thing, changing storage if the value is 1 if not then doing nothing instead)
I can't even imagine how simple this is going to be, but I would like to understand what I did wrong.

Movements.xml --->
XML:
 <movement event="StepIn" itemid="103" script="clairetiles.lua" />

Lua:
 function onStepIn(creature, item, position, lastPosition)
    if isPlayer(cid) and item.itemid == 103 and item.actionid == 7777 then
        local storageValue = getPlayerStorageValue(cid, 2976)
        if storageValue == 1 then
            setPlayerStorageValue(cid, 2976, 2)
        end
    end
    return true
end
Post automatically merged:

lets close this and not talk about ... reading all those thread of people spelling stuff wrong for an hour and I did the same damn thing.
 
Last edited:
On something as simple as a StepIn function, could anyone tell me how to fix this, I'm trying to make it so a player steps on a certain tile (in this case four tiles all doing the same thing, changing storage if the value is 1 if not then doing nothing instead)
I can't even imagine how simple this is going to be, but I would like to understand what I did wrong.

Movements.xml --->
XML:
 <movement event="StepIn" itemid="103" script="clairetiles.lua" />

Lua:
 function onStepIn(creature, item, position, lastPosition)
    if isPlayer(cid) and item.itemid == 103 and item.actionid == 7777 then
        local storageValue = getPlayerStorageValue(cid, 2976)
        if storageValue == 1 then
            setPlayerStorageValue(cid, 2976, 2)
        end
    end
    return true
end
Post automatically merged:

lets close this and not talk about ... reading all those thread of people spelling stuff wrong for an hour and I did the same damn thing.
As i'm not a pro, but the problem is isPlayer(cid) and old functions to new tfs

if your function is
Lua:
function onStepIn(creature, item, position, lastPosition)
try using new functions.

To start, we will identify the item that you will be using or stepping, as your script will be used with only one item, we do not need to identify the item with the function item.itemid, here we can use only the actionid of the item, this way, the script will work on any floor that you put this id, not getting stuck to only the itemid 103:

we can use item.itemid or item.actionid, but it is interesting to use the new functions as a way to get used to it, so we will use item:getId() and item:getActionId(), so if we put everything:
Lua:
if item:getId() == 103 and item:getActionId() == 7777 then

But as I said earlier, there is no reason to put the ID of the item, if you do this you restrict this script to only items with ID 103, but if you put only the ActionID 7777, you can use it on any item(Although as you will register this script in Movements.xml with Aid 7777, so it was not even necessary to put here in the script):
Lua:
if item:getActionId() == 7777 then


For movements, "creature" is everything: player, monster, npc(idk)... then we'll need to use creature:isPlayer() or creature:getPlayer():
-> creature:isPlayer() is a function that returns a Boolean value indicating whether the creature is a player or not. If the creature is a player, the function returns true, otherwise it returns false.
-> On the other hand, creature:getPlayer() is a function that attempts to convert the creature into an object of type Player. If the creature is a player, the function returns the corresponding Player object. Otherwise, returns nil.
=> The main difference between the two functions is that creature:isPlayer() is used to check whether a creature is a player or not, while creature:getPlayer() is used to get the Player object corresponding to a creature if it is a player.

so here we will use creature:getPlayer(), since in addition to checking if it is a player, we also need to interact with it:

right after function... we will add local player = creature:getPlayer(), the idea of using this is not to be using creature:getPlayer() every time it is necessary, being able to use only player as an "abbreviation", together we will use a way to "stop" the script if it is not a player, thus preventing it from being triggered by monsters.
Lua:
function onStepIn(creature, item, position, fromPosition)
if item:getActionId() == 7777 then
    local player = creature:getPlayer()
    if not player then -- If you are not a player, the script returns here and does not continue the rest of the functions
        return true
    end

You used getPlayerStorageValue(cid, storage), and although it works (as long as you declare the cid) it is an old and existing function only as a form of compatibility, if you are going to create new scripts, try using the new functions that in this case would be getStorageValue(storage) or setStorageValue(storage,value)..
Note that the CID is gone, and the CID is used as a way to "identify" the player, but in the new TFs this identification is done in another way(creature for movements, player for actions and so...), it is no longer within the function being declared in conjunction with it, I do not know the correct term, but you use the new functions declaring the player, monster, object, npc and then comes the function making a junction with : getting like this: player:getStorageValue(storage), remembering that player is creature:getPlayer() which we declare above

Lua:
function onStepIn(creature, item, position, fromPosition)
    if item:getActionId() == 7777 then
        local player = creature:getPlayer()
        if not player then -- If you are not a player, the script returns here and does not continue the rest of the functions
            return true
        end

        local storageValue = player:getStorageValue(2976)
        if storageValue == 1 then
            player:setStorageValue(2976, 2)
        end
    end
    return true
end

or you can solve everything using the old function, change creature for cid
 
On something as simple as a StepIn function, could anyone tell me how to fix this, I'm trying to make it so a player steps on a certain tile (in this case four tiles all doing the same thing, changing storage if the value is 1 if not then doing nothing instead)
I can't even imagine how simple this is going to be, but I would like to understand what I did wrong.

Movements.xml --->
XML:
 <movement event="StepIn" itemid="103" script="clairetiles.lua" />

Lua:
 function onStepIn(creature, item, position, lastPosition)
    if isPlayer(cid) and item.itemid == 103 and item.actionid == 7777 then
        local storageValue = getPlayerStorageValue(cid, 2976)
        if storageValue == 1 then
            setPlayerStorageValue(cid, 2976, 2)
        end
    end
    return true
end
Post automatically merged:

lets close this and not talk about ... reading all those thread of people spelling stuff wrong for an hour and I did the same damn thing.
should use actionid instead of itemid here
<movement event="StepIn" itemid="103" script="clairetiles.lua" />
That way you're not restricting the use of that item forever to only this script.

Then on this line, you don't need to check for the actionid or itemid, since you only need the actionid to trigger it.. and no point in verifying that the trigger exists.. since if it didn't trigger then the actionid already doesn't exist.

Hope that makes sense lol
if isPlayer(cid) and item.itemid == 103 and item.actionid == 7777 then
if isPlayer(cid) then

And I think you figured this out already.. but to re-iterate..
tfs 0.4 and tfs 1.0+ script are usually named differently when using the functions.
You can technically name them whatever you want, but it's good to keep consistency.

0.4
function onStepIn(cid, item, position, fromPosition)
1.0+
function onStepIn(creature, item, position, fromPosition)

You haven't stated it here, but I know you're using tfs 1.4.2
So you should try to not use the old compat functions as best you can


So all in all

XML:
 <movement event="StepIn" actionid="7777" script="clairetiles.lua" />
Lua:
local storageKey = 2976

function onStepIn(creature, item, position, lastPosition)
    local player = Player(creature:getId())
    if player then
        if player:getStorageValue(storageKey) == 1 then
            player:setStorageValue(storageKey, 2)
        end
    end
    return true
end
 
should use actionid instead of itemid here
<movement event="StepIn" itemid="103" script="clairetiles.lua" />
That way you're not restricting the use of that item forever to only this script.

Then on this line, you don't need to check for the actionid or itemid, since you only need the actionid to trigger it.. and no point in verifying that the trigger exists.. since if it didn't trigger then the actionid already doesn't exist.

Hope that makes sense lol
if isPlayer(cid) and item.itemid == 103 and item.actionid == 7777 then
if isPlayer(cid) then

And I think you figured this out already.. but to re-iterate..
tfs 0.4 and tfs 1.0+ script are usually named differently when using the functions.
You can technically name them whatever you want, but it's good to keep consistency.

0.4
function onStepIn(cid, item, position, fromPosition)
1.0+
function onStepIn(creature, item, position, fromPosition)

You haven't stated it here, but I know you're using tfs 1.4.2
So you should try to not use the old compat functions as best you can


So all in all

XML:
 <movement event="StepIn" actionid="7777" script="clairetiles.lua" />
Lua:
local storageKey = 2976

function onStepIn(creature, item, position, lastPosition)
    local player = Player(creature:getId())
    if player then
        if player:getStorageValue(storageKey) == 1 then
            player:setStorageValue(storageKey, 2)
        end
    end
    return true
end
Appreciate it, yeah I did eventually figure it out lol, I’m almost done with my quest and I’m gonna share just cause I think it’s neat, but currently having issues with a part where you meet another NPC and he gives you a side quest before continuing and the values keep messing up blah.
 
Back
Top