• 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 onKill() function ain't working?

Evan

A splendid one to behold
Senator
Premium User
Joined
May 6, 2009
Messages
7,019
Solutions
1
Reaction score
1,029
Location
United States
Lua:
function onKill(cid, target, lastHit)
monsterPos = getCreaturePosition(target)
newMonsterPos = {x= 748, y= 1139, z= 7}
wall_pos = {x= 748, y= 1139, z= 7, stackpos= 1}  
wall = getThingfromPos(wall_pos)  

        if isPlayer(cid) and (getCreatureName(target):lower() == "demon oak1") and wall.itemid == 8289 then
        doSendAnimatedText(monsterPos, "KILL!", TEXTCOLOR_ORANGE)
		doRemoveItem(wall.uid) 
		doSummonCreature("demon oak2", newMonsterPos)
        end
    return TRUE
end

Anyone know why this isn't working?
Is it because I have 2 different onKill() functions existing?
 
Okay, so going back to ruda's point on having only one onKill() function.
It may be playing a role in my demon oak2 not being able to summon, as far as I can see in Santi's code, demon oak2 should be summoned after killing demon oak1.
The coordinates of where demon oak2 is correct unless I'm numerically visually blind.

Demon Oak2:
17:13 You see a demon oak.
ItemID: [8289].
Position: [X: 748] [Y: 1139] [Z: 7].
*This is supposed to be removed and demon oak2 should be summoned right where this object was.


So, if ruda's theory is correct, then this is really depressing to have onKill() work for only one monster.
 
Dude, you're confusing yourself by listening to many people. Just read what I posted back a couple posts, you'll understand it.
 
i didn't said you can have onKill() to only one monster
i said you can have only one onKill() registered to players, and I'm not 100% sure about this

what problems with the code are you having now?
we may help you...
 
@JDB, yeah I understand how to do the arrays and tables, you can see my excitement in the last post on page two, if that's what you meant from my post on this page.
------- Though, JDB, should I be using your script instead of Santi's?
@ruda, I see, I guess I was misunderstood, I have no problem with any code now that I know arrays and tables.

The problem is that it's somewhat not working;
Here's the script I am using made by Santi:
Lua:
local t = {
['demon oak'] = {"demon oak1", {x= 750, y= 1137, z= 7}, {x= 750, y= 1137, z= 7, stackpos= 1}, 8288},
['demon oak1'] = {"demon oak2", {x= 748, y= 1139, z= 7}, {x= 748, y= 1139, z= 7, stackpos= 1}, 8289}
}
function onKill(cid, target, lastHit)
monsterPos = getCreaturePosition(target)
if isPlayer(cid) then
   for k, v in pairs(t) do
       if (getCreatureName(target):lower() == k) then
          if getThingfromPos(v[3]).itemid == v[4] then
             doSendAnimatedText(monsterPos, "KILL!", TEXTCOLOR_ORANGE)
             doRemoveItem(getThingfromPos(v[3]).uid)
             doSummonCreature(v[1], v[2])
          end
      end
   end
end
return true
end

After what you and JDB taught me and me looking through that script, everything seems to be perfectly normal in the code.
Now, when I do the thing in-game, killing demon oak summoned demon oak1, but killing demon oak1 did nothing.

Here's a picture for better explanation:
2lowt2.png

*PS: No "KILL!" shows up after killing demon oak1, either.




From reading the script, it should work if you kill demon oak1, but it's somehow NOT.
 
Dude, I don't know how else to explain it to you. You're not even using my script.
 
@Up: Items which are removed, Monsters with item looktypes are summoned in that positions, so they are monsters somehow :p
 
Okay JDB;

Lua:
local config = {
	["demon oak"] = {
		"demon oak1", 8288, {x= 750, y= 1137, z= 7}, {x= 750, y= 1137, z= 7, stackpos= 1}
	},
	["demon oak1"] = {
		"demon oak2", 8289, {x= 748, y= 1139, z= 7}, {x= 748, y= 1139, z= 7, stackpos= 1}
	}		
}
 
function onKill(cid, t)
	for v, x in pairs(config) do
		if getCreatureName(t):lower() == v then
			doCreatureSay(t, "OWNED!", TALKTYPE_MONSTER)
			doRemoveItem(getTileItemById(x[4], x[2]).uid)
			doCreateMonster(x[1], x[3], false, false, nil)
		end
	end
 
	return true
end

Is there anything wrong? This is your script.
Killed demon oak, removes the thing but summons demon oak1 in a different area nearby it. There's nothing wrong with my coordinates, it summons the monster nearby the coordinates as if it has no room to be summoned.
Also, upon after killing demon oak1, still getting no demon oak2.

[19:57:26.354] [Error - CreatureScript Interface]
[19:57:26.355] data/creaturescripts/scripts/demonoak.lua:eek:nKill
[19:57:26.357] Description:
[19:57:26.358] (luaDoRemoveItem) Item not found

The only thing I'm confused with is all the falses in summonCreature and the getTileItemByID.
 
You don't need stackpos...

Lua:
local config = {
	["demon oak"] = {
		"demon oak1", 8288, {x = 750, y = 1137, z = 7}, {x = 750, y = 1137, z = 7}
	},
	["demon oak1"] = {
		"demon oak2", 8289, {x = 748, y = 1139, z = 7}, {x = 748, y = 1139, z = 7}
	}	
}

function onKill(cid, t)
	for v, x in pairs(config) do
		if getCreatureName(t):lower() == v then
			doCreatureSay(t, "OWNED!", TALKTYPE_MONSTER)
			doRemoveItem(getTileItemById(x[4], x[2]).uid)
			doCreateMonster(x[1], x[3])
		end
		
		break
	end
	
	return true
end
 
Last edited:
Okay, now I see why you don't need stackpos.

It still frustrates me why it's not removing and summoning demon oak2.
It really should work.

This is the error I get after killing demon oak1 (ps: if I kill demon oak1, it summons demon oak1 again):
[20:5:36.429] [Error - CreatureScript Interface]
[20:5:36.431] data/creaturescripts/scripts/demonoak.lua:eek:nKill
[20:5:36.432] Description:
[20:5:36.433] (luaDoRemoveItem) Item not found


Looking in the picture above, the coordinate is correct, the ID is correct, am I missing something?

SEC, looking through my monster file.
 
I copied and pasted it:

Paste:
Lua:
local config = {
	["demon oak"] = {
		"demon oak1", 8288, {x = 750, y = 1137, z = 7}, {x = 750, y = 1137, z = 7}
	},
	["demon oak1"] = {
		"demon oak2", 8289, {x = 748, y = 1139, z = 7}, {x = 748, y = 1139, z = 7}
	}	
}
 
function onKill(cid, t)
	for v, x in pairs(config) do
		if getCreatureName(t):lower() == v then
			doCreatureSay(t, "OWNED!", TALKTYPE_MONSTER)
			doRemoveItem(getTileItemById(x[4], x[2]).uid)
			doCreateMonster(x[1], x[3])
		end
 
		break
	end
 
	return true
end

Saved.
Restarted server.

Result:
2007klc.png
 
Back
Top