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

My "live in town" script is not working

Jack Parsons

Member
Joined
Mar 8, 2016
Messages
32
Reaction score
12
Location
São Paulo State, Brazil
I've seen many scripts using "onUse", and that doesn't make sense to me (Since I'm not going to actually use the portal). The "onUse" scripts don't work for me as well. I'm using The Forgotten Server 1.0 (1041 client).

Here's my script:
Code:
local portalPos = {x = 1023, y = 1020, z = 6}

function onStepIn(cid, item, position, fromPosition)
    if position == portalPos then
        doPlayerSetTown(cid, 1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
        doSendAnimatedText(portalPos, "You are now living in the main part of the Agharti Empire!", TEXTCOLOR_GOLD)
    end
    return TRUE
end

It seems pretty logical to me, since the action is about stepping in, and not about "using". Nevertheless, it just doesn't work.

The mainstream version with "onUse" doesn't work as well:
Code:
local portalPos = {x = 1023, y = 1020, z = 6}

function onUse(cid, item, fromPosition, itemEx, toPosition)
        doPlayerSetTown(cid, 1)
        doTeleportThing(cid, portalPos, TRUE)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doSendAnimatedText(portalPos, "You are now living in the main part of the Agharti Empire!", TEXTCOLOR_GOLD)
    return TRUE
end

And here's the action inside actions.xml:
Code:
<actions>
<!-- > Portals </!-->
    <action uniqueid="2000" script="portals/agharti_main.lua"/>
</actions>

Also, the script is properly inside portals inside scripts inside actions inside data.
 
Hi there,

The function onStepIn is used in movements, so not in actions.xml.

Code:
<movevent event="StepIn" itemid="2000" script="portals/agharti_main.lua"/>
<!-- ItemID should be the tile itemid. -->

Code:
local portalPos = {x = 1023, y = 1020, z = 6}

function onStepIn(cid, item, position, fromPosition)
        if (item.uid == xxxx) then -- So this should be the Unique ID that you've putted on the tile in Remeres
              doPlayerSetTown(cid, 1)
              doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
              doSendAnimatedText(portalPos, "You are now living in the main part of the Agharti Empire!", TEXTCOLOR_GOLD)
              doTeleportThing(cid, portalPos, TRUE)
              end
    return TRUE
end

I'm not rlly good at scripting but maybe you can try this out. If you got an error let me know.

You need to change some stuff but I explained that in the script.

It doesn't give any error in my lua interpreter.
 
Last edited by a moderator:
Oh, this makes sense... It worked! Thank you very much! Here's the final script:

Code:
<movements>
    <!-- Portals -->
    <movevent event="StepIn" itemid="1387" script="portals/agharti_main.lua"/>
</movements>

1384 is the ID for the "magic forcefield" (Not the UID that I've inserted on the map editor, so I had to discover that).

Code:
local portalPos = {x = 1023, y = 1020, z = 6}
local townId = 1

function onStepIn(cid, item, position, fromPosition)
        if (item.uid == 2000) then
              doPlayerSetTown(cid, townId)
              doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
              doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are now living in the main part of the Agharti Empire!")
              doTeleportThing(cid, {x = 1023, y = 1023, z = 6}, TRUE)
        end
    return TRUE
end

doSendAnimatedText() is a deprecated function on the version that I'm using, so I had to use doPlayerSendTextMessage() instead. Also, the portal position can't be passed as an argument to doTeleportThing(), since that makes the player teleport itself endlessly to the same place, culminating in a stack overflow and crashing the server.

Thank you very much for your help!
 
Last edited:
Oh, this makes sense... It worked! Thank you very much! Here's the final script:

Code:
<movements>
    <!-- Portals -->
    <movevent event="StepIn" itemid="1387" script="portals/agharti_main.lua"/>
</movements>

1384 is the ID for the "magic forcefield" (Not the UID that I've inserted on the map editor, so I had to discover that).

Code:
local portalPos = {x = 1023, y = 1020, z = 6}
local townId = 1

function onStepIn(cid, item, position, fromPosition)
        if (item.uid == 2000) then
              doPlayerSetTown(cid, townId)
              doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
              doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are now living in the main part of the Agharti Empire!")
              doTeleportThing(cid, {x = 1023, y = 1023, z = 6}, TRUE)
        end
    return TRUE
end

doSendAnimatedText() is a deprecated function on the version that I'm using, so I had to use doPlayerSendTextMessage() instead. Also, the portal position can't be passed as an argument to doTeleportThing(), since that makes the player teleport itself endlessly to the same place, culminating in a stack overflow and crashing the server.

Thank you very much for your help!
Using itemID's is a bad idea though.(Well not a bad idea persay.. but if you want to use that item in another script you won't be able to.)
I personally try to use ActionID whenever possible.

On map editor put your aid on the tile beneath the portal.
In movements.xml place aid into the line like actionid="45001" instead of itemid="1387"

Setting it up this way, if the player steps on a tile that has that aid, it will trigger the script attached to it.

At this point you only need the script to do what you need it to do.

on my phone.. so no actual script but do this..

Code:
 function on step in

    set town
    send message
    teleport effect on portal
    teleport player
    teleport effect at new location of player
 
   return true
end
 
Back
Top