• 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 How to fix my script ?

megachock

Member
Joined
Mar 12, 2009
Messages
115
Reaction score
7
Well i made this script, but it was soo big and not simplified, so i tried to make a new one, but doRemoveItem dont works :(... Im a noob scripter jaja

Old
Code:
function onDeath(cid, corpse, killer)

local M ={
["Water Poliwrath"] = {Pos1 = {x=1212, y=1592, z=3}, Pos2 = {x=1211, y=1592, z=3}, Pos3 = {x=1210, y=1592, z=3}, Pos4 = {x=1209, y=1592, z=3}, id = 1544, time = 10},
}

local x = M[getCreatureName(cid)]
function criar()
local parede1 = getTileItemById(x.Pos1, x.id)
local parede2 = getTileItemById(x.Pos2, x.id)
local parede3 = getTileItemById(x.Pos3, x.id)
local parede4 = getTileItemById(x.Pos4, x.id)
doCreateItem(x.id, 1, x.Pos1)
doCreateItem(x.id, 1, x.Pos2)
doCreateItem(x.id, 1, x.Pos3)
doCreateItem(x.id, 1, x.Pos4)
end
if x then
local parede1 = getTileItemById(x.Pos1, x.id)
local parede2 = getTileItemById(x.Pos2, x.id)
local parede3 = getTileItemById(x.Pos3, x.id)
local parede4 = getTileItemById(x.Pos4, x.id)
if parede1 and parede2 and parede3 and parede4 then
doRemoveItem(parede1.uid, 1)
doRemoveItem(parede2.uid, 1)
doRemoveItem(parede3.uid, 1)
doRemoveItem(parede4.uid, 1)
doCreatureSay(cid, "The wall will appears in "..x.time.." seconds.", TALKTYPE_ORANGE_1)
addEvent(criar, x.time*1000)
end
end
return TRUE
end

New:
Code:
local M ={
["Water Poliwrath"] = {Pos = {
                              {x=1212, y=1592, z=3},
                              {x=1211, y=1592, z=3},
                              {x=1210, y=1592, z=3},
                              {x=1209, y=1592, z=3},
                                                    },
                      id = 1544,
                      time = 10,
                                       },
}





function onDeath(cid, corpse, killer)


local x = M[getCreatureName(cid)]
function criar()
for a = 1, #x.Pos do
local parede = getTileItemById(x.Pos[a], x.id)
doCreateItem(x.id, 1, x.Pos[a])
end
end

local wall = getTileItemById(x.Pos[a], x.id).uid
if x then
if wall then
doRemoveItem(wall)
doCreatureSay(cid, "The wall will appears in "..x.time.." seconds.", TALKTYPE_ORANGE_1)
addEvent(criar, x.time*1000)
end
end

return TRUE
end
end
 
Last edited:
Try This One
Code:
local M = "Water Poliwrath"
local id = 1544
local time = 10
local pos = {
        {x=1212, y=1592, z=3},
        {x=1211, y=1592, z=3},
        {x=1210, y=1592, z=3},
        {x=1209, y=1592, z=3}
            }
     





function onDeath(cid, corpse, killer)

function criar()
for i = 1,#pos do
local parede = getTileItemById(i, id)
doCreateItem(id, 1, i)
end
end

local wall = getTileItemById(i, id).uid
if wall then
doRemoveItem(wall)
doCreatureSay(cid, "The wall will appears in "..time.." seconds.", TALKTYPE_ORANGE_1)
addEvent(criar, time*1000)
end
return true
end
 
Try This One
Code:
local M = "Water Poliwrath"
local id = 1544
local time = 10
local pos = {
        {x=1212, y=1592, z=3},
        {x=1211, y=1592, z=3},
        {x=1210, y=1592, z=3},
        {x=1209, y=1592, z=3}
            }
    





function onDeath(cid, corpse, killer)

function criar()
for i = 1,#pos do
local parede = getTileItemById(i, id)
doCreateItem(id, 1, i)
end
end

local wall = getTileItemById(i, id).uid
if wall then
doRemoveItem(wall)
doCreatureSay(cid, "The wall will appears in "..time.." seconds.", TALKTYPE_ORANGE_1)
addEvent(criar, time*1000)
end
return true
end
I have something similar like this, the problem is i want to add more monsters with different positions in the same script, to dont make 1 script per monster
 
A Simple Code
Code:
local id = 1544
local time = 10
   
    local config = {
    ["name"] = {pos = x=500,y=500,z=7},
    ["name2"] = {pos = x=500,y=500,z=7},





function onDeath(cid, corpse, killer)

for i,v in pairs(config) do
if getCreatureName(cid) == i then
doCreateItem(id, 1 ,v.pos)
end
return true
end
end
 
A Simple Code
Code:
local id = 1544
local time = 10
 
    local config = {
    ["name"] = {pos = x=500,y=500,z=7},
    ["name2"] = {pos = x=500,y=500,z=7},





function onDeath(cid, corpse, killer)

for i,v in pairs(config) do
if getCreatureName(cid) == i then
doCreateItem(id, 1 ,v.pos)
end
return true
end
end
I think you dont understand xD, my script is When a monster die, will remove walls from x positions, then after x seconds walls will appear again.
You can add a different monsters with different positions
 
Code:
local config, time = {
    ["Demon"] = {itemId = 1544, pos = {{x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}}},
    ["Dragon"] = {itemId = 1543, pos = {{x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}}}
}, 10

function onKill(cid, target, lastHit)
    local v = config[getCreatureName(target)]
    if v then
        for _, k in ipairs(v.pos) do
            if getTileItemById(k, v.itemId).uid > 0 then
                doRemoveItem(getTileItemById(k, v.itemId).uid)
                doSendMagicEffect(k, CONST_ME_POFF)
            end
        end
     
        addEvent(function() for x, t in ipairs(v.pos) do doCreateItem(v.itemId, t) doSendMagicEffect(t, CONST_ME_MAGIC_BLUE) end end, time * 1000)
        doCreatureSay(cid, "The walls will appear in " .. time .. " seconds.", TALKTYPE_ORANGE_1)
    end
    return true
end
 
Code:
local config, time = {
    ["Demon"] = {itemId = 1544, pos = {{x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}}},
    ["Dragon"] = {itemId = 1543, pos = {{x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}, {x = 1000, y = 1000, z = 7}}}
}, 10

function onKill(cid, target, lastHit)
    local v = config[getCreatureName(target)]
    if v then
        for _, k in ipairs(v.pos) do
            if getTileItemById(k, v.itemId).uid > 0 then
                doRemoveItem(getTileItemById(k, v.itemId).uid)
                doSendMagicEffect(k, CONST_ME_POFF)
            end
        end
   
        addEvent(function() for x, t in ipairs(v.pos) do doCreateItem(v.itemId, t) doSendMagicEffect(t, CONST_ME_MAGIC_BLUE) end end, time * 1000)
        doCreatureSay(cid, "The walls will appear in " .. time .. " seconds.", TALKTYPE_ORANGE_1)
    end
    return true
end
It was giving some errors in console, i fixed them, but now it only works 1 time after, nothing happens, only send the message. :(
Code:
local config = {
    ["Demon"] = {itemId = 1544,
                            pos = {
                                  {x=1212, y=1590, z=3},
                                  {x=1211, y=1590, z=3},
                                  {x=1210, y=1590, z=3},
                                  {x=1209, y=1590, z=3}},
                          time = 300},
    ["Dragon"] = {itemId = 1544,
                            pos = {
                                  {x=1212, y=1588, z=3},
                                  {x=1211, y=1588, z=3},
                                  {x=1210, y=1588, z=3},
                                  {x=1209, y=1588, z=3}},
                          time = 300}
                          }

function onKill(cid, target, lastHit)
    local v = config[getCreatureName(target)]
    if v then
        for _, k in ipairs(v.pos) do
            if getTileItemById(k, v.itemId).uid > 0 then
                doRemoveItem(getTileItemById(k, v.itemId).uid)
                doSendMagicEffect(k, CONST_ME_POFF)
            end
        end
  
        addEvent(function() for x, t in ipairs(v.pos) do doCreateItem(v.itemId, t) doSendMagicEffect(t, CONST_ME_MAGIC_BLUE) end end, v.time * 1000)
        doCreatureSay(cid, "The walls will appear in " .. v.time .. " seconds.", TALKTYPE_ORANGE_1)
    end
    return true
end
 
Last edited:
Back
Top