• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Help me learn lua

Core_

Well-Known Member
Joined
Jul 9, 2010
Messages
1,557
Solutions
1
Reaction score
50
Well, i thought i need to learn lua, i find it kinda easy, but there are some things i just cant understand or i cant make them work, so i hope you can help me with my doubts.

_______________________________
  • What CID means?

Like here:
function onStepIn(cid, item, pos, fromPos), i think all that stuff (cid, item, pos~) its what the script calls right? like the script will use a item, a position etc.... but what cid means? my first guess is like creature id (the player that use the script).
_______________________________

Ok, so i'm making this script, when you step in a tile you'll be teleported to another tile (i dont want to use tp's thanks), i'll use it just in a few parts of the map like shortcuts in the city....

So thats my script

LUA:
function onStepIn(cid, pos, fromPos)
        doTeleportPlayer(cid,1025,985,7,CONST_ME_ENERGYAREA) 
        return false
end

I'ts not working on the latest 0.4.... :( i wish some one can tell me why, maybe doTeleportPlayer is no longer supported... but i couldnt find another function for teleport

:) thats all for now i hope you can help me with this basic things.
 
lmao, first of all instead of 1025, 985, 7 use {x=1025, y=985, z=7}
and the CONST_ME_ENERGYAREA
should be on
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_ENERGYAREA)
so it would be like
LUA:
function onSetpIn(cid, item, pos, fromPos)
        doTeleportThing(cid,{x=1025, y=985, z=7})
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_ENERGYAREA)
        return TRUE
end
 
Last edited:
lmao, first of all instead of 1025, 985, 7 use {x=1025, y=985, z=7}
and the CONST_ME_ENERGYAREA
should be on
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_ENERGYAREA)
so it would be like
LUA:
function onSetpIn(cid, pos, fromPos)
        doTeleportThing(cid,{x=1025, y=985, z=7})
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_ENERGYAREA)
        return TRUE
end

:P ok, the cid thing in doTeleportThing means it will teleport the player?


Code:
local place = {x= 95, y= 117, z= 7}
function onStepIn(cid, item, pos, fromPos)
		doTeleportThing(cid, place) 
			doSendMagicEffect(place, CONST_ME_ENERGYAREA)
			end
there you can learn some lua

:D i knew how that things work (local place) like variables :P how are they called?
 
:p already learn something thanks guys!
another noobie thing
<movevent type="StepIn" itemid="3196" event="script" value="custom/shortcuttp.lua"/>
if i put like actionid instead of itemid and i set a action id to a normal tile will it work?
 
:p already learn something thanks guys!
another noobie thing
<movevent type="StepIn" itemid="3196" event="script" value="custom/shortcuttp.lua"/>
if i put like actionid instead of itemid and i set a action id to a normal tile will it work?

yes
 
lmao, first of all instead of 1025, 985, 7 use {x=1025, y=985, z=7}
and the CONST_ME_ENERGYAREA
should be on
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_ENERGYAREA)
so it would be like
LUA:
function onSetpIn(cid, item, pos, fromPos)
        doTeleportThing(cid,{x=1025, y=985, z=7})
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_ENERGYAREA)
        return TRUE
end

broken script, enjoy errors

Remember! Always Test! before posting! That's a must on learning LUA
 
Mmmm the last script worked fine but i had to make 2, 1 for go from x pos to y pos and another one to go from y pos to x pos, so i tried to make it in only one script.

But no success :( i just suck in this D:

LUA:
local config = {
	temple =
	{
		{x = 1005, y = 999, z = 7}
	},
	temple1 =
	{
		{x = 1006, y = 999, z = 7}
	},
	shops =
	{
		{x = 1024, y = 985, z = 7}
	},
	shops1 =
	{
		{x = 1025, y = 985, z = 7}
	}
}
function onStepIn(cid, item, pos, fromPos)
	if getThingPos(cid) == temple then 
		doTeleportThing(cid, shops1) 
		doSendMagicEffect(cid, CONST_ME_MAGIC_GREEN)
elseif getThingPos(cid) == shops then
		doTeleportThing(cid, temple1) 
		doSendMagicEffect(cid, CONST_ME_MAGIC_GREEN)
end
	end

idk wats wrong with it :s maybe some function or something but idont get any error in the console..
also i had to make shops and shops1, idk how to make it like doTeleportThing(cid, shops {x + 1}) or something like that D:
 
your script is not written incorrectly, it just contains logic errors, think about what you want it to do and what you just told it to do - it doesn't match up. These kinds of errors are the aggravating and frustrating ones you'll run into, so learn how to overcome them :)
 
Besides you cant even compare tables like that. use doComparePositions
How does it work?

:( where do i find those functions i'm trying to do it like, if tileid = xx then tp to shops ...... but i cant find a function for that D:
getTileItemById(pos, itemId[, subType = -1])
getTileItemByType(pos, type)
getTileThingByPos(pos)
getTileInfo(pos)
would one of those help?
 
Last edited:
If you are using
LUA:
function onStepIn(cid, item, pos, fromPos)

You can get tile id by:
Code:
function onStepIn(cid, [COLOR="#FF0000"]item[/COLOR], pos, fromPos)
	if [COLOR="#FF0000"]item[/COLOR].itemid == 6458 then	
		............
		............
 
Last edited:
If you are using
LUA:
function onStepIn(cid, item, pos, fromPos)

You can get tile id by:
Code:
function onStepIn(cid, [COLOR="#FF0000"]item[/COLOR], pos, fromPos)
	if [COLOR="#FF0000"]item[/COLOR].itemid == 6458 then	
		............
		............

Thanks! works now, now i got 2 options this one or 2scripts in one i guess is best only one.
LUA:
local temple = {x = 1006, y = 999, z = 7}
shops = {x = 1025, y = 985, z = 7}
function onStepIn(cid, item, pos, fromPos)
	if item.itemid == 3188 then
		doTeleportThing(cid, shops) 
		doSendMagicEffect(shops, CONST_ME_MAGIC_GREEN)
	elseif item.itemid == 3196 then 
		doTeleportThing(cid, temple) 
		doSendMagicEffect(temple, CONST_ME_MAGIC_GREEN)
	end
	end

or 2 of this
LUA:
local place = {x= 1006, y= 999, z= 7}
function onStepIn(cid, item, pos, fromPos)
		doTeleportThing(cid, place) 
			doSendMagicEffect(place, CONST_ME_MAGIC_GREEN)
end

:P
 
Back
Top