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

Solved script bug

4Muki4

HOROHOROHORO
Joined
May 1, 2012
Messages
757
Reaction score
72
hello,

i added a new script to my server today it work perfectly to things what it should do.
when i try kill a player i get this error and he wont die he stays stuck with 0 hp also

Code:
[27/5/2013 18:6:9] [Error - CreatureScript Interface] 
[27/5/2013 18:6:9] data/creaturescripts/scripts/inq.lua:onKill
[27/5/2013 18:6:9] Description: 
[27/5/2013 18:6:9] data/creaturescripts/scripts/inq.lua:47: attempt to index local 'v' (a nil value)
[27/5/2013 18:6:9] stack traceback:
[27/5/2013 18:6:10] 	data/creaturescripts/scripts/inq.lua:47: in function <data/creaturescripts/scripts/inq.lua:45>
and here the script:
LUA:
local t = {
    ["ushuriel"] = { -- Monster name here. Must be LOWER case!
        toPos = {x = 1119, y = 1593, z = 10}, -- Where the portal takes the players.
        createPos = {x = 1224, y = 1587, z = 10}, -- Where the portal is created.
        timeToRemove = 60, -- Seconds until the portal is removed.
        messageOnKill = "You have defeated me... You shall be rewarded for your victory!"
    },
    ["zugurosh"] = {
        toPos = {x = 1027, y = 1650, z = 10},
        createPos = {x = 1226, y = 1569, z = 10},
        timeToRemove = 60,
        messageOnKill = "NOOOOOOOOOO, None can defeat me!"
    },
    ["latrivan"] = {
        toPos = {x = 1074, y = 1518, z = 10},
        createPos = {x = 1260, y = 1595, z = 10},
        timeToRemove = 60,
        messageOnKill = "Someday i will rise again!"
    },
    ["madareth"] = {
        toPos = {x = 1242, y = 1762, z = 12},
        createPos = {x = 1252, y = 1564, z = 10},
        timeToRemove = 60,
        messageOnKill = "Lies next time you wont survive."
    },
    ["hellgorak"] = {
        toPos = {x = 1004, y = 1506, z = 10},
        createPos = {x = 1290, y = 1592, z = 10},
        timeToRemove = 60,
        messageOnKill = "Never ill will get you some day!"
    },
    ["annihilon"] = {
        toPos = {x = 1064, y = 1415, z = 12},
        createPos = {x = 1281, y = 1565, z = 10},
        timeToRemove = 60,
        messageOnKill = "Defeat is defeat go get ur reward!"
    },
}
 
local function remove(pos)
    local k = getTileItemById(pos, 1387).uid
    return k > 0 and doRemoveItem(k)
end
 
function onKill(cid, target, damage, flags)
    local v = t[string.lower(getCreatureName(target))]
    local pos = v.createPos
    if(v and (damage == true or bit.band(flags, 1) == 1) and isMonster(target)) then
        doCreatureSay(cid, v.messageOnKill, TALKTYPE_MONSTER, nil, nil, getCreaturePosition(target))
        doSendMagicEffect(v.createPos, CONST_ME_ENERGYAREA)
        doCreateTeleport(1387, v.toPos, v.createPos)
        addEvent(remove, v.timeToRemove * 1000)
    end
    return true
end
rep++
 
Last edited:
The local pos function should be inside of the if statement

- - - Updated - - -

Where it says local pos = v.createPos put that inside if the if statement I can't do it right now I'm on my phone
 
As dchampag said, the local pos should be inside de if, just like this

LUA:
local t = {
    ["ushuriel"] = { -- Monster name here. Must be LOWER case!
        toPos = {x = 1119, y = 1593, z = 10}, -- Where the portal takes the players.
        createPos = {x = 1224, y = 1587, z = 10}, -- Where the portal is created.
        timeToRemove = 60, -- Seconds until the portal is removed.
        messageOnKill = "You have defeated me... You shall be rewarded for your victory!"
    },
    ["zugurosh"] = {
        toPos = {x = 1027, y = 1650, z = 10},
        createPos = {x = 1226, y = 1569, z = 10},
        timeToRemove = 60,
        messageOnKill = "NOOOOOOOOOO, None can defeat me!"
    },
    ["latrivan"] = {
        toPos = {x = 1074, y = 1518, z = 10},
        createPos = {x = 1260, y = 1595, z = 10},
        timeToRemove = 60,
        messageOnKill = "Someday i will rise again!"
    },
    ["madareth"] = {
        toPos = {x = 1242, y = 1762, z = 12},
        createPos = {x = 1252, y = 1564, z = 10},
        timeToRemove = 60,
        messageOnKill = "Lies next time you wont survive."
    },
    ["hellgorak"] = {
        toPos = {x = 1004, y = 1506, z = 10},
        createPos = {x = 1290, y = 1592, z = 10},
        timeToRemove = 60,
        messageOnKill = "Never ill will get you some day!"
    },
    ["annihilon"] = {
        toPos = {x = 1064, y = 1415, z = 12},
        createPos = {x = 1281, y = 1565, z = 10},
        timeToRemove = 60,
        messageOnKill = "Defeat is defeat go get ur reward!"
    },
}
 
local function remove(pos)
    local k = getTileItemById(pos, 1387).uid
    return k > 0 and doRemoveItem(k)
end
 
function onKill(cid, target, damage, flags)
    local v = t[string.lower(getCreatureName(target))]
    if(v and (damage == true or bit.band(flags, 1) == 1) and isMonster(target)) then
		local pos = v.createPos
        doCreatureSay(cid, v.messageOnKill, TALKTYPE_MONSTER, nil, nil, getCreaturePosition(target))
        doSendMagicEffect(v.createPos, CONST_ME_ENERGYAREA)
        doCreateTeleport(1387, v.toPos, v.createPos)
        addEvent(remove, v.timeToRemove * 1000)
    end
    return true
end
 
Back
Top