• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

A nice toutorial about making your own custom tp with advanced options

Doggynub

LUA / C++
Joined
Sep 28, 2008
Messages
2,541
Reaction score
186
*asuming you know a little about lua basics.
if not then visit this site:
Lua:
 How to make a working script - OpenTibia Fans[/URL]
 
[B][SIZE=3]-Now i hope you have read both action and movement parts and got an idea about them,so now [/SIZE][/B]
 
[B][U][SIZE=3][COLOR=red]Let's start with simple tp script then we advance in it step by step:[/COLOR][/SIZE][/U][/B]
 
[FONT=Arial Black][COLOR=black][U][B]1[/B][/U][FONT=Arial][SIZE=3][I]-[B]Now let's add this code in the movement.xml file([/B][SIZE=2]just to inform server if item is with this id then it do as follow in script)[/SIZE][/I][/SIZE][/FONT][/COLOR][/FONT]
[I][FONT=Arial][COLOR=#000000][B]in this case i will use a chair with id= 9445 [/B][/COLOR][/FONT][/I]
[CODE]<movevent type="StepIn" itemid="9445" event="script" value="custom tele.lua"/>
value is the script file name
in this case i iwll name it "custom tele.lua" this make us advance to the other step.

2-Now you need to go to the script folder in the movement and add file with this name "custom tele.lua"(place where you going to add the script in).

Now after we finished these 2 steps lets advance to the script thing:

First: as i hope u have lerned from basics up that movement scripts is started by this code
Code:
function onStepIn(cid, item, position, fromPosition)
to show server that this happen when u step on

then: like i have said before the item i use is a chair (id=9445) so what if you want only a chair in a chosen postion to do the tp thing but you dont want all the chairs of same kind you put in map to tp player.I quess you will think "I have to put a special mark to the needed chair".Yes that is right,but how to put special mark in server??
ok to put a special mark to an item you use this command
Code:
if item.actionid == number then
or this
Code:
if item.uid == number then

so the first one is to mark the item with an action id(but i will not use that here), so this lead us to the second command whch to put a unique id to the item,in the place where it says
number : refers to the unique id you chose to distinguish that chair from others of same kind.

so that line means if that item have exactly(==) that unique id then the following will happen

*Maybe you are wondring how to put the unique id for the item it self??
For those who wonder here it is:
in your map editor when you put an item and then (right click) on it then choose
properties, a box will appear will have 3 column:
count :
actionid:
uniqueid:*******
here in the third column you add the number you want to distinguich the item for other items, so this is the number you will add in script
script will be like that
if the unique id i put in the map editor is = 1994 then script will be like that
Code:
function onStepIn(cid, item, position, fromPosition)
     if item.uid == 1994 then
hope you got it untill here :confused:

now after we have added that up conditions we need to tell the server to teleport player when this condition is here so command use to tp is like that
Code:
doTeleportThing(cid, {x=xxxx, y=xxxx, z=x})
mayber some will wonder what cid is : it refers to player
explnation of this line: so this command will do th eteleport thing so the player will be tped to thiat (x,y,z)Let's say we want tp the player to the temple which pos is {x=1000, y=1000, z=7}

script will be like that
Code:
function onStepIn(cid, item, position, fromPosition)
     if item.uid == 1994 then
        doTeleportThing(cid, {x=1000, y=1000, z=7})
explain if the item have exactly that unique id, then teleport the player to that position(temple)

now we have to close the if statement and the function
so script be like that
Code:
function onStepIn(cid, item, position, fromPosition)
     if item.uid == 1994 then
        doTeleportThing(cid, {x=1000, y=1000, z=7}) 
     end
end

*Now like that the simple script have finished.let's add some options to it.

before we proceed to that let me explain somthng.
Code:
local id = 1994
local place = {x=1000, y=1000, z=7}

in scriptin local is a like a command written to give the word next to it a constant value through the script.

so in first line i wrote -local id = 1994- this mean that every <id> i write in the rest of script have that constant value which is equal to 1994.
same with -local place = {x=1000, y=1000, z=7}- means that every <place> i write in script have a constant value which is equal to {x=1000, y=1000, z=7}.

so we can change the script up to be like that:
Code:
local [B]id[/B] =1994
local [B]place[/B] =  {x=1000, y=1000, z=7}
function onStepIn(cid, item, position, fromPosition)
   if item.uid == [B]id[/B] then
      doTeleportThing(cid, [B]place)[/B]
   end
end

you got it, the words in bold up we gave them a constant values by using local and replaced the values down in script with thos words (this is useful in two ways, easier to edit if you made a script and want ppl to fst edit it they wll only change values beside local.And you can right them before yu writgh script to safe time )

-Now lets add 2 things to script to make only a player with certain level or group or both of them can use this script.

ok for group id we add these 2 lines:

Code:
local group = put here the number of the group id
 
 
if getPlayerGroupId(cid) == group then

if you want to know from where to know the group id then go to you server folder then data --> XML --> groups.xml.

And for level we add
Code:
local leve = level u need to use this tp
 
 
if getPlayerLevel(cid) >= level then

ok,let's explain that sign thing

Code:
< 50 -- lower level then 50.
> 50 then -- higher level then 50.
<= 50 then -- lower or the same level as 50.
>= 50 then -- higher level or same level as 50
~= 50 then -- if the Player doesn't have level 50.
== 50 then -- only if the Player has level 50 exactly.

Also if you want to add only males or females can use it:
Code:
local sex =        --- type sextype here < [B]0>[/B] or <[B]1>   (1) is mail  (0) is femal[/B]
 
if getPlayerSex(cid) == sex

As we have many if statment we can start a line with if and then between the commands we can write <and> so will be like that
Code:
if item.uid == id [COLOR=black]and getPlayerGroupId(cid) >= group and getPlayerLevel(cid) >= level getPlayerSex(cid) == sex then[/COLOR]
you sow we can just write an if and then an <and> between command then at last we wright <then> to show what happens if this condition are here.

so script wil be like that
Code:
local id =1000       -- the unique id of the item
local place =  {x=118, y=123, z=7}   --place where tp will teleport player
local group = 6   --required group id here only gods
local level = 1   ---require level
local sex = 0    -- male(1) , female(0)
function onStepIn(cid, item, position, fromPosition)
     if item.uid == 1000 and getPlayerGroupId(cid) >= group and getPlayerLevel(cid) >= level and getPlayerSex(cid) == sex then
     doTeleportThing(cid, place)
  end
end

what if we want to make when the player is teleported a magic effect appear :
Code:
doSendMagicEffect(getPlayerPosition(cid), 10)

what is getPlayerPosition(cid)??
we use this so the magiceffect will appear on the place where the player stands on.
now 10 is the magic effect type (here it is the tp effect)

so we will add this line here
Code:
local id =1000       -- the unique id of the item
local place =  {x=118, y=123, z=7}   --place where tp will teleport player
local group = 6   --required group id here only gods
local level = 1   ---require level
local sex = 0    -- male(1) , female(0)
function onStepIn(cid, item, position, fromPosition)
     if item.uid == 1000 and getPlayerGroupId(cid) >= group and getPlayerLevel(cid) >= level and getPlayerSex(cid) == sex then
     doTeleportThing(cid, place)
     doSendMagicEffect(getPlayerPosition(cid), 10)
  end
end

So what if we want to send a cancel message if the player dont have this conditions so we use this word:
Code:
local cancelmessage = ""         -- here you type the cancl message that will appear to players when they don't have the required condition
 
 
 
else    --- if this conditions arn't here then
   doPlayerSendCancel(cid, cancel message)
dont forget to put the messag betwen "" this.

Script will be like that
Code:
local id =1000       -- the unique id of the item
local place =  {x=118, y=123, z=7}   --place where tp will teleport player
local group = 6   --required group id here only gods
local level = 1   ---require level
local sex = 0    -- male(1) , female(0)
local cancelmessage = "Sorry,You don't have the required conditions, level(1000),sex,group(gm)."         -- here you type the cancl message that will appear to players when they don't have the required condition
function onStepIn(cid, item, position, fromPosition)
     if item.uid == 1000 and getPlayerGroupId(cid) >= group and getPlayerLevel(cid) >= level and getPlayerSex(cid) == sex then
     doTeleportThing(cid, place)
  doSendMagicEffect(getPlayerPosition(cid), 10)
  else 
     doPlayerSendCancel(cid, cancel message)
  end
end
.

now we have end the script.Hope you learned somthng. :p

If I hlped Feel free to add Rep++. :blink:
 
Last edited:
Ugly tutorial.


Poor examples.
Code:
function onStepIn(cid, item, position, fromPosition)
     if item.uid == 1994 then
        doTeleportThing(cid, {x=1000, y=1000, z=7}) 
     end
end

What the fuck is that?
You can just use:
Code:
function onStepIn(cid, item, position, fromPosition)
	doTeleportThing(cid, {x=1000, y=1000, z=7})
	return true
end
 
omg what the fuxk are you sAYING READ REST OF TOUTORIAL NOOB.oNLY FUCKERS WHO SAY THAT NUB.
 
I don't wanna read the whole sux tutorial, sorry.
 
Don't cry? What's the point of using if item.uid == xXxPorn then while it's used in script one time, and already refferenced by .xml file?
 
AND I HAVE WRITED IF ITEM.UID TO deffrenciate between this item and others of same kind so not all of them tp lol
 
So write about it? You don't gave example with more than one.
 
then: like i have said before the item i use is a chair (id=9445) so what if you want only a chair in a chosen postion to do the tp thing but you dont want all the chairs of same kind you put in map to tp player.I quess you will think "I have to put a special mark to the needed chair".Yes that is right,but how to put special mark in server??
ok to put a special mark to an item you use this command


reaeed
 
Put chair on map with UniqueID = 6666.
Then:
Code:
<action uniqueid="6666" event="script" value="name.lua"/>

name.lua:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	doTeleportThing(cid, {x=,y=,z=})
	return true
end

if not used, huh?
 
blablabalbal and so what. lol,same but just added inside the script have a life man lol
 
cuzzz i didnt say to add it when i said to add this line in the movement.xml
Code:
<movevent type="StepIn" itemid="9445" event="script" value="custom tele.lua"/>
 
man is this rlly differ a lot with you :/ lol. it is only a line any way ppl can learn from it that his is the command written to get the uid of the item :).
 
Code:
local ourVaribleWithItemUID = item.uid
:F

And yes, it's big different for me. You should not learn peoples how to use useless clauses.
 
and what you said about adding in movement .xml i cant made it work soo in this way i find my script worked and i explained it to ppl and it will work with them too lol
 
@Topic,
I say, "Nice Try." :huh:
There is always room for learning though...
 
Back
Top