function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
local spellbook = 6120
local levReq = 20
if(getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == spellbook or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == spellbook) then
if(getPlayerLevel(cid) >= levReq) then
return true
else
doTeleporThing(cid, fromPosition)
doPlayerSendCancel(cid, "Sorry, you haven't reached level ".. levReq .." yet.")
return false
end
else
doTeleporThing(cid, fromPosition)
doPlayerSendCancel(cid, "Sorry, you have to equip ".. getItemInfo(spellbook).article .." ".. getItemInfo(spellbook).name .." to enter this teleport.")
return false
end
return true
end
onStepIn
if cid has X item and is level 20+ then
teleport cid to x teleport
else
teleport cid to fromPosition
prompt error
end
end
It's really simple, you should start learning to write Lua.
Since you're dealing with something that is caused by stepping into something, we know it has to be a movement script.
Basically, you really have to come up with an algorithm before you start scripting.
Lua:onStepIn if cid has X item and is level 20+ then teleport cid to x teleport else teleport cid to fromPosition prompt error end end
EDIT: Oh OTx already posted it, well, you can still look at my post to learn
By the way, his script won't work.
attempt to call global 'doTeleportThing' <a nil value>
Well, it's pretty easy to fix, just change doTeleporThing to doTeleportThing.
Also, this script checks if the spellbook is in your hands ONLY, not in your backpack or anywhere else on you.
Other than that, it looks like a good working script.
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
local spellbook = 6120
local levReq = 8
if(getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == spellbook or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == spellbook) then
if(getPlayerLevel(cid) >= levReq) then
return true
else
doTeleportThing(cid, fromPosition)
doPlayerSendCancel(cid, "You need level ".. levReq .." to enter this portal.")
return false
end
else
doTeleportThing(cid, fromPosition)
doPlayerSendCancel(cid, "You have to bring a ".. getItemInfo(spellbook).article .." ".. getItemInfo(spellbook).name .." to enter this portal.")
return false
end
return true
end
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
local spellbook = 6120
local levReq = 20
local newPos = {x = XXX, y = XXX, z = XXX}
if(getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == spellbook or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == spellbook) then
if(getPlayerLevel(cid) >= levReq) then
doTeleportThing(cid, newPos)
else
doTeleportThing(cid, fromPosition)
doPlayerSendCancel(cid, "Sorry, you haven't reached level ".. levReq .." yet.")
end
else
doTeleportThing(cid, fromPosition)
doPlayerSendCancel(cid, "Sorry, you have to equip ".. getItemInfo(spellbook).article .." ".. getItemInfo(spellbook).name .." to enter this teleport.")
end
return true
end
Use [lua][/lua] tags next time when you post Lua scripts.
Try this (don't forget to change the coordinates):
Lua:function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor) local spellbook = 6120 local levReq = 20 local newPos = {x = XXX, y = XXX, z = XXX} if(getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == spellbook or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == spellbook) then if(getPlayerLevel(cid) >= levReq) then doTeleportThing(cid, newPos) else doTeleportThing(cid, fromPosition) doPlayerSendCancel(cid, "Sorry, you haven't reached level ".. levReq .." yet.") end else doTeleportThing(cid, fromPosition) doPlayerSendCancel(cid, "Sorry, you have to equip ".. getItemInfo(spellbook).article .." ".. getItemInfo(spellbook).name .." to enter this teleport.") end return true end