• 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 Downgrading a 1.x script to 0.4

lolipop00

New Member
Joined
Oct 6, 2016
Messages
35
Reaction score
3
Hello everyone, i'm wondering if someone could downgrade this script for me to its compatible with TFS 0.4. I am sure many znote aac users that use 0.4 will also benifit from this :d

Lua:
function onThink(interval, lastExecution)
    local orderQuery = db.storeQuery([[
        SELECT
            MIN(`po`.`player_id`) AS `player_id`,
            `shop`.`id`,
            `shop`.`type`,
            `shop`.`itemid`,
            `shop`.`count`
        FROM `players_online` AS `po`
        INNER JOIN `players` AS `p`
            ON `po`.`player_id` = `p`.`id`
        INNER JOIN `znote_shop_orders` AS `shop`
            ON `p`.`account_id` = `shop`.`account_id`
        WHERE `shop`.`type` IN(1,5,6)
        GROUP BY `shop`.`id`
    ]])
    -- Detect if we got any results
    if orderQuery ~= false then
        local type_desc = {
            "itemids",
            "pending premium (skip)",
            "pending gender change (skip)",
            "pending character name change (skip)",
            "Outfit and addons",
            "Mounts"
        }
        repeat
            local player_id = result.getDataInt(orderQuery, 'player_id')
            local orderId = result.getDataInt(orderQuery, 'id')
            local orderType = result.getDataInt(orderQuery, 'type')
            local orderItemId = result.getDataInt(orderQuery, 'itemid')
            local orderCount = result.getDataInt(orderQuery, 'count')
            local served = false

            local player = Player(player_id)
            if player ~= nil then
                print("Processing shop order for: [".. player:getName() .."] type "..orderType..": ".. type_desc[orderType])
                local tile = Tile(player:getPosition())
                if tile ~= nil and tile:hasFlag(TILESTATE_PROTECTIONZONE) then
                    -- ORDER TYPE 1 (Regular item shop products)
                    if orderType == 1 then
                        served = true
                        -- Get wheight
                        if player:getFreeCapacity() >= ItemType(orderItemId):getWeight(orderCount) then
                            db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
                            player:addItem(orderItemId, orderCount)
                            player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received " .. orderCount .. " x " .. ItemType(orderItemId):getName() .. "!")
                            print("Process complete. [".. player:getName() .."] has recieved " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".")
                        else
                            player:sendTextMessage(MESSAGE_STATUS_WARNING, "You need more CAP to carry this order!")
                            print("Process canceled. [".. player:getName() .."] need more cap to carry " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".")
                        end
                    end

                    -- ORDER TYPE 5 (Outfit and addon)
                    if orderType == 5 then
                        served = true
                        -- Make sure player don't already have this outfit and addon
                        if not player:hasOutfit(orderItemId, orderCount) then
                            db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
                            player:addOutfit(orderItemId)
                            player:addOutfitAddon(orderItemId, orderCount)
                            player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!")
                            print("Process complete. [".. player:getName() .."] has recieved outfit: ["..orderItemId.."] with addon: ["..orderCount.."]")
                        else
                            player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!")
                            print("Process canceled. [".. player:getName() .."] already have outfit: ["..orderItemId.."] with addon: ["..orderCount.."].")
                        end
                    end

                    -- ORDER TYPE 6 (Mounts)
                    if orderType == 6 then
                        served = true
                        -- Make sure player don't already have this outfit and addon
                        if not player:hasMount(orderItemId) then
                            db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
                            player:addMount(orderItemId)
                            player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new mount!")
                            print("Process complete. [".. player:getName() .."] has recieved mount: ["..orderItemId.."]")
                        else
                            player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this mount!")
                            print("Process canceled. [".. player:getName() .."] already have mount: ["..orderItemId.."].")
                        end
                    end

                    -- If this order hasn't been processed yet (missing type handling?)
                    if not served then
                        print("Znote shop: Type ["..orderType.."] not properly processed. Missing Lua code?")
                    end
                else
                    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have a pending shop order, please enter protection zone.')
                    print("Skipped one shop order. Reason: Player: [".. player:getName() .."] is not inside protection zone.")
                end
            else
                print("Skipped one shop order. Reason: Player with id [".. player_id .."] is not online.")
            end

        until not result.next(orderQuery)
        result.free(orderQuery)
    end
    return true
end
 
