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

LevelReq + Item on Teleport?

Synergy

New Member
Joined
Nov 24, 2011
Messages
334
Reaction score
0
How do I do this?

I want the player to have a item on him & level 20, if so he can enter the teleport?
 
Here you are. Hope it works :)
Lua:
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
 
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.
 
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.


Haven't tried his yet, why won't it work?

- - - Updated - - -

yep, I got the error:

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.
 
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.

+ There is no destination IF you have the required stuff? :S
And when I put destination on map editor, it teleports u even if u go in without spellbook lol
 
Well, his script assumed you had the destination set in the teleport on mapeditor.
Basically, if you have the required stuff, it would return true and let you go in the teleport.

Give me your script that you added the destination to.
 
Now I got no destination in the map editor, only the action id on the teleport which is connected to the movement 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
 
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
 
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



Works perfectly, thanks Evan.

You could even check out my Lua problem on the first script I attempted to do by myself :p in "support" section
 
Back
Top