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

Teleport to post if needed eq is on

Kernel

Tibera!
Joined
Apr 30, 2009
Messages
57
Reaction score
0
yo! I was searching all around a script that would teleport a player if he steps on special tile only if he has required eq on.
In my case, it is helmet.

so...Player steps on tile with helmet and gets teleported somewere, if he does not have helmet, hes teleported too(to other pos) and gets a messege. I think it should not be hard.


Thank you.
 
Lua:
function isItemEquipped(cid, slot, itemid) 
    -- Function by Colandus
    if(isPlayer(cid) == FALSE) then
        return LUA_ERROR
    end

    return (getPlayerSlotItem(cid, slot).itemid == itemid) and TRUE or FALSE
end

Take that function and use it as such:
Lua:
if(isItemEquipped(cid, CONST_SLOT_HEAD, 1939) == TRUE) then
   -- code if item is in head!
end

Now, I just typed a random number for itemid, I don't know what that item is :p

Also you could need this function as well:
Lua:
function hasPlayerWeapon(cid, itemid)
    -- Function by Colandus
    return (isItemEquipped(cid, CONST_SLOT_RIGHT, itemid) == TRUE or isItemEquipped(cid, CONST_SLOT_LEFT, itemid) == TRUE) and TRUE or FALSE
end

Or a bit more readable:
Lua:
function hasPlayerWeapon(cid, itemid)
    -- Function by Colandus
    local ret = isItemEquipped(cid, CONST_SLOT_RIGHT, itemid)
    return bit.bor(ret, isItemEquipped(cid, CONST_SLOT_LEFT, itemid))
end

That would check if he's got a certain item in his hands, you could check for weapons, shields or any item you want...
 
Last edited:
Thank you so far, but I didn't admit I am total newbie in lua. How can I add the teleport function+player recieves msg? Or it would be better if someone made all script. Lua is fucking hard, where do you guys learn it? :eek: :s
 
@up, lua is actually quite easy I find compared to some other languages Ive used (C++). Anyway heres the code...

Lua:
  function isItemEquiped(cid, slot, itemid)
    -- Function by Colandus
    if(isPlayer(cid) == FALSE) then
        return LUA_ERROR
    end

    return (getPlayerSlotItem(cid, slot).itemid == itemid) and TRUE or FALSE
end

function onStepIn(cid, item, pos, frompos)
    itemid = XXXX -- Id of the item
    slot = XXXX -- Slot of the item
    tp = {x=??, y=??, z=??} -- Position to teleport them to
    message = "Blah!" -- Message sent to the player
    if isItemEquipped(cid, slot, itemid) == TRUE then
        doTeleportThing(cid, tp)
        doSendPlayerTextMessage(cid, 22, message)
    end
    return TRUE
end

That should work fine :) Just change the XXXX, ??, and Blah!, to what you want them to be.
 
@up
Ehm... I added this line to my movements.xml:

Code:
	<movevent type="StepIn" itemid="8632" event="script" value="Yalaharunderwater.lua"/>

and this is the Yalaharunderwater.lua:
Lua:
  function isItemEquiped(cid, slot, itemid)
    -- Function by Colandus
    if(isPlayer(cid) == FALSE) then
        return LUA_ERROR
    end

    return (getPlayerSlotItem(cid, slot).itemid == itemid) and TRUE or FALSE
end

function onStepIn(cid, item, pos, frompos)
    itemid = 5461 -- Id of the item
    slot = head -- Slot of the item
    tp = {x=748, y=582, z=9} -- Position to teleport them to
    message = "You need helmet of the deep to dive in!" -- Message sent to the player
    if isItemEquipped(cid, slot, itemid) == TRUE then
        doTeleportThing(cid, tp)
        doSendPlayerTextMessage(cid, 22, message)
    end
    return TRUE
end

I spammed item/tile 863(whirlpool) on ground with my gm and stepped on it, but than recieved long error on console:




I guess its the script fault, or I did something wrong?


PS. It also would be nice if u told me what u did when fixed it, cuz I wanna know. And yeah, how and when did you start learning lua?
 
Set it to local function isItemEquipped

EDIT: Actually, change head to CONST_SLOT_HEAD

Edit2: Like 2 - 3 weeks ago and coz I wanted to make a totally custom ot.

