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

Lua Question

Cloow

Active Member
Joined
May 10, 2010
Messages
1,086
Reaction score
35
Alright, i made a quick script. My first one actually.

Here is my question, if i want the line
if item.itemid == 59281 then
To be UID instead of itemID what should i do?


Also, when im trying to start the server with my script i get this error
16h2sci.png
and i can't just see what i have done wrong.







PHP:
local t = 
{
      monster = "Monster"
	  pos = {x=967, y=1007, z=7},
	  msg = "Monster appears right infront of your eyes!!"
	  tpos = {x=967, y=1007, z=7},
	  cpod = {x=960, y=1007, z=7},
	  bmsg = "How dare you?!"
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
       if item.itemuid == 59281 then
         doSummonCreature(t.monster,t.pos)
		  doCreatureSay(cid, t.msg, TALKTYPE_ORANGE_1)
		   doCreateTeleport(1387, t.tpos, t.cpos)
		     doBroadcastMessage(t.bmsg, TALKTYPE_RED_1)
		    return TRUE
     end
end


If you see any errors, wich will not work when im testing this. I would love to know em =>

Soon enough im gonna be pro on scripting !
 
Code:
local t = 
{
      monster = "Monster",
      pos = {x=967, y=1007, z=7},
      msg = "Monster appears right infront of your eyes!!",
      tpos = {x=967, y=1007, z=7},
      cpod = {x=960, y=1007, z=7},
      bmsg = "How dare you?!"
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
       if item.uid == 59281 then
         doSummonCreature(t.monster,t.pos)
          doCreatureSay(cid, t.msg, TALKTYPE_ORANGE_1)
           doCreateTeleport(1387, t.tpos, t.cpos)
             doBroadcastMessage(t.bmsg, TALKTYPE_RED_1)
     end
return TRUE
end

it's item.uid

also, you don't really need it... just register it in actions.xml with "actionuid"
 
UID/AID = ex. quest chest.
while id = is the id of the item ex.

Lua:
 if item.id == 2160 then
  return doCreature......
end
 
Alright, i've tested the script now. Almost everything works.

But this line just dont want to work

PHP:
      doCreateTeleport(1387, t.tpos, t.cpos)
             doBroadcastMessage(t.bmsg, TALKTYPE_RED_1)

Why that ?

Also i can just pull the switch once.
 
Code:
local t = 
{
      monster = "Monster"
      pos = {x=967, y=1007, z=7},
      msg = "Monster appears right infront of your eyes!!"
      tpos = {x=967, y=1007, z=7},
      [B]cpod[/B] = {x=960, y=1007, z=7},
      bmsg = "How dare you?!"
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.uid == 59281 then
        doSummonCreature(t.monster,t.pos)
        doCreatureSay(cid,t.msg,TALKTYPE_ORANGE_1)
        doBroadcastMessage(t.bmsg)
	doCreateTeleport(1387,t.tpos,t.[B]cpod[/B])
    end
    return true
end

in the doCreateTeleport you've given the wrong local, you used cpos instead of cpod.

Also with doBroadcastMessage you don't need to define the color.

Also, I suggest you to use the TAB button instead of using space
 
Hey guys, i got another question.

doPlayerPopupFYI(cid,msg)
This CID what does that mean ? It's here to
function onLogin(cid)


Ahh, another one.

can someone explain to me, why is these important ?

function onUse(cid, item, fromPosition, itemEx, toPosition)
I mean it's not used in scripts anyway.







doPlayerAddMapMark(cid, pos, type[, description])
type ? Wich mean? It's it like effects ?




Here's one to

4qo10y.png



PHP:
local t = 
{     
      msg = "TEXT"
      pos = {x=693, y=1007, z=7},
	  typ = 
}	   
	   
function onLogin(cid)
  doPlayerPopupFYI(cid, t.msg)
    doPlayerAddMapMark(cid, t.pos, t.typ)
	end
	return TRUE
end

I can't just see where it is to close ?
 
Last edited:
The CID means creature ID, also know as the person for which the action is executed.

So in your cases the cid is for a player who activates a script.

--

function onUse(cid, item, fromPosition, itemEx, toPosition)

You can leave it out, but I suggest you not to as you might reconsider to change something in the script that DOES use it.

--

doPlayerAddMapMark(cid, pos, type[, description])

I'm not sure about this one, but I'm guessing that it's the type of icon.
 
The CID means creature ID, also know as the person for which the action is executed.

So in your cases the cid is for a player who activates a script.

--

function onUse(cid, item, fromPosition, itemEx, toPosition)

You can leave it out, but I suggest you not to as you might reconsider to change something in the script that DOES use it.

--

doPlayerAddMapMark(cid, pos, type[, description])

I'm not sure about this one, but I'm guessing that it's the type of icon.


So the CID is kinda important ? So in my case
PHP:
doPlayerPopupFYI(cid, t.msg)
I got to type the CID of the starter outfit there ?


NOTE: I updated the post @up
 
Code:
local t = 
{     
      msg = "TEXT"[B][COLOR="Red"],[/COLOR][/B]
      pos = {x=693, y=1007, z=7},
      typ = 0 -- I guess :|
}       
       
function onLogin(cid)
  doPlayerPopupFYI(cid, t.msg)
    doPlayerAddMapMark(cid, t.pos, t.typ)
    end
    return TRUE
end
 
cid means Creature ID, which means the player himself - so if you put "cid" in a script, the script executes on the player... dunno how to explain really but i guess unknown666, the troll xD, explained it well

yes, cid is important.

Code:
local t = 
{     
      msg = "TEXT"
      pos = {x=693, y=1007, z=7},
      typ = 
}       
       
function onLogin(cid)
  doPlayerPopupFYI(cid, t.msg)
    doPlayerAddMapMark(cid, t.pos, t.typ)
    end
    return TRUE
end

you don't need to make a .lua file, just paste
Code:
  doPlayerPopupFYI(cid, "TEXT")
    doPlayerAddMapMark(cid, {x=693, y=1007, z=7}, "blabla")

in your login.lua, so everytime a player logs in this happens.

edit: too late, troll posted b4 me -.-

edit2: typ should probably be '""' so like this:

typ = ""
 
Ahh, thanks!

This is wierd.
Now i get this error -
'<eof>' expected near 'end'

edit: But if i add it on login.lua in appears everytime someone logs. I want it just to heppend when they first login, with a new char
 
My bad, didn't see that.

The error is because of the double 'end'.
there is no condition (if) so you don't need more than 1 end.

Code:
local t = 
{     
      msg = "TEXT"[B][COLOR="Red"],[/COLOR][/B]
      pos = {x=693, y=1007, z=7},
      typ = 0 -- I guess :|
}       
       
[B]function onLogin(cid)[/B]
    doPlayerPopupFYI(cid, t.msg)
    doPlayerAddMapMark(cid, t.pos, t.typ)
    return TRUE
[B]end[/B]
 
So my script should be like this -

PHP:
local t = 
{     
      msg = "TEXT",
      pos = {x=693, y=1007, z=7},
	  typ = "0"
}	   
	   
function onLogin(cid) <-- Not sure if "STARTER_OUTFITID" should be here to ?
  doPlayerPopupFYI("STARTER_OUTFITID", t.msg)
    doPlayerAddMapMark("STARTER_OUTFITID", t.pos, t.typ, "NPC NAME")
	return TRUE
end

right hm ?
 
Lua:
   local text = "Welcome! Young master, if you go north east from here you reach Dr. Oak's lab. Talk with him and get your starting pokemon!", 
   local position = {x=693, y=1007, z=7}, 
   local type = "0"  
   
function onLogin(cid)
  return doPlayerPopupFYI(STARTER_OUTFITID, text) and doPlayerAddMapMark(STARTER_OUTFITID, position, type, "Dr. Oak") 
end
 
Last edited:
Cloow said:
But if i add it on login.lua in appears everytime someone logs. I want it just to heppend when they first login, with a new char

In order to that you need to use a storage value.

Code:
local t = 
{     
	storage = 15012,
    msg = "TEXT",
    pos = {x=693, y=1007, z=7},
    typ = 0 -- I guess :|
}       
       
function onLogin(cid)
	if getPlayerStorageValue(cid,t.storage) < 0 then -- this will check if your value is -1.
		setPlayerStorageValue(cid,t.storage,1) -- here you set it above the value 0 so that it will skip it the next time.
		doPlayerPopupFYI(cid, t.msg)
		doPlayerAddMapMark(cid, t.pos, t.typ)
	end
    return TRUE
end

you can still do it in login.lua though.

just paste these lines.
Code:
if getPlayerStorageValue(cid,t.storage) < 0 then -- this will check if your value is -1.
		setPlayerStorageValue(cid,t.storage,1) -- here you set it above the value 0 so that it will skip it the next time.
		doPlayerPopupFYI(cid, t.msg)
		return doPlayerAddMapMark(cid, t.pos, t.typ)
	end
 
Back
Top Bottom