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

Items attributes on newly created item.

desalib

New Member
Joined
Jul 4, 2010
Messages
30
Reaction score
0
Hello everyone !

I'm having big trouble with code that involve attributes. When using mock's upgrade script (modified) I can change my attributes with the onUse (trigger?) and it works really well.
But what I really want is a way to change the attributes on a newly created item.

So first of all "setItemName" is a function from Mock's upgrade script here the codes behind :

Code:
function setItemName(uid,name)
         return doItemSetAttribute(uid,'name',name)
end

This function work well with onUse trigger. But using it on a newly created item return an error.

Code:
local monsters = {
["demon"] = {item = 2160, count = 2, chance = 70},
["rat"] = {item = 2396, count = 1, chance = 100}
}	

function onKill(cid, target, lastHit)
 
local v = getMonsterInfo(getCreatureName(target))
local chance = math.random(1, 100)
	for k, a in pairs(monsters) do
		if (isMonster(target) and ((string.lower(getCreatureName(target))) == k)) then
			if a.chance >= chance then
				local function dropLoot(pos, v, cid)
					local corpse = getTileItemById(pos, v.lookCorpse).uid
					local newItem = doCreateItemEx(a.item)
                                                        print(newitem)
                                                        setItemName(newItem, 'new item name')
                                                        doAddContainerItemEx(corpse, newItem) 
				end			
				addEvent(dropLoot, 0, getThingPos(target), v,cid)
			end
		end
	end
return true
end

data/creaturescripts/scripts/csloot.lua:23: attempt to call global
'setItemName' (a nil value)

If i understand the error correctly it's saying that the principal parameter got a nil value ? but my print of newitem return me a uid format : / ...

I need a little help to understand what is wrong with my code.
The attributes will change depending on the killed monster so no I can't just change it from items.xml

Thanks you, I just want to know how to make it works : / ... I know it's possible as Cykotitan attribute mod isn't sending error and work about the same way .. I think.
 
Last edited:
Back
Top