Movements...

kuks

New Member
Joined
Apr 30, 2017
Messages
20
Reaction score
3
Hi, somebody know how make teleport when player enter on this fire?
Somebody can tell me step by step how to do it? I know only i have do something in script and movement...
 

Mustafa1337

Î Àm ŁĕğẹňĎ
Joined
Mar 4, 2017
Messages
313
Reaction score
80
TFS version?
movements/scripts
Lua:
function onStepIn(cid, item, position, fromPosition)
    local from, to, setX, setY, setZ, Pos = { x = 258, y = 1934 }, { x = 284, y = 1955 }, math.random(from.x,to.x), math.random(from.y,to.y), 8, {x = setX, y = setY, z = setZ}
    
    function isWalkable(cid, pos)
    pos.stackpos = 0
    if getTileThingByPos(pos).uid ~= 0 then
        local n = getTileInfo(pos)
        if n.house == false and getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
            return true
        end
    end    end
    if isWalkable(cid, Pos) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doTeleportThing(cid, Pos)
    else
        return doTeleportThing(cid, fromPosition, true) and doPlayerSendCancel(cid, "Try again.")
    end
    return true
end
Name it what ever you want .lua, This should tp players to range from xyz to xyz random.
add to movements and change actionid/script name and then add it using map editor
XML:
    <movevent type="StepIn" actionid="7070" event="script" value="yourname.lua"/>
since you didn't say your TFS so I posted this one TFS 0.4 and should be working with higher TFS to 1.x I think so.
 
OP
K

kuks

New Member
Joined
Apr 30, 2017
Messages
20
Reaction score
3
Apologise i forgot - TFS version 1.3

Przejsciestatek.lua - name script.

So if i want TP from position x= 1101 y= 992 z= 6 to x= 1101 y= 996 z= 6 i have to edit script like that


Code:
function onStepIn(cid, item, position, fromPosition)

    local from, to, setX, setY, setZ, Pos = { x = 1101, y = 992, z = 6}, { x = 1101, y = 992, z = 6 }, math.random(from.x,to.x), math.random(from.y,to.y), 8, {x = 1101 y = 996, z = set6}

    

    function isWalkable(cid, pos)

    pos.stackpos = 0

    if getTileThingByPos(pos).uid ~= 0 then

        local n = getTileInfo(pos)

        if n.house == false and getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then

            return true

        end

    end    end

    if isWalkable(cid, Pos) then

        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)

        doTeleportThing(cid, Pos)

    else

        return doTeleportThing(cid, fromPosition, true) and doPlayerSendCancel(cid, "Try again.")

    end

    return true

end
I add one line to movement

Code:
<movevent type="StepIn" actionid="7070" event="script" value="przejsciestatek.lua"/>
And the last step change in RME ActionID "7070"

I do everything like i wrote but teleport didn't work...
 

Mustafa1337

Î Àm ŁĕğẹňĎ
Joined
Mar 4, 2017
Messages
313
Reaction score
80
Change this
XML:
<movevent type="StepIn" actionid="7070" event="script" value="przejsciestatek.lua"/>
to this
XML:
<movevent event="StepIn" actionid="7070" script="przejsciestatek.lua"/>
And tell me how it works, as I mentioned this one is made mainly for 0.4 but I guess it should work.
 
OP
K

kuks

New Member
Joined
Apr 30, 2017
Messages
20
Reaction score
3
I change this line in movements but still didn't work...Plus error in my consol

Code:
[Warning - Event::checkScript] Can not load script: scripts/przejsciestatek.lua
data/movements/scripts/przejsciestatek.lua:5: '}' expected near 'y'
 
OP
K

kuks

New Member
Joined
Apr 30, 2017
Messages
20
Reaction score
3
Still nothing...Somebody have any idea why?
 

Mustafa1337

Î Àm ŁĕğẹňĎ
Joined
Mar 4, 2017
Messages
313
Reaction score
80
Put this instead of the one you have and try.
Lua:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end
        player:teleportTo(Position(32369, 32232, 7), false)           
    return true
end
 
Last edited:

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
722
Reaction score
442
Location
United States
Put this instead of the one you have and try.
Lua:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end
        player:teleportTo(Position(1000, 1000, 7), false)        
    end
    return true
