• 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.
 
LUA:
function onStepIn(cid, item, pos)
        doRelocate(pos,{x=1025, y=985, z=7})
		doSendMagicEffect({x=1025, y=985, z=7}, CONST_ME_ENERGYAREA)
end

According to Cykotitan, doRelocate is better. No idea why.
 
I'm making a monster spell its meant to be a polymorph with my custom monsters (looktypes)
But its not working :( idk why i still sucking at this
LUA:
local combat, area = createCombatObject(), createCombatArea(AREA_SQUARE1X1)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_ENERGYAREA)
setCombatArea(combat, area)

local condition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(condition, CONDITION_PARAM_TICKS, 20000)

n = math.random(100)
if n <= 10 then 
addOutfitCondition(condition, {lookTypeEx = 60})
elseif n > 10 or <= 20 then
addOutfitCondition(condition, {lookTypeEx = 116})
elseif n > 20 or <= 30 then
addOutfitCondition(condition, {lookTypeEx = 21})
elseif n > 30 or <= 40 then
addOutfitCondition(condition, {lookTypeEx = 111})
elseif n > 40 or <= 50 then
addOutfitCondition(condition, {lookTypeEx = 45})
elseif n > 50 or <= 60 then
addOutfitCondition(condition, {lookTypeEx = 32})
elseif n > 60 or <= 70 then
addOutfitCondition(condition, {lookTypeEx = 106})
elseif n > 70 or <= 100 then
addOutfitCondition(condition, {lookTypeEx = 399})
end

setCombatCondition(combat, condition)
function onCastSpell(cid, var)
	return doCombat(cid, combat, var)
end
 
LUA:
function onStepIn(cid, item, position, fromPosition)
             doTeleportThing(cid, fromPosition, FALSE)
             doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
	 doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
         doPlayerSendTextMessage(cid, 22, "Your Text here.")
         end
return true
end

goto data/movements open movements.xml and paste
actiondid="xxx" is your id tile.. name.lua ,name script
LUA:
  <movevent type="StepIn" actionid="xxx" event="script" value="name.lua"/>

edit online this part:
LUA:
1º doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) ---- effect example for energy  doSendMagicEffect(getPlayerPosition(cid), CONST_ME_ENERGYAREA)

2º doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)  ---- effect example CONST_ME_MAGIC_BLUE) or CONST_ME_MAGIC_POFF) ,etc..

3º doPlayerSendTextMessage(cid, 22, "Your Text here.")  ---  cid, 22 is effect .. example say /z 1 in your ot /z 2, etc. 
effect 2 is change cid, 2 , etc.. all effect change only need change number.. for look effect say /z 1, /z 2, etc!
Your text - text send player step in tile

NOTE: for only tile vip is
change
LUA:
function onStepIn(cid, item, position, fromPosition)

to

LUA:
function onStepIn(cid, item, position, fromPosition)
         if getPlayerVipDays(cid) == 1 then
 
Last edited:
LUA:
function onStepIn(cid, item, position, fromPosition)
             doTeleportThing(cid, fromPosition, FALSE)
             doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
	 doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
         doPlayerSendTextMessage(cid, 22, "Your Text here.")
         end
return true
end

goto data/movements open movements.xml and paste
actiondid="xxx" is your id tile.. name.lua ,name script
LUA:
  <movevent type="StepIn" actionid="xxx" event="script" value="name.lua"/>

edit online this part:
LUA:
1º doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) ---- effect example for energy  doSendMagicEffect(getPlayerPosition(cid), CONST_ME_ENERGYAREA)

2º doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)  ---- effect example CONST_ME_MAGIC_BLUE) or CONST_ME_MAGIC_POFF) ,etc..

3º doPlayerSendTextMessage(cid, 22, "Your Text here.")  ---  cid, 22 is effect .. example say /z 1 in your ot /z 2, etc. 
effect 2 is change cid, 2 , etc.. all effect change only need change number.. for look effect say /z 1, /z 2, etc!
Your text - text send player step in tile