This is what it should look like
Lua:
local function isItemEquiped(cid, slot, itemid)
    -- Function by Colandus
    if(isPlayer(cid) == FALSE) then
        return LUA_ERROR
    end
    return (getPlayerSlotItem(cid, slot).itemid == itemid) and TRUE or FALSE
end

function onStepIn(cid, item, pos, frompos)
    itemid = 5461 -- Id of the item
    slot = CONST_SLOT_HEAD -- Slot of the item
    tp = {x=748, y=582, z=9} -- Position to teleport them to
    message = "You need helmet of the deep to dive in!" -- Message sent to the player
    if isItemEquipped(cid, slot, itemid) == TRUE then
        doTeleportThing(cid, tp)
        doSendPlayerTextMessage(cid, 22, message)
    end
    return TRUE
end

Edit3: All I did was change function isItemEquipped to local function isItemEquipped, since there are locals and globals. I also changed head to CONST_SLOT_HEAD (Since CONST_SLOT_HEAD is a number (2 I think), and head is nothing.
 
Last edited:
Exactly the same error. Maybe I am doing something wrong? Maybe that tile works only when it is added in map editor, not spammed with gm or it has to have uniq id?

3weeks? :eek: cool. How should I start learning it?
 
Last edited:
I found whats wrong!
Lua:
if isItemEquipped(cid, slot, itemid) == TRUE then
Should be...
Lua:
if isItemEquiped(cid, slot, itemid) == TRUE then
Stupid mistake that everyone makes. Anyway start by just looking at some of the built in scripts and you should start to see the way it works.
 
Now it tpes me to the destenation(spelling?), but the messege is not working:

Look only the last error(bottom at console)



Well but that thing this script does not do, is tp me to pos I want if I got not helmet on me. How can I add it? :eek: That will be probably something with "elseif"? :p
 
I think Ive turned blonde today! Change doSendPlayerTextMessage to doPlayerSendTextMessage, for the other part do this: before the end but after doPlayerSendTextMessage
Lua:
else
    doTeleportThing(cid, tp2)
    doPlayerSendTextMessage(cid, 22, message2)

And also set the two variables tp2 and message2.

Edit: BTW tp2 = the other position, and message2 is the other message
 
YESS!! IT WORKS!! THAN KYOU=****************

Just one last thing. I want to add so I can buy items from my captain npc, I tried to add some scsript lines but always filed. too this is my captain npc:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Captain Max" script="data/npc/scripts/theboat.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="134" head="95" body="10" legs="56" feet="77" addons="0"/>
	<parameters>
		<parameter key="module_travel" value="1" />
		<parameter key="message_greet" value="Hello |PLAYERNAME|. I can take you to: {Thais}, {Venore}, {Carlin}, {Edron}, {Ankrahmun},{ Ab dendriel}, {Port hope}, {Darashia}, {Svargrond}, {Goroma}, {Yalahar} for free." />
		<parameter key="travel_destinations" value="liberty bay,32285,32890,6,0;thais,32311,32210,6,0;venore,32954,32022,6,0;carlin,32388,31821,6,0;ab dendriel,32733,31669,6,0;ankrahmun,33092,32883,6,0;darashia,33288,32482,6,0;edron,33176,31765,6,0;port hope,32528,32784,6,0;goroma,31994,32565,6,0;svargrond,32343,31106,6,0;yalahar,601,670,6,0;" />
	</parameters>
</npc>

and this is the lua file:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) 			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) 	npcHandler:onCreatureSay(cid, type, msg) end
function onThink() 						npcHandler:onThink() end
-- OTServ event handling functions end

npcHandler:addModule(FocusModule:new())

To help you find the lines to copy/modifie I will post you my rashid npc( it sells items):

