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

Add uniqueid on this script

Bruce Leal

New Member
Joined
Nov 9, 2017
Messages
77
Reaction score
3
Code:
local levelReward = {
    [30] = 3,
    [50] = 5,
    [100] = 10
}

function onAdvance(cid, skill, oldLevel, newLevel)
    doCreatureAddHealth(cid, getCreatureHealth(cid))
    doCreatureAddMana(cid, getCreatureMana(cid))

    for k, v in pairs(levelReward) do
        if newLevel == k and getPlayerStorageValue(cid, 3746) < k then
            doPlayerAddItem(cid, 2160, v, TRUE)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations, you\'ve received "..v.." crystal coins as a reward for level "..k..".")
     
            setPlayerStorageValue(cid, 3746, k)
        end
    end
    return true
end

Player will receive only 1 item with uniqueid 1980 such as the example 2160 but with uniqueID 1980, somebody can helpme to do?
 
Solution
"21:05 coins como recompensa por adquirir o nivel 9." :D:D

Now it got worse hahahahaha, the chat message continues to appear, it should be in the middle of the screen. (that GOD broadcast red)
zzzzz
just use my original script. don't use whatever your trying to do.
I removed the 'uid' thing that you originally requested.
Lua:
local storage = 45001
local levelReward = {
   [1] = {10, 2160, 1, "crystal coin"},
   [2] = {30, 2160, 3, "crystal coins"}, -- lowest level Must be at top, descending down
   [3] = {50, 2160, 5, "crystal coins"}, -- level, itemID, item_amount, item_name
   [4] = {100, 2160, 10, "crystal coins"}
}

function onAdvance(cid, skill, oldLevel, newLevel)
   if skill ~= SKILL__LEVEL or oldLevel >= newLevel then...
stackable items cannot retain aid/uid values.
but sure, you can do it.

"new_item.uid" might need to be "new_item"
Been awhile since I've done this.

Lua:
local unique_id = 1980
local storage = 45001
local levelReward = {
    [1] = {10, 2160, 1, "crystal coin"},
    [2] = {30, 2160, 3, "crystal coins"}, -- lowest level Must be at top, descending down
    [3] = {50, 2160, 5, "crystal coins"}, -- level, itemID, item_amount, item_name
    [4] = {100, 2160, 10, "crystal coins"}
}

function onAdvance(cid, skill, oldLevel, newLevel)
    if skill ~= SKILL__LEVEL or oldLevel >= newLevel then
        return true
    end

    doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
    doCreatureAddMana(cid, getCreatureMaxMana(cid))

    for i = 1, #levelReward do
        local table_level = levelReward[i][1]
        if newLevel >= table_level and table_level > getPlayerStorageValue(cid, storage) then
            local table_count = levelReward[i][3]
            local new_item = doPlayerAddItem(cid, levelReward[i][2], table_count, true)
            doItemSetAttribute(new_item.uid, "uid", unique_id)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations, system has sent " .. table_count .. " " .. levelReward[i][4] .. " as a reward for level " .. table_level .. " to your location!")
            setPlayerStorageValue(cid, storage, table_level)
            break
        end
    end

    return true
end
 
Yesterday I added these lines however ... it did not work.

  1. The doubt is ... What I should for in the XML of creaturescripts,
    Code:
    <event type="??" name="??" event="script" value="ganhaitemenxehp.lua"/>


    And... this will work for all rewards?
    Code:
    local unique_id = 1980
 
login.lua
Lua:
registerCreatureEvent(cid, "ganhaitemenxehp")
creaturescripts.xml
XML:
<event type="advance" name="ganhaitemenxehp" script="ganhaitemenxehp.lua"/>

If above doesn't work.. I guess try this
XML:
<event type="advance" name="ganhaitemenxehp" event="script" value="ganhaitemenxehp.lua"/>

And... this will work for all rewards?
Code:
local unique_id = 1980
Yes.
 
-bump
Dont receive item with UniqueID, only item without UniqueID
Code:
local unique_id = 1980
local storage = 45001
local levelReward = {
    [1] = {2, 10454, 1, "Sementes de Valholl"}
}

