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

Lua onUse. Elseif doesn't work for items of the same itemid and diffrent uid.

waqmaz

Member
Joined
Jun 17, 2015
Messages
203
Reaction score
11
Hello. Can someone explain, why it doesn't work?
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

    if item.itemid == 10351 and item.uid == 4767 then
        print(item.uid)
    elseif item.itemid == 10351 and item.uid == 4768 then
        print(item.uid)
    end

    return true
end

I've added uid to those items in RME Map Editor.
The function prints only 4767 when I click on the first item. When I click second item,it does nothing.
TFS 0.3.6.
 
Hello. Can someone explain, why it doesn't work?
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

    if item.itemid == 10351 and item.uid == 4767 then
        print(item.uid)
    elseif item.itemid == 10351 and item.uid == 4768 then
        print(item.uid)
    end

    return true
end

I've added uid to those items in RME Map Editor.
The function prints only 4767 when I click on the first item. When I click second item,it does nothing.
TFS 0.3.6.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

    if item.itemid == 10351 then
        if item.uid == 4767 then
            print(item.uid)
        elseif item.uid == 4768 then
            print(item.uid)
        end
    end

    return true
end

While your code is not wrong, this is the proper way to do it.

The problem is probably that you registered it with the uid 4767 in the xml and you should register it with the itemid.
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

    if item.itemid == 10351 then
        if item.uid == 4767 then
            print(item.uid)
        elseif item.uid == 4768 then
            print(item.uid)
        end
    end

    return true
end

While your code is not wrong, this is the proper way to do it.

The problem is probably that you registered it with the uid 4767 in the xml and you should register it with the itemid.
Thanks, but I've registered it this way:
HTML:
<action uniqueid="4767-4768" event="script" value="ravageSystem.lua" />
 
The correct is:
Code:
<action fromuid="4767" touid="4768" event="script" value="ravageSystem.lua" />
thanks, it works, but i am not sure it is the only correct way. i remember that "
4767-4768" was working to while tried to and there are even examples like:
Code:
<action itemid="7588-7591;8472-8473;7618;7620;8704" event="script" value="liquids/potions.lua"/>
 
thanks, it works, but i am not sure it is the only correct way. i remember that "
4767-4768" was working to while tried to and there are even examples like:
Code:
<action itemid="7588-7591;8472-8473;7618;7620;8704" event="script" value="liquids/potions.lua"/>
On 0.3.6? There is. It was removed.

This is what did the job back in the days: https://github.com/peonso/forgottenserver036pl1/blob/master/src/tools.cpp#L1438-L1457

You did not mention the tfs you're using but if you're using 0.3.6 it should work.

Sorry i'm fucking blind. Maybe it doesn't work with a single "-" if you don't have an ";" idk now
 
Last edited:
Back
Top