Rashid XML:


Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Rashid" script="data/npc/scripts/default.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="146" head="12" body="101" legs="122" feet="115" addons="2"/>
	<parameters>
		<parameter key="module_shop" value="1"/>
		<parameter key="shop_sellable" value="Paladin armor,8891,30000;Dragon scale mail,2492,40000;Dwarven armor,2503,30000;Golden armor,2466,20000;Leopard armor,3968,1000;Mammoth fur cape,7463,6000;Pirate shirt,6095,500;Pirate knee breeches,5918,200;Bone shield,2541,80;Castle shield,2535,5000;Dark shield,2521,400;Demon shield,2520,30000;Medusa shield,2536,9000;Scarab shield,2540,2000;Tortoise shield,6131,150;Beholder helmet,3972,7500;Devil helmet,2462,1000;Krimhorn helmet,7461,200;Pirate hat,6096,1000;Ragnir helmet,7462,400;Skull helmet,5741,40000;Crocodile boots,3982,1000;Fur boots,7457,2000;Pirate boots,5462,3000;Steel boots,2645,30000;Amber staff,7426,8000;Beastslayer axe,3962,1500;Brutetamer's staff,7379,1500;Crystal sword,7449,600;Daramanian mace,2439,110;Daramanian waraxe,2440,1000;Diamond sceptre,7387,3000;Dragon slayer,7402,15000;Dragonbone staff,7430,3000;Furry club,7432,1000;Heavy machete,2442,90;Lunar staff,7424,5000;Mammoth whopper,7381,300;Sapphire hammer,7437,7000;Silver dagger,2402,500;Taurus mace,7425,500;War axe,2454,9000;Wyvern fang,7408,1500;Ancient amulet,2142,200;Scarab amulet,2135,200;Light Shovel,5710,300;Patched Boots,2641,2000"/>
		<parameter key="shop_buyable" value=""/>
	</parameters>
</npc>

Rashid lua:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

npcHandler:addModule(FocusModule:new())

Thank you for everything, adding reputation point(15 rep points :D )
 
If you want a swap from travel to shop replace:
Lua:
		<parameter key="module_travel" value="1" />
		<parameter key="message_greet" value="Hello |PLAYERNAME|. I can take you to: {Thais}, {Venore}, {Carlin}, {Edron}, {Ankrahmun},{ Ab dendriel}, {Port hope}, {Darashia}, {Svargrond}, {Goroma}, {Yalahar} for free." />
		<parameter key="travel_destinations" value="liberty bay,32285,32890,6,0;thais,32311,32210,6,0;venore,32954,32022,6,0;carlin,32388,31821,6,0;ab dendriel,32733,31669,6,0;ankrahmun,33092,32883,6,0;darashia,33288,32482,6,0;edron,33176,31765,6,0;port hope,32528,32784,6,0;goroma,31994,32565,6,0;svargrond,32343,31106,6,0;yalahar,601,670,6,0;" />
with
Lua:
		<parameter key="module_shop" value="1"/>
		<parameter key="shop_sellable" value="Paladin armor,8891,30000;Dragon scale mail,2492,40000;Dwarven armor,2503,30000;Golden armor,2466,20000;Leopard armor,3968,1000;Mammoth fur cape,7463,6000;Pirate shirt,6095,500;Pirate knee breeches,5918,200;Bone shield,2541,80;Castle shield,2535,5000;Dark shield,2521,400;Demon shield,2520,30000;Medusa shield,2536,9000;Scarab shield,2540,2000;Tortoise shield,6131,150;Beholder helmet,3972,7500;Devil helmet,2462,1000;Krimhorn helmet,7461,200;Pirate hat,6096,1000;Ragnir helmet,7462,400;Skull helmet,5741,40000;Crocodile boots,3982,1000;Fur boots,7457,2000;Pirate boots,5462,3000;Steel boots,2645,30000;Amber staff,7426,8000;Beastslayer axe,3962,1500;Brutetamer's staff,7379,1500;Crystal sword,7449,600;Daramanian mace,2439,110;Daramanian waraxe,2440,1000;Diamond sceptre,7387,3000;Dragon slayer,7402,15000;Dragonbone staff,7430,3000;Furry club,7432,1000;Heavy machete,2442,90;Lunar staff,7424,5000;Mammoth whopper,7381,300;Sapphire hammer,7437,7000;Silver dagger,2402,500;Taurus mace,7425,500;War axe,2454,9000;Wyvern fang,7408,1500;Ancient amulet,2142,200;Scarab amulet,2135,200;Light Shovel,5710,300;Patched Boots,2641,2000"/>
		<parameter key="shop_buyable" value=""/>