Solution
Hey dude, I know you don't usually do more of 0.4 scripts so I just want to thank you for taking your time, its working perfectly, exept for one thing. Outside of PZ it will not go say "You have a pending shop order.." and I do get errors
Lua:
[21:33:10.492] [Error - CreatureScript Interface]
[21:33:10.492] In a timer event called from:
[21:33:10.492] data/creaturescripts/scripts/znoteShop.lua:onLogin
[21:33:10.492] Description:
[21:33:10.492] (luaDoPlayerSendTextMessage) Player not found

[21:33:10.493] [Error - CreatureScript Interface]
[21:33:10.493] In a timer event called from:
[21:33:10.493] data/creaturescripts/scripts/znoteShop.lua:onLogin
[21:33:10.493] Description:
[21:33:10.493]...
Thank you, yes I did get some errors

Lua:
[14:3:56.419] mysql_real_query():         SELECT
[14:3:56.420]             MIN(`po`.`player_id`) AS `player_id`,
[14:3:56.420]             `shop`.`id`,
[14:3:56.420]             `shop`.`type`,
[14:3:56.420]             `shop`.`itemid`,
[14:3:56.420]             `shop`.`count`
[14:3:56.420]         FROM `players_online` AS `po`
[14:3:56.421]         INNER JOIN `players` AS `p`
[14:3:56.421]             ON `po`.`player_id` = `p`.`id`
[14:3:56.421]         INNER JOIN `znote_shop_orders` AS `shop`
[14:3:56.421]             ON `p`.`account_id` = `shop`.`account_id`
[14:3:56.421]         WHERE `shop`.`type` IN(1,5,6)
[14:3:56.421]         GROUP BY `shop`.`id`
[14:3:56.421]      - MYSQL ERROR: Table 'tfs.players_online' doesn't exist (1146)
Try to change
Lua:
FROM `players_online` AS `po`
to
Lua:
FROM `online` AS `po`
 
