• 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 NPC random chance

sick

Member
Joined
Feb 5, 2009
Messages
258
Reaction score
6
Location
Lithuania, Vilnius
Hello :),

I'm looking for some help with adding random chance of success when giving X item and receiving Y item. For example there is just 30% chance to receive Y item when giving out X item.

Lua:
function obsidian(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
        if getPlayerItemCount(cid,2157) >= 1 then
        if randomChance == 1 then
        if doPlayerRemoveItem(cid,2157,1) then
            npcHandler:say('Here is your item!', cid)
            doPlayerAddItem(cid,7764,1)
        end
        else
            npcHandler:say('You don\'t have enough items!', cid)
    end
end

Thank for help in advance!
 
I think you want something like this:
Lua:
function obsidian(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

        local randomChance = 30

        if getPlayerItemCount(cid,2157) >= 1 then

            local random = math.random(1,100)
          
            if random <= randomChance then
                   if doPlayerRemoveItem(cid,2157,1) then
                    npcHandler:say('Here is your item!', cid)
                    doPlayerAddItem(cid,7764,1)
                end
            end
        else
            npcHandler:say('You don\'t have enough items!', cid)
        end
end
 
Back
Top