Or just add the second part to the xml file if you want both.
 
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Captain Max" script="data/npc/scripts/theboat.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="134" head="95" body="10" legs="56" feet="77" addons="0"/>
	<parameters>
                <parameter key="module_shop" value="1"/>
                <parameter key="shop_sellable" value="Paladin armor,8891,30000;Dragon scale mail,2492,40000;Dwarven armor,2503,30000;Golden armor,2466,20000;Leopard armor,3968,1000;Mammoth fur cape,7463,6000;Pirate shirt,6095,500;Pirate knee breeches,5918,200;Bone shield,2541,80;Castle shield,2535,5000;Dark shield,2521,400;Demon shield,2520,30000;Medusa shield,2536,9000;Scarab shield,2540,2000;Tortoise shield,6131,150;Beholder helmet,3972,7500;Devil helmet,2462,1000;Krimhorn helmet,7461,200;Pirate hat,6096,1000;Ragnir helmet,7462,400;Skull helmet,5741,40000;Crocodile boots,3982,1000;Fur boots,7457,2000;Pirate boots,5462,3000;Steel boots,2645,30000;Amber staff,7426,8000;Beastslayer axe,3962,1500;Brutetamer's staff,7379,1500;Crystal sword,7449,600;Daramanian mace,2439,110;Daramanian waraxe,2440,1000;Diamond sceptre,7387,3000;Dragon slayer,7402,15000;Dragonbone staff,7430,3000;Furry club,7432,1000;Heavy machete,2442,90;Lunar staff,7424,5000;Mammoth whopper,7381,300;Sapphire hammer,7437,7000;Silver dagger,2402,500;Taurus mace,7425,500;War axe,2454,9000;Wyvern fang,7408,1500;Ancient amulet,2142,200;Scarab amulet,2135,200;Light Shovel,5710,300;Patched Boots,2641,2000"/>
                <parameter key="shop_buyable" value=""/>
		<parameter key="module_travel" value="1" />
		<parameter key="message_greet" value="Hello |PLAYERNAME|. I can take you to: {Thais}, {Venore}, {Carlin}, {Edron}, {Ankrahmun},{ Ab dendriel}, {Port hope}, {Darashia}, {Svargrond}, {Goroma}, {Yalahar} for free." />
		<parameter key="travel_destinations" value="liberty bay,32285,32890,6,0;thais,32311,32210,6,0;venore,32954,32022,6,0;carlin,32388,31821,6,0;ab dendriel,32733,31669,6,0;ankrahmun,33092,32883,6,0;darashia,33288,32482,6,0;edron,33176,31765,6,0;port hope,32528,32784,6,0;goroma,31994,32565,6,0;svargrond,32343,31106,6,0;yalahar,601,670,6,0;" />
	</parameters>
</npc>
 
I found whats wrong!
Lua:
if isItemEquipped(cid, slot, itemid) == TRUE then
Should be...
Lua:
if isItemEquiped(cid, slot, itemid) == TRUE then
Stupid mistake that everyone makes. Anyway start by just looking at some of the built in scripts and you should start to see the way it works.

Actually you should have changed functions name to isItemEquipped instead of changing the if-statement, because I spelled wrong :p
 
Mine is working perfect:
Lua:
function onStepIn(cid, item, pos)
    local checkhelm = getPlayerSlotItem(cid, 1)
    local yesway_pos = { x = 32950, y = 31182, z = 9 } -- where to be tped if they have the storage
    local noway_pos = { x = 32950, y = 31180, z = 6 } -- where to be tped if they do not have the storage

     if checkhelm.itemid == 5461 then
         doTeleportThing(cid, yesway_pos)
	 doCreatureSay(cid, "Diving.", TALKTYPE_ORANGE_1)
    else
         doTeleportThing(cid, noway_pos)
		 doCreatureSay(cid, "You need a helmet of the deep to dive here.", TALKTYPE_ORANGE_1)
    end
end
 
Here is my Captain Max, sells Helmet of the deep and can take you to calassa(if you have the real cordinates you don't have to edit the xyz :p)
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Captain Max" script="data/npc/scripts/travel.lua" walkinterval="0" floorchange="0" access="5" level="1" maglevel="1">
	<health now="150" max="150"/>
	<look type="134" head="95" body="9" legs="58" feet="77" corpse="2212"/>
	<parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|." />
		<parameter key="module_shop" value="1" />
		<parameter key="shop_buyable" value="helmet of the deep,5461,5000" />
		<parameter key="module_travel" value="1" />
		<parameter key="travel_destinations" value="calassa,31916,32710,6,200;liberty bay,32298,32895,6,0" />
	</parameters>
</npc>
 
Back
Top