• 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 Table. insert ? not working ?

gabrieldi

New Member
Joined
Mar 21, 2012
Messages
8
Reaction score
0
hi otland!

Here is my problem,

i want to add a value to a table, but it does not work...

the table.insert(piece, #piece,{x = 525, y = 270, z = 7})
do not work :/

here is a part of my script
Code:
    if item.actionid == 20011 and  getspoi >= 10000 then
            do1 = getTileItemById(door.d1[1], 1547)
            do2 = getTileItemById(door.d1[2], 1547)
            setPlayerStorageValue(cid, 20022, (getspoi - 10000))
                doRemoveItem(do1.uid, 1)
                doRemoveItem(do2.uid, 1)            
    table.insert(piece, #piece,{x = 525, y = 270, z = 7})
    table.insert(piece, #piece,{x = 527, y = 264, z = 7})
    table.insert(piece, #piece,{x = 534, y = 264, z = 7})
end


REP + + + + + + + IF YOU HELP ME OUT :D
 
like this
LUA:
local t = {
    piece = {
        {x = 525, y = 270, z = 7},
        {x = 527, y = 264, z = 7},
        {x = 534, y = 264, z = 7}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local check = {}
    for _, k in ipairs(t.piece) do
        local x = getTopCreature(k).uid
         if item.actionid == 20011 and  getspoi >= 10000 then
            do1 = getTileItemById(door.d1[1], 1547)
            do2 = getTileItemById(door.d1[2], 1547)
            setPlayerStorageValue(cid, 20022, (getspoi - 10000))
                doRemoveItem(do1.uid, 1)
                doRemoveItem(do2.uid, 1)            
               table.insert(creaturesList, creature.uid)
end
 
thanks for doin this but i don't think it would work :S the purpose of my Table.insert is to add new spawn points to the posiotions table. so on use of my item, it will add the positions to the table and then monster can now randomly be spawned from any of the positions in the table. since there is 21 spawn position and they can all be unlocked in a differant way, I use the table insert function.


Code:
local piece = {
	{x = 522, y = 273, z = 7},
	{x = 516, y = 279, z = 7},
	{x = 518, y = 284, z = 7},
}

--I want the 3 position below to be added  to  the upper table on use of my item.
        {x = 525, y = 270, z = 7},
	{x = 527, y = 264, z = 7},
	{x = 534, y = 264, z = 7},

-- Here is the script again.


if item.actionid == 20011 and  getspoi >= 10000 then
			do1 = getTileItemById(door.d1[1], 1547)
			do2 = getTileItemById(door.d1[2], 1547)
			setPlayerStorageValue(cid, 20022, (getspoi - 10000))
				doRemoveItem(do1.uid, 1)
				doRemoveItem(do2.uid, 1)			
	table.insert(piece, #piece,{x = 525, y = 270, z = 7})
	table.insert(piece, #piece,{x = 527, y = 264, z = 7})
	table.insert(piece, #piece,{x = 534, y = 264, z = 7})
		
	elseif item.actionid == 20011 and getspoi < 10000 then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You need 10000 points to open a door.")
end



:D does not seems easy to do but OFC ill REP ++++++
THANK YOU SUPER HELPFUL EXPERT SCRIPTER. :D
 
bump bump ! there's aint no one on ot land who can figure what's wront in this script ? i'm not good enought to get it fixed bu myself :S keep getting errors :S please if someone knows about the table insertions PLEASE LET ME KNOW! =D it would set all my f******* script up! everything is working right but this part. it would be great to have a fully working script=D

thanks is advance for any helps and ofc REP +++
 
damn do one erver use this kind of script :S i think ill have to think on another way to fix this shit myself. maybe I am not the best scripter but my concepts are quite good though.

If someone can fix it please quickly let me know =D so i wont have to rework all the script... =D thanks guys!
 
In your case I'd just do this:

LUA:
piece[#piece+1] = {x = 525, y = 270, z = 7};

Keep in mind that your initial code inserted the item right before the last one, because Lua starts counting from 1, not from 0 like most other languages.
 
Back
Top