Why this did not work?

kyleflow

Pirate
Registered
LV
0
 
Joined
Jan 12, 2026
Messages
18
Reaction score
3
Points
8
This is the same code from carribien map with the function name and etc is change. I dont know my iteration of this did not work. The map is clickable and if im not in position. it provide me the coordinate. and when I arrive at the expected location from coordinate, if it does not directly succeed in digging, it will be able to dig till succeed. BUT, after the succeed notification appeared, the map did not consume, the character stuck on place, no reward gain. Yes I update the iteminfo, Yes I made also a specific table for the reward in the variable.lua. So yeah I'm confused on why it did not work. I also ask GPT to compare the 2 code and it said its perfectly replicated.
Code:
function ItemUse_MAPK1(role, Item)
     local Item_CanGet = GetChaFreeBagGridNum(role)
    if Item_CanGet < 1 then
        SystemNotice(role ,"You need to have at least 1 empty inventory slot")
        UseItemFailed(role)
        return
    end
    local lv= GetChaAttr(role, ATTR_LV)
    if lv < 15 or  lv > 100 then
        SystemNotice(role, "Characters lower than Lv 15 or higher than Lv 40 cannot use this treasure map")
        UseItemFailed(role)
        return   
    end
    local Has_GoldenMap = CheckBagItem(role, 9630)
    if Has_GoldenMap >= 2 then
        SystemNotice(role, "You can only have 1 treasure map in inventory to seek for treasure. Please deposit the rest into your vault")
        UseItemFailed(role)
        return
    end
    local Item = GetChaItem2(role, 2, 9630)
    local Item_MAXURE = GetItemAttr(Item, ITEMATTR_MAXURE)
    local Item_URE = GetItemAttr(Item, ITEMATTR_URE)
    local Item_MAXENERGY = GetItemAttr(Item, ITEMATTR_MAXENERGY)
    local pos_x = Item_MAXURE
    local pos_y = Item_MAXENERGY
    local Themap = Item_URE
    local MapList = {}   
    MapList[0] = "NoMap"
    MapList[1] = "jialebi"
    local MapNameList = {}
    MapNameList[0] = "No map"
    MapNameList[1] = "Treasure Gulf"
    if pos_x == 0 or pos_y == 0 or Themap == 0 then
        pos_x, pos_y, Themap = GetTheMapPos_JLB(role, 1)   
        Item_MAXURE = pos_x
        Item_URE = Themap
        Item_MAXENERGY = pos_y
        SetItemAttr(Item, ITEMATTR_MAXENERGY, Item_MAXENERGY)
        SetItemAttr(Item, ITEMATTR_MAXURE, Item_MAXURE)
        SetItemAttr(Item, ITEMATTR_URE, Item_URE)
    end
    local GetPos = CheckGetMapPos(role, pos_x, pos_y, MapList[Themap])
    if GetPos == 0 then
        SystemNotice(role, "Treasure is hidden at "..MapNameList[Themap].." Region. "..pos_x..","..pos_y.." nearby")
        UseItemFailed(role)
        return
    elseif GetPos == 1 then
        local getrandom = math.random(1,3)
        if getrandom == 1 then
            Give_MAPK1(role)
        else
            SystemNotice(role, "Looks like nothing is dug out. Look again nearby")
            UseItemFailed(role)
            return
        end
    end
end
function Give_MAPK1(role)
    local CheckRandom = math.random(1,100)
    local x, y = GetChaPos(role)
    local monsterID = math.random(829,836)
    if CheckRandom >= 1 and CheckRandom <= 20 then
        local GiveMoney = 10000 * math.random (1, 20)
        SystemNotice (role, "Dug out Caribbean Treasure and obtain "..GiveMoney.."G")
        AddMoney (role, 0, GiveMoney)
    elseif CheckRandom > 20 and CheckRandom <= 24 then
        XianJing(role, 1)
    elseif CheckRandom > 24 and CheckRandom <= 28 then
        XianJing(role, 2)
    elseif CheckRandom > 28 and CheckRandom <= 33 then
        SystemNotice(role, "Today seems to be spining about. Don't know where it will spin to")
        MapRandomtele(role)
    elseif CheckRandom > 33 and CheckRandom <= 40 then
        SystemNotice(role , "Oh no! Who let the dogs out! Help...")
        local new1 = CreateCha(monsterID, x, y, 145, 30)
        SetChaLifeTime(new1, 90000)
    else
        SystemNotice (role, "dug out a hidden pirate treasure")
        local General = 0       
        for i = 1 , #BaoXiang_MAPK1, 1 do
            if BaoXiang_MAPK1[i].Active == 1 then
                General = BaoXiang_MAPK1[i].Rad + General
            end
        end
        local a = math.random(1, General)
        local b = 0
        local d = 0
        local c = -1
        for k = 1 , #BaoXiang_MAPK1, 1 do
            if BaoXiang_MAPK1[k].Active == 1 then
                d = BaoXiang_MAPK1[k].Rad + b
                if a <= d and a > b then
                    c = k
                    break
                end
                b = d
            end
        end
        if c ~= -1 then
            local Item2Give = BaoXiang_MAPK1[c].ItemID
            local ItemCount = BaoXiang_MAPK1[c].Quantity
            local ItemQuality = BaoXiang_MAPK1[c].Quality
            local GoodItem = BaoXiang_MAPK1[c].GoodItem
            GiveItem(role, 0, Item2Give, ItemCount, ItemQuality)
            if GoodItem == 1 then
                local message = ""..GetChaDefaultName(role).." Dug out a treasure and obtained "..GetItemName(Item2Give)..""
                Notice(message)
            end
        end
    end
end