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

I NEED LIMITE 50X THIS ACTION

lorinholukete69

New Member
Joined
Apr 22, 2021
Messages
22
Reaction score
2
GitHub
lorinholukete69
I HAVE THIS SCRIPT:

this script give 1 magic level each "magic stone" player use.

i need same script but with a usage limit of 50x.

i need same script that adds sword , axe , club , distance, with a usage limit of 50x. help me ??

-----------------------------------------------------------------
local count = 1 -- GIVE 1 ML

function onUse(cid, item, fromPosition, itemEx, toPosition)
doPlayerAddMagLevel(cid, count)
doRemoveItem(item.uid)
return true
end

function doPlayerAddMagLevel(cid, amount)
local amount = amount or 1
for i = 1, amount do
doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true) + 1) - getPlayerSpentMana(cid), false)
end
return true
end
----------------------------------------------------------
 
LUA:
local max = 50
local count = 1
local storageKey = 12345

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local usageCount = getPlayerStorageValue(cid, storageKey) or 0
    if usageCount < 0 then usageCount = 0 end

    if usageCount >= max then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have reached the maximum usage limit for this item.")
        return false
    end

    doPlayerAddMagLevel(cid, count)
    setPlayerStorageValue(cid, storageKey, usageCount + 1)
    doRemoveItem(item.uid)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have used this item " .. (usageCount + 1) .. "/" .. max .. " times.")
    return true
end

function doPlayerAddMagLevel(cid, amount)
    local amount = amount or 1
    for i = 1, amount do
        doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true) + 1) - getPlayerSpentMana(cid), false)
    end
    return true
end

not tested
 
LUA:
local max = 50
local count = 1
local storageKey = 12345

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local usageCount = getPlayerStorageValue(cid, storageKey) or 0
    if usageCount < 0 then usageCount = 0 end

    if usageCount >= max then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have reached the maximum usage limit for this item.")
        return false
    end

    doPlayerAddMagLevel(cid, count)
    setPlayerStorageValue(cid, storageKey, usageCount + 1)
    doRemoveItem(item.uid)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have used this item " .. (usageCount + 1) .. "/" .. max .. " times.")
    return true
end

function doPlayerAddMagLevel(cid, amount)
    local amount = amount or 1
    for i = 1, amount do
        doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true) + 1) - getPlayerSpentMana(cid), false)
    end
    return true
end

not tested
instead of this
LUA:
local usageCount = getPlayerStorageValue(cid, storageKey) or 0
if usageCount < 0 then usageCount = 0 end
can do it like this instead.
LUA:
local usageCount = math.max(getPlayerStorageValue(cid, storageKey), 0)
 
Back
Top