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

Pure Lua - Znote PHP Shop Makers

Status
Not open for further replies.

OT World

Banned User
Joined
Apr 1, 2017
Messages
51
Solutions
4
Reaction score
9
These scripts just allow you to parse the mounts, outfits and items, the items script is an edited version of @zbizu's item parser. The items and outfit's parser are edited versions of @Codex NG's parsers for 1.2

Sources
Parsers for 1.2

[TFS 1.1] Items parser (useful for searching ids)

Outfits
Lua:
-- location of outfits.xml
local file = "/home/user/forgottenserver/data/XML/outfits.xml"
-- save location of outfitsphp.lua
local fileEx = '/home/user/outfitsphp.lua'
local outputFile = fileEx
local items = {}

function isInArray(a, f)
  for k, v in pairs(a) do
      if f == v then
        return true
      end
  end
  return false
end

local para = {
    {'t', "type\" => 5"}, -- the type default is 5
    {'looktype', 'itemid'}, -- the looktype is the itemid
    {'c', 'count\" => 3'}, -- 3 refers to both addons
    {'name', 'description'}, -- name as description
    {'p', 'points\" => 20'} -- the cost
  }

-- where in the array to start counting
local startIndex = 7

-- these indexes are not located in the xml attributes but are required by the php array
local specialIndex = {'t', 'c', 'p'}
function parseOutfits()
    local k = {}
   
    for line in io.lines(file) do
        if string.match(line, '<(%a-)%s* ') ~= nil then
            local itemParam =  string.match(line, '<(%a-)%s* ')
            if itemParam ~= nil then
                for type_ in line:gmatch(itemParam) do
                    for i = 1, #para do
                        if isInArray(specialIndex, para[i][1]) then
                              table.insert(k, '    "'..para[i][2]..',\n')
                        end
                        if line:match(para[i][1]..'="(.-)"') then
                            value = line:match(para[i][1]..'="(.-)"')
                            if type(tonumber(value)) ~= "number" then
                              value = '\"'..value..'\"'
                            end
                            table.insert(k, '    "'..para[i][2]..'" => '..value..',\n')
                        end
                    end
                    local temp = startIndex..' => array(\n'..table.concat(k)
                    temp = temp:sub(1, #temp - 2)..'\n),'
                    startIndex = startIndex + 1
                    k = {}
                    table.insert(items, temp)
                end
            end
        end
    end
   
    fileEx = io.open(fileEx, "w+")
    for k, v in pairs(items)do
        fileEx:write(v)
    end
    fileEx:close()
    print("#############################")
    print("File saved as " .. outputFile)
    print("----")
    print("Outfits loaded: " .. #items)
end
parseOutfits()
Code:
#############################
File saved as /home/user/outfitsphp.lua
----
Outfits loaded: 110
Program completed in 1.12 seconds (pid: 14856).
Sample:
PHP:
7 => array(
    "type" => 5,
    "itemid" => 136,
    "count" => 3,
    "description" => "Citizen",
    "points" => 20
),8 => array(
    "type" => 5,
    "itemid" => 137,
    "count" => 3,
    "description" => "Hunter",
    "points" => 20
),9 => array(
    "type" => 5,
    "itemid" => 138,
    "count" => 3,
    "description" => "Mage",
    "points" => 20
)

mounts
Lua:
-- location of mounts.xml
local file = "/home/user/forgottenserver/data/XML/mounts.xml"
-- save location of mountsphp.lua
local fileEx = '/home/user/mountsphp.lua'
local outputFile = fileEx
function isInArray(a, f)
  for k, v in pairs(a) do
      if f == v then
        return true
      end
  end
  return false
end
local items = {}
local para = {
    {'t', "type\" => 6"}, -- the type default is 6
    {'id', 'itemid'}, -- the id is the itemid
    {'c', 'count\" => 1'}, -- default ...
    {'name', 'description'}, -- name as description
    {'speed', 'points'} -- using speed to set price of mount
  }
-- these indexes are not located in the xml attributes but are required by the php array
local specialIndex = {'t', 'c'}
-- where in the array to start counting
local startIndex =117
function parseMounts()
    local k = {}
    for line in io.lines(file) do
        if string.match(line, '<(%a-)%s* ') ~= nil then
            local itemParam =  string.match(line, '<(%a-)%s* ')
            if itemParam ~= nil then
                for type_ in line:gmatch(itemParam) do
                    for i = 1, #para do
                        if isInArray(specialIndex, para[i][1]) then
                              table.insert(k, '    "'..para[i][2]..',\n')
                        end
                        if line:match(para[i][1]..'="(.-)"') then
                            value = line:match(para[i][1]..'="(.-)"')
                            if type(tonumber(value)) ~= "number" then
                              value = '\"'..value..'\"'
                            end
                            table.insert(k, '    "'..para[i][2]..'" => '..value..',\n')
                        end
                    end
                    local temp = startIndex..' => array(\n'..table.concat(k)
                    temp = temp:sub(1, #temp - 2)..'\n),'
                    startIndex = startIndex + 1
                    k = {}
                    table.insert(items, temp)
                end
            end
        end
    end
    fileEx = io.open(fileEx, "w+")
    for k, v in pairs(items)do
        fileEx:write(v)
    end
    fileEx:close()
    print("#############################")
    print("File saved as " .. outputFile)
    print("----")
    print("Mounts loaded: " .. #items)
end
parseMounts()
Code:
#############################
File saved as /home/user/mountsphp.lua
----
Mounts loaded: 102
Program completed in 2.41 seconds (pid: 15004)
Sample:
PHP:
117 => array(
    "type" => 6,
    "itemid" => 1,
    "count" => 1,
    "description" => "Widow Queen",
    "points" => 20
),118 => array(
    "type" => 6,
    "itemid" => 2,
    "count" => 1,
    "description" => "Racing Bird",
    "points" => 20
),119 => array(
    "type" => 6,
    "itemid" => 3,
    "count" => 1,
    "description" => "War Bear",
    "points" => 20
),

items
Lua:
table.find = function(table, value)
    for i, v in pairs(table) do
        if v == value then
            return i
        end
    end
    return false
end
-- where to start counting in the array
local startIndex = 10
-- count the number of items created
local count = 0
function parseItems()
    -- location of items.xml
    local file = '/home/user/forgottenserver/data/items/items.xml'
    -- save location of items.lua
    local fileEx = '/home/user/items.lua'
    local outputFile = fileEx
    local items = {}
    
    for line in io.lines(file) do
        for mi,id,mid,name in line:gmatch('<(%a-)%s*id%s*=%s*"(%d+)"%s*(.-)%s*name%s*=%s*"(.-)"') do
        if mi == 'item' then
            table.insert(items, {id = id, name = name})
        end
        end
        for key,value in line:gmatch('<attribute key="(.-)" value="(.-)"') do
            if key == "slotType" or key == "weaponType" then
                items[#items].slot = value
            end
        end
    end
    local types = {}
    for i = 1, #items do
        if items[i].slot then
        if not table.find(types, items[i].slot) then
            table.insert(types, items[i].slot)
        end
        end
    end
    fileEx = io.open(fileEx, "w+")
    for i = 1, #items do
        if items[i].slot then
            count = count + 1
            fileEx:write(
            startIndex .. " => array(\n"
            .."    'type' => 4,\n" -- default is 4
            .."    'itemid' => ".. items[i].id ..",\n" -- itemid
            .."    'count' => 1,\n" -- default count
            .."    'description' => \""..items[i].name.."\",\n" -- name of the item
            .."    'points' => 20,\n" -- cost in points
            .."),\n"
          )
          startIndex = startIndex + 1
        end
    end
    for a = 1, #types do
        for b = 1, #items do
            if items[b].slot then
                if items[b].slot == types[a] then
                end
            end
        end
    end
    fileEx:close()
    print("#############################")
    print("File saved as " .. outputFile)
    print("----")
    print("Items created: " .. count)
return true
end

parseItems()
Code:
#############################
File saved as /home/user/items.lua
----
Items created: 878
Program completed in 2.65 seconds (pid: 15081
Sample:
PHP:
10 => array(
    'type' => 4,
    'itemid' => 1294,
    'count' => 1,
    'description' => "small stone",
    'points' => 20,
),
11 => array(
    'type' => 4,
    'itemid' => 1987,
    'count' => 1,
    'description' => "bag",
    'points' => 20,
),
12 => array(
    'type' => 4,
    'itemid' => 1988,
    'count' => 1,
    'description' => "backpack",
    'points' => 20,
),
13 => array(
    'type' => 4,
    'itemid' => 1991,
    'count' => 1,
    'description' => "green bag",
    'points' => 20,
),

You will need a lua interpreter in order to use these scripts as they are.
 
Status
Not open for further replies.
Back
Top