function onAdvance(cid, skill, oldLevel, newLevel)
    if skill ~= SKILL__LEVEL or oldLevel >= newLevel then
        return true
    end

    doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
    doCreatureAddMana(cid, getCreatureMaxMana(cid))

    for i = 1, #levelReward do
        local table_level = levelReward[i][1]
        if newLevel >= table_level and table_level > getPlayerStorageValue(cid, storage) then
            local table_count = levelReward[i][3]
            local new_item = doPlayerAddItem(cid, levelReward[i][2], table_count, true)
            doItemSetAttribute(new_item.uid, "uid", unique_id)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Pelos deuses, Odin lhe concedeu " .. table_count .. " " .. levelReward[i][4] .. " como recompensa pelo nivel " .. table_level .. " para a sua posicao.")
            setPlayerStorageValue(cid, storage, table_level)
            break
        end
    end

    return true
end

Also, every level up, i got an item as reward... i need only for level 2
@Xikini i got this error:
1M0whwk.jpg
 
Last edited:
-bump
Dont receive item with UniqueID, only item without UniqueID
Code:
local unique_id = 1980
local storage = 45001
local levelReward = {
    [1] = {2, 10454, 1, "Sementes de Valholl"}
}

function onAdvance(cid, skill, oldLevel, newLevel)
    if skill ~= SKILL__LEVEL or oldLevel >= newLevel then
        return true
    end

    doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
    doCreatureAddMana(cid, getCreatureMaxMana(cid))

    for i = 1, #levelReward do
        local table_level = levelReward[i][1]
        if newLevel >= table_level and table_level > getPlayerStorageValue(cid, storage) then
            local table_count = levelReward[i][3]
            local new_item = doPlayerAddItem(cid, levelReward[i][2], table_count, true)
            doItemSetAttribute(new_item.uid, "uid", unique_id)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Pelos deuses, Odin lhe concedeu " .. table_count .. " " .. levelReward[i][4] .. " como recompensa pelo nivel " .. table_level .. " para a sua posicao.")
            setPlayerStorageValue(cid, storage, table_level)
            break
        end
    end

    return true
end

Also, every level up, i got an item as reward... i need only for level 2
@Xikini i got this error:
1M0whwk.jpg
stackable items cannot retain aid/uid values.
but sure, you can do it.

"new_item.uid" might need to be "new_item"
Been awhile since I've done this.
 
bump-
Anyway to add on this script |PlayerName| , as the example:
Pelos Deuses, Jhon recebeu "..v.." como recompensa por adquirir o nivel "..k..".")
Code:
local levelReward = {
    [2] = 1,
    [4] = 1,
    [5] = 1
}

function onAdvance(cid, skill, oldLevel, newLevel)
    doCreatureAddHealth(cid, getCreatureHealth(cid))
    doCreatureAddMana(cid, getCreatureMana(cid))

    for k, v in pairs(levelReward) do
        if newLevel == k and getPlayerStorageValue(cid, 3746) < k then
            doPlayerAddItem(cid, 2160, v, TRUE)
            doBroadcastMessage("Pelos deuses, |PLAYERNAME|. recebeu "..v.."  como recompensa por adquirir o nivel "..k..".")
    
            setPlayerStorageValue(cid, 3746, k)
        end
    end
    return true
end
Inserting |PLAYERNAME| not work '-'
 
doBroadcastMessage(msg) -> doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, msg)

Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, msg)
Just like in the original script, it will send the message only to the player who received the rebound, I would like everyone on the server to see the message.
 
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, msg)
Just like in the original script, it will send the message only to the player who received the rebound, I would like everyone on the server to see the message.
soo.. like this?
Lua:
for _, pid in ipairs(getPlayersOnline()) do
    doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "Pelos deuses, " .. getCreatureName(cid) .. " recebeu "..v.."  como recompensa por adquirir o nivel "..k..".")
end
 
We are almost there, but have to appear in the middle of the screen in red, as well as the broadcast of the Administrator.

Something is wrong, because the item that the player received is not appearing, see:


20:55 Pelos deuses, Deus recebeu 1 como recompensa por adquirir o nivel 8.

The Correct would be "20:55 Pelos deuses, Deus recebeu 1 crystal coins como recompensa por adquirir o nivel 8."

Code:
local levelReward = {
    [30] = 3,
    [50] = 5,
    [7] = 1,
    [8] = 1
}