NOTE: for only tile vip is
change
LUA:
function onStepIn(cid, item, position, fromPosition)

to

LUA:
function onStepIn(cid, item, position, fromPosition)
         if getPlayerVipDays(cid) == 1 then

Lol thanks for all that but i already done that xD thanks anyways

And if I have 2 vip days I can't pass, /;

@On:
LUA:
elseif n > 10 or <= 20 then

Change all to
LUA:
elseif n > 10 or n <= 20 then

Yeap znote told me that, and also find for myself the bug with the oncastspell xd

If some one wants it here it is, its the spell for "Incredibly Old Witch"


LUA:
local combat, area = createCombatObject(), createCombatArea(AREA_SQUARE1X1)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_ENERGYAREA)
setCombatArea(combat, area)

local condition = createConditionObject(CONDITION_OUTFIT)
setConditionParam(condition, CONDITION_PARAM_TICKS, 20000)

function onCastSpell(cid, var)
n = math.random(1,100)
if n <= 10 then 
addOutfitCondition(condition, {lookType = 60})
elseif n > 10 and n <= 20 then
addOutfitCondition(condition, {lookType = 116})
elseif n > 20 and n <= 30 then
addOutfitCondition(condition, {lookType = 21})
elseif n > 30 and n <= 40 then
addOutfitCondition(condition, {lookType = 111})
elseif n > 40 and n <= 50 then
addOutfitCondition(condition, {lookType = 45})
elseif n > 50 and n <= 60 then
addOutfitCondition(condition, {lookType = 32})
elseif n > 60 and n <= 70 then
addOutfitCondition(condition, {lookType = 106})
elseif n > 70 and n <= 100 then
addOutfitCondition(condition, {lookType = 399})
end
setCombatCondition(combat, condition)
	return doCombat(cid, combat, var)
end

Thanks to znote, and evil puncker who help me with the script :P
 
@Santi
loool? you not understand scripts eeh?
And if I have 2 vip days I can't pass, /; lOL - Fail!
If getplayevipdays is. for only pass -- This stops working when you run out of VIP, you can go if you have 1 day or more VIP for enter vip zone.. no edit line is your error santi (:
is
LUA:
if getPlayerVipDays(cid) == 0 then
or
LUA:
if getPlayerVipDays(cid) == 1 then

elseif n > 10 or <= 20 then
only players 10 + vip days enter.. i have 9 and dont enter more -.^?
 
@Santi
loool? you not understand scripts eeh?
And if I have 2 vip days I can't pass, /; lOL - Fail!
If getplayevipdays is. for only pass -- This stops working when you run out of VIP, you can go if you have 1 day or more VIP for enter vip zone.. no edit line is your error santi (:
is
LUA:
if getPlayerVipDays(cid) == 0 then
or
LUA:
if getPlayerVipDays(cid) == 1 then

elseif n > 10 or <= 20 then
only players 10 + vip days enter.. i have 9 and dont enter more -.^?

Okay.. I tried my best to understand what you said, still, its your fail.
the custom function getPlayerVipDays(cid) will return an int value, meaning a number.
So... I have 2 vip days.
LUA:
if getPlayerVipDays(cid) == 1 then
Will be:
LUA:
 if 2 == 1 then
So the statement is false! Omg! I was right!

EDIT:
you can go if you have 1 day or more VIP for enter vip zone
LUA:
>=
 
test again here you go :P
LUA:
function onStepIn(cid, item, position, fromPosition)
         if getPlayerVipDays(cid) == 0 then
             doTeleportThing(cid, fromPosition, FALSE)
             doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
	 doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
         doPlayerSendTextMessage(cid, 22, "Only vip account players can go there.")
         end
return true
end

@up
Yee is true.. is function edit .. need add functions and querys /: i fail jsjs! ;p!
vipdays.. :O
 
Last edited:
Back
Top