Jump to content

Some Item-Questfunctions in Lua


Recommended Posts

M2 Download Center

This is the hidden content, please
( Internal )

quest_functions:

string_in_table
item.is_worn
item.get_worn_vnum
item.get_worn_wearflag
item.get_worn_flag
item.get_wearflag
item.get_flag

questlib.lua

slottypes = {["armor"] = 90,
             ["helmet"] = 91,
             ["shoes"] = 92,
             ["bracelet"] = 93,
             ["weapon"] = 94,
             ["necklace"] = 95,
             ["earrings"] = 96,
             ["slot1"] = 97,
             ["slot2"] = 98,
             ["shield"] = 100,
             ["costume_armor"] = 109,
             ["costume_hair"] = 110,
             ["costume_weapon"] = 111}

function string_in_table(s,t)        -- syntax: string_in_table(string, table)
    return ((t[s] == nil) == false)
end

function item.is_worn(itype)        -- syntax: item.is_worn(itemtype) // e.g.: item.is_worn("helmet")
    if not string_in_table(itype, slottypes) then return end
    local itemcell = tonumber(slottypes[itype])
    item.select_cell(itemcell)
    if item.get_cell() == itemcell and item.get_vnum() >= 0 then
        return true 
    else 
        return false 
    end
end

function item.get_worn_vnum(itype)    -- syntax: item.get_worn_vnum(itemtype) // e.g.: item.get_worn_vnum("helmet")
    if not string_in_table(itype, slottypes) then return end
    local itemcell = tonumber(slottypes[itype])
    if not item.is_worn(itemcell) then return end
    item.select_cell(itemcell)
    return item.get_vnum()
end

function item.get_worn_wearflag(itype)    -- syntax: item.get_worn_wearflag(itemtype) // e.g.: item.get_worn_wearflag("helmet")
    if not string_in_table(itype, slottypes) then return end
    local itemcell = tonumber(slottypes[itype])
    if not item.is_worn(itemcell) then return end
    item.select_cell(itemcell)
    return item.get_wearflag()
end

function item.get_worn_flag(itype)        -- syntax: item.get_worn_flag(itemtype) // e.g.: item.get_worn_flag("helmet")
    if not string_in_table(itype, slottypes) then return end
    local itemcell = tonumber(slottypes[itype])
    if not item.is_worn(itemcell) then return end
    item.select_cell(itemcell)
    return item.get_flag()
end

function item.get_wearflag()            -- syntax: item.get_wearflag()
    return tonumber(mysql_query("SELECT wearflag FROM player.item_proto WHERE vnum='"..item.get_vnum().."';")[1])
end

function item.get_flag()                -- syntax: item.get_flag()
    return tonumber(mysql_query("SELECT flag FROM player.item_proto WHERE vnum='"..item.get_vnum().."';")[1])
end

 

  • Metin2 Dev 11
  • Eyes 1
  • Confused 1
  • Love 1
  • Love 9
Link to comment
https://metin2.dev/topic/5947-some-item-questfunctions-in-lua/
Share on other sites

i m sorry i have not high knowledge

can you please explain all these new functions, what are the functions in game?

thanks you.

9eb4c35951.png

Edited by Metin2 Dev
Core X - External 2 Internal
  • 3 years later...
  • Active Member

One thing to mention for everyone facing issues whilst using this function, check below:

 if not item.is_worn(itemcell) then return end

Change into

 if not item.is_worn(itype) then return end

As you're using the previous function which takes a string not a number, itemcell returns the itype's number.
Other than that thank you very much for posting these functions Avenue.

for brain_cells in xrange(brain):
  if brain_cells == 0:
    print("0x3703c7 Fatal error occurred. Please replace the brain.")
    break
  if brain_cells == "damaged":
    print("0x3703c7 Error occurred. Please repair damaged brain_cells")
    break
  
  print("brain_cells are at 100% capacity.")

 

  • Honorable Member

Rewritten,

slottypes = {
    ["armor"] = 90,
    ["helmet"] = 91,
    ["shoes"] = 92,
    ["bracelet"] = 93,
    ["weapon"] = 94,
    ["necklace"] = 95,
    ["earrings"] = 96,
    ["slot1"] = 97,
    ["slot2"] = 98,
    ["shield"] = 100,
    ["costume_armor"] = 109,
    ["costume_hair"] = 110,
    ["costume_weapon"] = 111
};

function string_in_table(s, t)
    return t[s] ~= nil;
end -- function

function item.is_worn(itype)
    if (not string_in_table(itype, slottypes)) then
        return false;
    end -- if
  
    local itemcell = slottypes[itype];
    item.select_cell(itemcell);

    return item.get_cell() == itemcell;
end -- function

function item.select_cell_check(itype)
    if (not string_in_table(itype, slottypes) or not item.is_worn(itype)) then
    	return;
    end -- if
  
    local itemcell = slottypes[itype];
    item.select_cell(itemcell);
end -- function

function item.get_worn_vnum(itype)
    item.select_cell_check(itype);
    return item.get_vnum();
end -- function

function item.get_worn_wearflag(itype)
    item.select_cell_check(itype);
    return item.get_wearflag();
end -- function

function item.get_worn_flag(itype)
    item.select_cell_check(itype);
    return item.get_flag();
end -- function

function item.get_wearflag()
    return mysql_query(string.format("SELECT wearflag FROM player.item_proto WHERE vnum = %d;", item.get_vnum()))[1];
end -- function

function item.get_flag()
    return mysql_query(string.format("SELECT flag FROM player.item_proto WHERE vnum = %d;", item.get_vnum()))[1];
end -- function

 

  • Love 3

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.