• 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 How to delete specific item description?

gabriel28

Member
Joined
Mar 16, 2012
Messages
199
Solutions
6
Reaction score
24
I trying to make a script that delete a specific item description, but without success.
The problem are in the form of comment in the script.
Here are my trying:

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local oo = "+3 reflect."
local cc = "+5 reflect."
local nn = "+7 reflect."
if getItemAttribute(itemEx.uid, "reflect") then
    doItemEraseAttribute(itemEx.uid, "reflect") -- attribute is deleted
    doItemEraseAttribute(itemEx.uid, "description", string.find(oo)) -- dont find the item
    doItemEraseAttribute(itemEx.uid, "description", string.find(cc)) -- dont find the item
    doItemEraseAttribute(itemEx.uid, "description", string.find(nn)) -- dont find the item
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "you deleted the atribute")
    doRemoveItem(item.uid, 1)
else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "this item dont have attribute to delete.")
   end
   return true
end
 
Last edited:
are you setting description before trying to erase it?
this will only work if you manually set the description attribute
could you show the exact text that you get when you look at the item?
 
@Static_
This script is to erase the attribute if the player don't like, because the "main" script add random reflect value attribute and a description with the value.
And i need it because I have other scripts that add different descriptions to the item.
19:11 You see a kankuro hat (Arm:5).
It weighs 13.00 oz.
+3 reflect.
 
if you want to remove the reflect line use this
Lua:
local desc = getItemAttribute(itemEx.uid, "description"):gsub("(\n?+%d+ reflect)", "")
doItemSetAttribute(itemEx.uid, "description" desc)
 
@Static_
Sorry for double post, but I think I'm close to solve my problem.
As I said, the first way makes a blank line in the description, so I decided to replace the old description to a new one, and I sucesfull in part.
If the item already have a description (that I want to change), the script runs fine, but if dont, it return a nil value. And I need to check if the description is the what I want. I tried with string.find but failed.
Here are the script:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local ab = math.random(1, 100)
local config = {
        {aumento = 3, chance1 = 41, chance2 = 100},
        {aumento = 5, chance1 = 11, chance2 = 40},
        {aumento = 7, chance1 = 1, chance2 = 10}

}
    for i = 1, #config, 1 do
    if isInArray({2430,2494,7380,7438,2451}, itemEx.itemid) then
        if ab >= config[i].chance1 and ab <= config[i].chance2 then
                doItemSetAttribute(itemEx.uid, "reflect", config[i].aumento)
               -- return a nil value in local desc
                local desc = getItemAttribute(itemEx.uid, "description"):gsub("(\n?+%d+ reflect.)", "+".. config[i].aumento .." reflect.")
                if getItemAttribute(itemEx.uid, "description") then
                doItemSetAttribute(itemEx.uid, "description", desc)
                else
                doItemSetAttribute(itemEx.uid, "description", "+".. config[i].aumento .. " reflect.")
                end
                doSendMagicEffect(toPosition,30)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "you add + ".. config[i].aumento .." of reflect. ")
                doRemoveItem(item.uid, 1)
            end
    else
        doPlayerSendCancel(cid, "Sorry, not possible.")
    end
    end
return true
end
 
@Static_
I don't solved the problem of the post, but I found an alternative way and I learned a little about string throught you, thanks.
 
Last edited:
Solution
Back
Top