function onAdvance(cid, skill, oldLevel, newLevel)
    doCreatureAddHealth(cid, getCreatureHealth(cid))
    doCreatureAddMana(cid, getCreatureMana(cid))

    for k, v in pairs(levelReward) do
        if newLevel == k and getPlayerStorageValue(cid, 3746) < k then
            doPlayerAddItem(cid, 2160, v, TRUE)
            for _, pid in ipairs(getPlayersOnline()) do
            doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "Pelos deuses, " .. getCreatureName(cid) .. " recebeu "..v.."  como recompensa por adquirir o nivel "..k..".")
            end
            setPlayerStorageValue(cid, 3746, k)
        end
    end
    return true
end
 
We are almost there, but have to appear in the middle of the screen in red, as well as the broadcast of the Administrator.

Something is wrong, because the item that the player received is not appearing, see:

20:55 By the gods, God received 1 as a reward for acquiring level 8.

The Correct would be: "20:55 By the gods, God received 1 crystal coins as a reward for acquiring level 8."

Code:
local levelReward = {
    [30] = 3,
    [50] = 5,
    [7] = 1,
    [8] = 1
}

function onAdvance(cid, skill, oldLevel, newLevel)
    doCreatureAddHealth(cid, getCreatureHealth(cid))
    doCreatureAddMana(cid, getCreatureMana(cid))

    for k, v in pairs(levelReward) do
        if newLevel == k and getPlayerStorageValue(cid, 3746) < k then
            doPlayerAddItem(cid, 2160, v, TRUE)
            for _, pid in ipairs(getPlayersOnline()) do
            doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "Pelos deuses, " .. getCreatureName(cid) .. " recebeu "..v.."  como recompensa por adquirir o nivel "..k..".")
            end
            setPlayerStorageValue(cid, 3746, k)
        end
    end
    return true
end
That's because your not using the original script I wrote. xP

try
Lua:
for _, pid in ipairs(getPlayersOnline()) do
    doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "Pelos deuses, " .. getCreatureName(cid) .. " recebeu " .. v .. " crystal " .. v == 1 and "coin" or "coins" .. "  como recompensa por adquirir o nivel " .. k .. ".")
end

Oh, and if you want it in the middle of the screen, use
Code:
MESSAGE_STATUS_WARNING
instead of
Code:
MESSAGE_STATUS_CONSOLE_BLUE
 
"21:05 coins como recompensa por adquirir o nivel 9." :D:D

Now it got worse hahahahaha, the chat message continues to appear, it should be in the middle of the screen. (that GOD broadcast red)
 
"21:05 coins como recompensa por adquirir o nivel 9." :D:D

Now it got worse hahahahaha, the chat message continues to appear, it should be in the middle of the screen. (that GOD broadcast red)
zzzzz
just use my original script. don't use whatever your trying to do.
I removed the 'uid' thing that you originally requested.
Lua:
local storage = 45001
local levelReward = {
   [1] = {10, 2160, 1, "crystal coin"},
   [2] = {30, 2160, 3, "crystal coins"}, -- lowest level Must be at top, descending down
   [3] = {50, 2160, 5, "crystal coins"}, -- level, itemID, item_amount, item_name
   [4] = {100, 2160, 10, "crystal coins"}
}

function onAdvance(cid, skill, oldLevel, newLevel)
   if skill ~= SKILL__LEVEL or oldLevel >= newLevel then
       return true
   end

   doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
   doCreatureAddMana(cid, getCreatureMaxMana(cid))

   for i = 1, #levelReward do
       local table_level = levelReward[i][1]
       if newLevel >= table_level and table_level > getPlayerStorageValue(cid, storage) then
           local table_count = levelReward[i][3]
           doPlayerAddItem(cid, levelReward[i][2], table_count, true)           
           for _, pid in ipairs(getPlayersOnline()) do
               doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Pelos deuses, " .. getCreatureName(cid) .. " recebeu " .. table_count .. " " .. levelReward[i][4] .. " como recompensa por adquirir o nivel " .. table_level .. "!")
           end
           setPlayerStorageValue(cid, storage, table_level)
           break
       end
   end

   return true
end
 
Solution
-bump
Well, unfortunately does not appear the name of the item, I will have to put a costume message ... but it was in the middle of the screen, appearing the name of the character, please!
W43LDCb.png


@EDIT

Uowwww, thanks i using that original now, LOL>
Sorry for all Xikini , lolololol
 
Back
Top