end
Returning false won't negate the onStepIn. You'll need to teleport them back to fromPosition with walk movement and you have an unnecessary end that will cause error.
 

Mustafa1337

Î Àm ŁĕğẹňĎ
Joined
Mar 4, 2017
Messages
313
Reaction score
80
Returning false won't negate the onStepIn. You'll need to teleport them back to fromPosition with walk movement and you have an unnecessary end that will cause error.
Yeah I edited that and tested it is working now, sorry I am still new to this. you can correct it but I tested in-game it works.
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
722
Reaction score
442
Location
United States
Yeah I edited that and tested it is working now, sorry I am still new to this. you can correct it but I tested in-game it works.
I'm sure it'll ignore the code that follows after you return false. I'm just saying it will still allow the monster to walk on the portal without teleporting it. Yours is good tho, I'm just pointing it out.

I would do like this:
Lua:
local destination = Position(1101, 996, 6)

function onStepIn(creature, item, toPosition, fromPosition)
    if creature:isPlayer() then
        creature:teleportTo(destination)
        destination:sendMagicEffect(CONST_ME_TELEPORT)
    else
        creature:teleportTo(fromPosition, true)
    end
    return true
end
 

Mustafa1337

Î Àm ŁĕğẹňĎ
Joined
Mar 4, 2017
Messages
313
Reaction score
80
I'm sure it'll ignore the code that follows after you return false. I'm just saying it will still allow the monster to walk on the portal without teleporting it. Yours is good tho, I'm just pointing it out.

I would do like this:
Lua:
local destination = Position(1101, 996, 6)

function onStepIn(creature, item, toPosition, fromPosition)
    if creature:isPlayer() then
        creature:teleportTo(destination)
        destination:sendMagicEffect(CONST_ME_TELEPORT)
    else
        creature:teleportTo(fromPosition, true)
    end
    return true
end
Yeah I understood what you meant, Thanks he can use yours seems to be more specific.
 
OP
K

kuks

New Member
Joined
Apr 30, 2017
Messages
20
Reaction score
3
Ok guys, i didn't check script what you wrote Apollos but many thanks.I spoke with one of user our forum and he give me solution ;)

Code:
function onStepIn(cid, item, pos)
 
local tp = {x=1101, y=996, z=6} 
   if item.actionid == 50040 then
    doTeleportThing(cid,tp)
    doSendMagicEffect(getCreaturePosition(cid),10)
 end
   return 1
end
And movements

Code:
<movevent event="StepIn" actionid="50040" script="NAME.lua" />
Thanks everybody who try help me!
 

beliar34

Intermediate OT User
Joined
Feb 28, 2012
Messages
276
Reaction score
7
Guys why you make so complicated scripts ? XD you want to show off or smtin ? simple solutions are the best ones :)
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
722
Reaction score
442
Location
United States
Ok guys, i didn't check script what you wrote Apollos but many thanks.I spoke with one of user our forum and he give me solution ;)

Code:
function onStepIn(cid, item, pos)

local tp = {x=1101, y=996, z=6}
   if item.actionid == 50040 then
    doTeleportThing(cid,tp)
    doSendMagicEffect(getCreaturePosition(cid),10)
end
   return 1
end
And movements

Code:
<movevent event="StepIn" actionid="50040" script="NAME.lua" />
Thanks everybody who try help me!
For the sake of learning. This script is messed up in many ways.

  • Even though it will still return true since 1 == true it is not syntactically correct to do so in lua. This gives the impression that 0 is treated as a false boolean which is not the case.
  • Using outdated legacy functions are bad practice when you're using TFS 1.X
  • There is no need to verify that the items action id is right in the script because that is already handled in xml.
  • These onStepIn parameters are misleading, creature data is sent in 1.X onStepIn's, not cid you essentially are reverifying a creature userdata because you are under the impression this is a unique id.
  • Best to use enums for magic effects instead of the numbers so it's easier to identify.
  • local tp can be declared outside the function since it's a universal variable and doesn't need to be declared every time.
EDIT: There's nothing complicated about our scripts at all. We're just correctly writing them.
 
Last edited:
Top