Found this, don't really know if could help you haven't tested
Lua:
-- ### CONFIG ###
-- message send to player by script "type" (types you can check in "global.lua")
SHOP_MSG_TYPE = 18
-- time (in seconds) between connections to SQL database by shop script
SQL_interval = 30
-- ### END OF CONFIG ###
function onThink(interval, lastExecution)
  local result_plr = db.storeQuery("SELECT * FROM z_ots_comunication")
  if(result_plr ~= false) then
  repeat
  local id = tonumber(result.getDataInt(result_plr, "id"))
  local action = tostring(result.getDataString(result_plr, "action"))
  local delete = tonumber(result.getDataInt(result_plr, "delete_it"))
  local cid = getPlayerByName(tostring(result.getDataString(result_plr, "name")))
  if(cid) then
  local itemtogive_id = tonumber(result.getDataInt(result_plr, "param1"))
  local itemtogive_count = tonumber(result.getDataInt(result_plr, "param2"))
  local container_id = tonumber(result.getDataInt(result_plr, "param3"))
  local container_count = tonumber(result.getDataInt(result_plr, "param4"))
  local add_item_type = tostring(result.getDataString(result_plr, "param5"))
  local add_item_name = tostring(result.getDataString(result_plr, "param6"))
  local received_item = 0
  local full_weight = 0
  if(add_item_type == 'container') then
  container_weight = getItemWeight(container_id, 1)
  if(isItemRune(itemtogive_id)) then
  items_weight = container_count * getItemWeight(itemtogive_id, 1)
  else
  items_weight = container_count * getItemWeight(itemtogive_id, itemtogive_count)
  end
  full_weight = items_weight + container_weight
  else
  full_weight = getItemWeight(itemtogive_id, itemtogive_count)
  if(isItemRune(itemtogive_id)) then
  full_weight = getItemWeight(itemtogive_id, 1)
  else
  full_weight = getItemWeight(itemtogive_id, itemtogive_count)
  end
  end
  local free_cap = getPlayerFreeCap(cid)
  if(full_weight <= free_cap) then
  if(add_item_type == 'container') then
  local new_container = doCreateItemEx(container_id, 1)
  local iter = 0
  while(iter ~= container_count) do
  doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
  iter = iter + 1
  end
  received_item = doPlayerAddItemEx(cid, new_container)
  else
  local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
  received_item = doPlayerAddItemEx(cid, new_item)
  end
  if(type(received_item) == "number" and received_item == RETURNVALUE_NOERROR) then
  doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received >> '.. add_item_name ..' << from OTS shop.')
  db.query("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
  db.query("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
  else
  doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
  end
  else
  doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. It weight is '.. full_weight ..' oz., you have only '.. free_cap ..' oz. free capacity. Put some items in depot and wait about '.. SQL_interval ..' seconds to get it.')
  end
  end
  until not result.next(result_plr)
  result.free(result_plr)
  end
  return true
end
 
I have not tested it, I have only changed each function to be compatible with the old TFS version
Lua:
function onThink(interval, lastExecution)
    local orderQuery = db.storeQuery([[
        SELECT
            MIN(`po`.`player_id`) AS `player_id`,
            `shop`.`id`,
            `shop`.`type`,
            `shop`.`itemid`,
            `shop`.`count`
        FROM `players_online` AS `po`
        INNER JOIN `players` AS `p`
            ON `po`.`player_id` = `p`.`id`
        INNER JOIN `znote_shop_orders` AS `shop`
            ON `p`.`account_id` = `shop`.`account_id`
        WHERE `shop`.`type` IN(1,5,6)
        GROUP BY `shop`.`id`
    ]])
    -- Detect if we got any results
    if orderQuery ~= false then
        local type_desc = {
            "itemids",
            "pending premium (skip)",
            "pending gender change (skip)",
            "pending character name change (skip)",
            "Outfit and addons",
            "Mounts"
        }
        repeat
            local player_id = result.getDataInt(orderQuery, 'player_id')
            local orderId = result.getDataInt(orderQuery, 'id')
            local orderType = result.getDataInt(orderQuery, 'type')
            local orderItemId = result.getDataInt(orderQuery, 'itemid')
            local orderCount = result.getDataInt(orderQuery, 'count')
            local served = false

            local player = getPlayerByGUID(player_id)
            if player ~= nil then
                local playerName = getCreatureName(player)
                print("Processing shop order for: [".. playerName.."] type "..orderType..": ".. type_desc[orderType])
                if getTileInfo(getCreaturePosition(player), "protection") then
                    -- ORDER TYPE 1 (Regular item shop products)
                    if orderType == 1 then
                        served = true
                        -- Get wheight
                        local itemType = getItemInfo(orderItemId)
                        if getPlayerFreeCap(player) >= (itemType.weight * orderCount) then
                            db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
                            doPlayerAddItem(player, orderItemId, orderCount)
                            doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Congratulations! You have received " .. orderCount .. " x " .. itemType.name .. "!")
                            print("Process complete. [".. playerName .."] has recieved " .. orderCount .. "x " .. itemType.name .. ".")
                        else
                            doPlayerSendTextMessage(player, MESSAGE_STATUS_WARNING, "You need more CAP to carry this order!")
                            print("Process canceled. [".. playerName .."] need more cap to carry " .. orderCount .. "x " .. itemType.name .. ".")
                        end
                    end

                    -- ORDER TYPE 5 (Outfit and addon)
                    if orderType == 5 then
                        served = true
                        -- Make sure player don't already have this outfit and addon
                        if not canPlayerWearOutfitId(player, orderItemId, orderCount) then
                            db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
                            doPlayerAddOutfitId(orderItemId, orderCount)
                            doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!")
                            print("Process complete. [".. playerName.."] has recieved outfit: ["..orderItemId.."] with addon: ["..orderCount.."]")
                        else
                            doPlayerSendTextMessage(player, MESSAGE_STATUS_WARNING, "You already have this outfit and addon!")
                            print("Process canceled. [".. playerName.."] already have outfit: ["..orderItemId.."] with addon: ["..orderCount.."].")
                        end
                    end

                    -- If this order hasn't been processed yet (missing type handling?)
                    if not served then
                        print("Znote shop: Type ["..orderType.."] not properly processed. Missing Lua code?")
                    end
                else
                    doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, 'You have a pending shop order, please enter protection zone.')
                    print("Skipped one shop order. Reason: Player: [".. playerName.."] is not inside protection zone.")
                end
            else
                print("Skipped one shop order. Reason: Player with id [".. player_id .."] is not online.")
            end

        until not result.next(orderQuery)
        result.free(orderQuery)
    end
    return true
end

I hope it works for you and if it does not work, remember to leave the error report here so that we can continue to help you
 
I have not tested it, I have only changed each function to be compatible with the old TFS version
Lua:
function onThink(interval, lastExecution)
    local orderQuery = db.storeQuery([[
        SELECT
            MIN(`po`.`player_id`) AS `player_id`,
            `shop`.`id`,
            `shop`.`type`,
            `shop`.`itemid`,
            `shop`.`count`
        FROM `players_online` AS `po`
        INNER JOIN `players` AS `p`
            ON `po`.`player_id` = `p`.`id`
        INNER JOIN `znote_shop_orders` AS `shop`
            ON `p`.`account_id` = `shop`.`account_id`
        WHERE `shop`.`type` IN(1,5,6)
        GROUP BY `shop`.`id`
    ]])
    -- Detect if we got any results
    if orderQuery ~= false then
        local type_desc = {
            "itemids",
            "pending premium (skip)",
            "pending gender change (skip)",
            "pending character name change (skip)",
            "Outfit and addons",
            "Mounts"
        }
        repeat
            local player_id = result.getDataInt(orderQuery, 'player_id')
            local orderId = result.getDataInt(orderQuery, 'id')
            local orderType = result.getDataInt(orderQuery, 'type')
            local orderItemId = result.getDataInt(orderQuery, 'itemid')
            local orderCount = result.getDataInt(orderQuery, 'count')
            local served = false

            local player = getPlayerByGUID(player_id)
            if player ~= nil then
                local playerName = getCreatureName(player)
                print("Processing shop order for: [".. playerName.."] type "..orderType..": ".. type_desc[orderType])
                if getTileInfo(getCreaturePosition(player), "protection") then
                    -- ORDER TYPE 1 (Regular item shop products)
                    if orderType == 1 then
                        served = true
                        -- Get wheight
                        local itemType = getItemInfo(orderItemId)
                        if getPlayerFreeCap(player) >= (itemType.weight * orderCount) then
                            db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
                            doPlayerAddItem(player, orderItemId, orderCount)
                            doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Congratulations! You have received " .. orderCount .. " x " .. itemType.name .. "!")
                            print("Process complete. [".. playerName .."] has recieved " .. orderCount .. "x " .. itemType.name .. ".")
                        else
                            doPlayerSendTextMessage(player, MESSAGE_STATUS_WARNING, "You need more CAP to carry this order!")
                            print("Process canceled. [".. playerName .."] need more cap to carry " .. orderCount .. "x " .. itemType.name .. ".")
                        end
                    end

                    -- ORDER TYPE 5 (Outfit and addon)
                    if orderType == 5 then
                        served = true
                        -- Make sure player don't already have this outfit and addon
                        if not canPlayerWearOutfitId(player, orderItemId, orderCount) then
                            db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
                            doPlayerAddOutfitId(orderItemId, orderCount)
                            doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!")
                            print("Process complete. [".. playerName.."] has recieved outfit: ["..orderItemId.."] with addon: ["..orderCount.."]")
                        else
                            doPlayerSendTextMessage(player, MESSAGE_STATUS_WARNING, "You already have this outfit and addon!")
                            print("Process canceled. [".. playerName.."] already have outfit: ["..orderItemId.."] with addon: ["..orderCount.."].")
                        end
                    end

                    -- If this order hasn't been processed yet (missing type handling?)
                    if not served then
                        print("Znote shop: Type ["..orderType.."] not properly processed. Missing Lua code?")
                    end
                else
                    doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, 'You have a pending shop order, please enter protection zone.')
                    print("Skipped one shop order. Reason: Player: [".. playerName.."] is not inside protection zone.")
                end
            else
                print("Skipped one shop order. Reason: Player with id [".. player_id .."] is not online.")
            end

        until not result.next(orderQuery)
        result.free(orderQuery)
    end
    return true
end

I hope it works for you and if it does not work, remember to leave the error report here so that we can continue to help you
Thank you, yes I did get some errors

Lua:
[14:3:56.419] mysql_real_query():         SELECT
[14:3:56.420]             MIN(`po`.`player_id`) AS `player_id`,
[14:3:56.420]             `shop`.`id`,
[14:3:56.420]             `shop`.`type`,
[14:3:56.420]             `shop`.`itemid`,
[14:3:56.420]             `shop`.`count`
[14:3:56.420]         FROM `players_online` AS `po`
[14:3:56.421]         INNER JOIN `players` AS `p`
[14:3:56.421]             ON `po`.`player_id` = `p`.`id`
[14:3:56.421]         INNER JOIN `znote_shop_orders` AS `shop`
[14:3:56.421]             ON `p`.`account_id` = `shop`.`account_id`
[14:3:56.421]         WHERE `shop`.`type` IN(1,5,6)
[14:3:56.421]         GROUP BY `shop`.`id`
[14:3:56.421]      - MYSQL ERROR: Table 'tfs.players_online' doesn't exist (1146)
 
Back
Top