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

Help with SIMPLE SCRIPT

Dankoo

Active Member
Joined
Sep 4, 2010
Messages
1,007
Reaction score
27
I'm trying to make a very simple script

When you use an item, it transforms to another, I've made the following:

LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 12668 then 
		doSendMagicEffect(fromPosition, 17)
		doPlayerAddItem(cid, 12706, 1)
		doPlayerRemoveItem(cid, 12688, 1)
	elseif item.itemid == 12706 then 
		doSendMagicEffect(fromPosition, 36)
		doPlayerAddItem(cid, 12707, 1)
		doPlayerRemoveItem(cid, 12606, 1)
			elseif item.itemid == 12707 then 
		doSendMagicEffect(fromPosition, 43)
		doPlayerAddItem(cid, 12708, 1)
		doPlayerRemoveItem(cid, 12607, 1)
			elseif item.itemid == 12708 then 
		doSendMagicEffect(fromPosition, 37)
		doPlayerAddItem(cid, 12709, 1)
		doPlayerRemoveItem(cid, 12608, 1)
			elseif item.itemid == 12709 then 
		doSendMagicEffect(fromPosition, 45)
		doPlayerAddItem(cid, 12710, 1)
		doPlayerRemoveItem(cid, 12609, 1)
			elseif item.itemid == 12710 then 
		doSendMagicEffect(fromPosition, 39)
		doPlayerAddItem(cid, 12668, 1)
		doPlayerRemoveItem(cid, 12610, 1)
	end
	return true
end

Everything smells fine, except player don't receive item, and the item I'm trying to use is a weapon, so when you click it, the cursor appears and nothing happens, but when I set an "non-usable" item to script, it works fine (but don't add the item)

Thanks!!
 
Updating:

As the item I'm trying to transform is a weapon, and when I "Use" it, it actually gives "Use item...", I've adapted the rusty remover script:

LUA:
local breakChance = 0
local rustyItems = {
    [12668] = {12706}, --weapon 1
    [12706] = {12707}, --weapon 2
    [12707] = {12708}, --weapon 3
    [12708] = {12709}, --weapon 4
    [12709] = {12710}, --weapon 5
    [12710] = {12668}, --weapon 6 returning to weapon 1
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if rustyItems[itemEx.itemid] ~= nil then
        if math.random(100) <= breakChance then
            doRemoveItem(itemEx.uid)
            doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You broke it.")
			doSendMagicEffect(getCreaturePosition(cid),34)
        else
            local newId = rustyItems[itemEx.itemid][math.random(#rustyItems[itemEx.itemid])]
            doTransformItem(itemEx.uid,newId)
            doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You removed the rust, revealing a "..getItemNameById(newId))
			doSendMagicEffect(getCreaturePosition(cid),66)
        end
        doRemoveItem(item.uid,1)
        return TRUE
    end
    return FALSE
end

This way, when I use the item on itself, it should give a new item, but it's not working, nothing happens and a message "You cannot use this object" appears
 
Didn't work.

like this?

I've tried to remove all itemEx to item and didn't work as well

LUA:
local breakChance = 0
local rustyItems = {
    [12668] = {12706}, --weapon 1
    [12706] = {12707}, --weapon 2
    [12707] = {12708}, --weapon 3
    [12708] = {12709}, --weapon 4
    [12709] = {12710}, --weapon 5
    [12710] = {12668} --weapon 6 returning to weapon 1
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if rustyItems[item.itemid] ~= nil then
        if math.random(100) <= breakChance then
            doRemoveItem(itemEx.uid)
            doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You broke it.")
			doSendMagicEffect(getCreaturePosition(cid),34)
        else
            local newId = rustyItems[itemEx.itemid][math.random(#rustyItems[itemEx.itemid])]
            doTransformItem(itemEx.uid,newId)
            doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You removed the rust, revealing a "..getItemNameById(newId))
			doSendMagicEffect(getCreaturePosition(cid),66)
        end
        doRemoveItem(item.uid,1)
        return TRUE
    end
    return FALSE
end
 
LUA:
local breakChance = 0
local rustyItems = {
    [12668] = {12706}, --weapon 1
    [12706] = {12707}, --weapon 2
    [12707] = {12708}, --weapon 3
    [12708] = {12709}, --weapon 4
    [12709] = {12710}, --weapon 5
    [12710] = {12668} --weapon 6 returning to weapon 1
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local v = rustyItems[item.itemid]
	if math.random(100) <= breakChance then
		doRemoveItem(item.uid)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You broke it.')
		doSendMagicEffect(getThingPos(cid), 34)
	else
		local newId = v[math.random(#v)]
		doTransformItem(item.uid, newId)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You removed the rust, revealing a ' .. getItemNameById(newId))
		doSendMagicEffect(getThingPos(cid), 66)
	end
	return true
end
 
Didn't work Cyk

Shouldn't it use itemex? 'Cause it's a "Use with..." item, like a weapon... If it was just a "Use" item I think I would be able to do it already

Is there a way to make a weapon not "Use with..."? Or is there a way to make a script that work with this hitch?

Thanks!!
 
hippo_bump.jpg
 
yes it's my own items

It's a weapon, so when you click it, it "Use with ...", not "Use", u know, so when you tried in your pc you've taken this into consideration?

If so, you "use it" with itself, or it transform right away into another item?
 
Back
Top