Various optimization to config.php and LUA scripts

* Update config.php
* spaces to tabs and new line at eof
* updated playerdeath.lua to match latest one from master
This commit is contained in:
Evil Puncker 2020-05-29 16:40:28 -03:00 committed by GitHub
parent a78d26b103
commit e056898f31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 404 additions and 397 deletions

View File

@ -1,6 +1,6 @@
function onLogin(cid)
local storage = 30055 -- storage value
local sorcItems = {
2460, -- Brass helmet
2465, -- Brass armor
@ -39,39 +39,39 @@ function onLogin(cid)
1988, -- Brown backpack
2050 -- torch
}
if getPlayerStorageValue(cid, storage) == -1 then
setPlayerStorageValue(cid, storage, 1)
if getPlayerVocation(cid) == 1 then
-- Sorcerer
for i = 1, table.getn(sorcItems), 1 do
doPlayerAddItem(cid, sorcItems[i], 1, FALSE)
doPlayerAddItem(cid, sorcItems[i], 1, false)
end
elseif getPlayerVocation(cid) == 2 then
-- Druid
for i = 1, table.getn(druidItems), 1 do
doPlayerAddItem(cid, druidItems[i], 1, FALSE)
doPlayerAddItem(cid, druidItems[i], 1, false)
end
elseif getPlayerVocation(cid) == 3 then
-- Paladin
for i = 1, table.getn(pallyItems), 1 do
doPlayerAddItem(cid, pallyItems[i], 1, FALSE)
doPlayerAddItem(cid, pallyItems[i], 1, false)
end
-- 8 arrows
doPlayerAddItem(cid, 2544, 8, FALSE)
doPlayerAddItem(cid, 2544, 8, false)
elseif getPlayerVocation(cid) == 4 then
-- Knight
for i = 1, table.getn(kinaItems), 1 do
doPlayerAddItem(cid, kinaItems[i], 1, FALSE)
doPlayerAddItem(cid, kinaItems[i], 1, false)
end
end
-- Common for all
doPlayerAddItem(cid, 2674, 5, FALSE) -- 5 apples
doPlayerAddItem(cid, 2120, 1, FALSE) -- 1 rope
doPlayerAddItem(cid, 2674, 5, false) -- 5 apples
doPlayerAddItem(cid, 2120, 1, false) -- 1 rope
end
return true
end

View File

@ -2,11 +2,11 @@
function onSay(cid, words, param)
local storage = 54073 -- Make sure to select non-used storage. This is used to prevent SQL load attacks.
local cooldown = 15 -- in seconds.
if getPlayerStorageValue(cid, storage) <= os.time() then
setPlayerStorageValue(cid, storage, os.time() + cooldown)
local accid = getAccountNumberByPlayerName(getCreatureName(cid))
local type_desc = {
"itemids",
"pending premium (skip)",
@ -34,17 +34,17 @@ function onSay(cid, words, param)
description = type_desc[q_type]
end
print("Processing type "..q_type..": ".. description)
-- ORDER TYPE 1 (Regular item shop products)
if q_type == 1 then
served = true
-- Get wheight
-- Get weight
local playerCap = getPlayerFreeCap(cid)
local itemweight = getItemWeight(q_itemid, q_count)
if playerCap >= itemweight then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
doPlayerAddItem(cid, q_itemid, q_count)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have recieved ".. q_count .." "..getItemName(q_itemid).."(s)!")
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received ".. q_count .." "..getItemName(q_itemid).."(s)!")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Need more CAP!")
end
@ -77,7 +77,7 @@ function onSay(cid, words, param)
-- ORDER TYPE 6 (Mounts)
-- Not supported on TFS 0.2
-- Add custom order types here
-- Type 1 is for itemids (Already coded here)
-- Type 2 is for premium (Coded on web)

View File

@ -1,6 +1,6 @@
function onLogin(cid)
local storage = 30055 -- storage value
local sorcItems = {
2460, -- Brass helmet
2465, -- Brass armor
@ -39,39 +39,39 @@ function onLogin(cid)
1988, -- Brown backpack
2050 -- torch
}
if getPlayerStorageValue(cid, storage) == -1 then
setPlayerStorageValue(cid, storage, 1)
if getPlayerVocation(cid) == 1 then
-- Sorcerer
for i = 1, table.getn(sorcItems), 1 do
doPlayerAddItem(cid, sorcItems[i], 1, FALSE)
doPlayerAddItem(cid, sorcItems[i], 1, false)
end
elseif getPlayerVocation(cid) == 2 then
-- Druid
for i = 1, table.getn(druidItems), 1 do
doPlayerAddItem(cid, druidItems[i], 1, FALSE)
doPlayerAddItem(cid, druidItems[i], 1, false)
end
elseif getPlayerVocation(cid) == 3 then
-- Paladin
for i = 1, table.getn(pallyItems), 1 do
doPlayerAddItem(cid, pallyItems[i], 1, FALSE)
doPlayerAddItem(cid, pallyItems[i], 1, false)
end
-- 8 arrows
doPlayerAddItem(cid, 2544, 8, FALSE)
doPlayerAddItem(cid, 2544, 8, false)
elseif getPlayerVocation(cid) == 4 then
-- Knight
for i = 1, table.getn(kinaItems), 1 do
doPlayerAddItem(cid, kinaItems[i], 1, FALSE)
doPlayerAddItem(cid, kinaItems[i], 1, false)
end
end
-- Common for all
doPlayerAddItem(cid, 2674, 5, FALSE) -- 5 apples
doPlayerAddItem(cid, 2120, 1, FALSE) -- 1 rope
doPlayerAddItem(cid, 2674, 5, false) -- 5 apples
doPlayerAddItem(cid, 2120, 1, false) -- 1 rope
end
return true
end

View File

@ -2,11 +2,11 @@
function onSay(cid, words, param)
local storage = 54073 -- Make sure to select non-used storage. This is used to prevent SQL load attacks.
local cooldown = 15 -- in seconds.
if getPlayerStorageValue(cid, storage) <= os.time() then
setPlayerStorageValue(cid, storage, os.time() + cooldown)
local accid = getAccountNumberByPlayerName(getCreatureName(cid))
local type_desc = {
"itemids",
"pending premium (skip)",
@ -35,7 +35,7 @@ function onSay(cid, words, param)
description = type_desc[q_type]
end
print("Processing type "..q_type..": ".. description)
-- ORDER TYPE 1 (Regular item shop products)
if q_type == 1 then
served = true
@ -91,7 +91,7 @@ function onSay(cid, words, param)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this mount!")
end
end
-- Add custom order types here
-- Type 1 is for itemids (Already coded here)
-- Type 2 is for premium (Coded on web)
@ -115,4 +115,4 @@ function onSay(cid, words, param)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every "..cooldown.." seconds. Remaining cooldown: ".. getPlayerStorageValue(cid, storage) - os.time())
end
return false
end
end

View File

@ -2,11 +2,11 @@
function onSay(cid, words, param)
local storage = 54073 -- Make sure to select non-used storage. This is used to prevent SQL load attacks.
local cooldown = 15 -- in seconds.
if getPlayerStorageValue(cid, storage) <= os.time() then
setPlayerStorageValue(cid, storage, os.time() + cooldown)
local accid = getAccountNumberByPlayerName(getCreatureName(cid))
local type_desc = {
"itemids",
"pending premium (skip)",
@ -29,28 +29,28 @@ function onSay(cid, words, param)
local q_type = result.getDataInt(orderQuery, "type")
local q_itemid = result.getDataInt(orderQuery, "itemid")
local q_count = result.getDataInt(orderQuery, "count")
local description = "Unknown or custom type"
if type_desc[q_type] ~= nil then
description = type_desc[q_type]
end
print("Processing type "..q_type..": ".. description)
-- ORDER TYPE 1 (Regular item shop products)
if q_type == 1 then
served = true
-- Get wheight
-- Get weight
local playerCap = getPlayerFreeCap(cid)
local itemweight = getItemWeightById(q_itemid, q_count)
if playerCap >= itemweight and getTileInfo(getCreaturePosition(cid)).protection then
--backpack check
-- backpack check
local backpack = getPlayerSlotItem(cid, 3)
local gotItem = false
if(backpack and backpack.itemid > 0) then
local received = doAddContainerItem(getPlayerSlotItem(cid, 3).uid, q_itemid,q_count)
if(received ~= false) then
db.executeQuery("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have recieved ".. q_count .." "..getItemNameById(q_itemid).."(s)!")
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have received ".. q_count .." "..getItemNameById(q_itemid).."(s)!")
gotItem = true
end
end
@ -100,7 +100,7 @@ function onSay(cid, words, param)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You already have this mount!")
end
end
-- Add custom order types here
-- Type 1 is for itemids (Already coded here)
-- Type 2 is for premium (Coded on web)
@ -120,9 +120,9 @@ function onSay(cid, words, param)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every "..cooldown.." seconds. Remaining cooldown: ".. getPlayerStorageValue(cid, storage) - os.time())
end
return false
end
end

View File

@ -1,4 +1,4 @@
Step 1: Copy firstitems.lua to /data/creaturescripts/scripts/ folder
-- Edit firstitems.lua with item IDs you want characters to start with on your server.
Step 2: Restart OT server, and it should work. :)
Step 2: Restart OT server, and it should work. :)

View File

@ -1,17 +1,16 @@
-- With Rookgaard
--[[
local firstItems = {2050, 2382}
local firstItems = {2050, 2382} -- torch and club
function onLogin(cid)
local player = Player(cid)
function onLogin(player)
if player:getLastLoginSaved() <= 0 then
for i = 1, #firstItems do
player:addItem(firstItems[i], 1)
end
player:addItem(player:getSex() == 0 and 2651 or 2650, 1)
player:addItem(1987, 1)
player:addItem(2674, 1)
player:addItem(player:getSex() == 0 and 2651 or 2650, 1) -- coat
player:addItem(ITEM_BAG, 1)
player:addItem(2674, 1) -- red apple
end
return true
end
@ -19,34 +18,33 @@ end
-- Without Rookgaard
local config = {
[1] = {
--equipment spellbook, wand of vortex, magician's robe, mage hat, studded legs, leather boots, scarf
items = {{2175, 1}, {2190, 1}, {8819, 1}, {8820, 1}, {2468, 1}, {2643, 1}, {2661, 1}},
--container rope, shovel, mana potion
container = {{2120, 1}, {2554, 1}, {7620, 1}}
},
[2] = {
--equipment spellbook, snakebite rod, magician's robe, mage hat, studded legs, leather boots scarf
items = {{2175, 1}, {2182, 1}, {8819, 1}, {8820, 1}, {2468, 1}, {2643, 1}, {2661, 1}},
--container rope, shovel, mana potion
container = {{2120, 1}, {2554, 1}, {7620, 1}}
},
[3] = {
--equipment dwrven shield, 5 spear, ranger's cloak, ranger legs scarf, legion helmet
items = {{2525, 1}, {2389, 5}, {2660, 1}, {8923, 1}, {2643, 1}, {2661, 1}, {2480, 1}},
--container rope, shovel, health potion, bow, 50 arrow
container = {{2120, 1}, {2554, 1}, {7618, 1}, {2456, 1}, {2544, 50}}
},
[4] = {
--equipment dwarven shield, steel axe, brass armor, brass helmet, brass legs scarf
items = {{2525, 1}, {8601, 1}, {2465, 1}, {2460, 1}, {2478, 1}, {2643, 1}, {2661, 1}},
--container jagged sword, daramian mace, rope, shovel, health potion
container = {{8602, 1}, {2439, 1}, {2120, 1}, {2554, 1}, {7618, 1}}
}
[1] = { -- Sorcerer
-- equipment: spellbook, wand of vortex, magician's robe, mage hat, studded legs, leather boots, scarf
items = {{2175, 1}, {2190, 1}, {8819, 1}, {8820, 1}, {2468, 1}, {2643, 1}, {2661, 1}},
-- container: rope, shovel, mana potion
container = {{2120, 1}, {2554, 1}, {7620, 1}}
},
[2] = { -- Druid
-- equipment: spellbook, snakebite rod, magician's robe, mage hat, studded legs, leather boots, scarf
items = {{2175, 1}, {2182, 1}, {8819, 1}, {8820, 1}, {2468, 1}, {2643, 1}, {2661, 1}},
-- container: rope, shovel, mana potion
container = {{2120, 1}, {2554, 1}, {7620, 1}}
},
[3] = { -- Paladin
-- equipment: dwarven shield, 5 spear, ranger's cloak, ranger legs, scarf, legion helmet
items = {{2525, 1}, {2389, 5}, {2660, 1}, {8923, 1}, {2643, 1}, {2661, 1}, {2480, 1}},
-- container: rope, shovel, health potion, bow, 50 arrow
container = {{2120, 1}, {2554, 1}, {7618, 1}, {2456, 1}, {2544, 50}}
},
[4] = { -- Knight
-- equipment: dwarven shield, steel axe, brass armor, brass helmet, brass legs, scarf
items = {{2525, 1}, {8601, 1}, {2465, 1}, {2460, 1}, {2478, 1}, {2643, 1}, {2661, 1}},
-- container jagged sword, daramanian mace, rope, shovel, health potion
container = {{8602, 1}, {2439, 1}, {2120, 1}, {2554, 1}, {7618, 1}}
}
}
function onLogin(cid)
local player = Player(cid)
function onLogin(player)
local targetVocation = config[player:getVocation():getId()]
if not targetVocation then
return true

View File

@ -32,8 +32,11 @@ local function sendWarStatus(guildId, enemyGuildId, warId, playerName, killerNam
end
end
function onDeath(cid, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
local player = Player(cid)
function onDeath(player, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
local playerId = player:getId()
if nextUseStaminaTime[playerId] then
nextUseStaminaTime[playerId] = nil
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are dead.")
if not deathListEnabled then
@ -41,27 +44,25 @@ function onDeath(cid, corpse, killer, mostDamage, unjustified, mostDamage_unjust
end
local byPlayer = 0
local killerCreature = Creature(killer)
if not killerCreature then
killerName = "field item"
else
if killerCreature:isPlayer() then
local killerName
if killer then
if killer:isPlayer() then
byPlayer = 1
else
local master = killerCreature:getMaster()
if master and master ~= killerCreature and master:isPlayer() then
killerCreature = master
local master = killer:getMaster()
if master and master ~= killer and master:isPlayer() then
killer = master
byPlayer = 1
end
end
killerName = killerCreature:isMonster() and killerCreature:getType():getNameDescription() or killerCreature:getName()
killerName = killer:getName()
else
killerName = "field item"
end
local byPlayerMostDamage = 0
if mostDamage == 0 then
mostDamageName = "field item"
else
local mostDamageKiller = Creature(mostDamage)
local mostDamageKillerName
if mostDamageKiller then
if mostDamageKiller:isPlayer() then
byPlayerMostDamage = 1
else
@ -71,7 +72,9 @@ function onDeath(cid, corpse, killer, mostDamage, unjustified, mostDamage_unjust
byPlayerMostDamage = 1
end
end
mostDamageName = mostDamageKiller:isMonster() and mostDamageKiller:getType():getNameDescription() or mostDamageKiller:getName()
mostDamageName = mostDamageKiller:getName()
else
mostDamageName = "field item"
end
local playerGuid = player:getGuid()
@ -89,18 +92,18 @@ function onDeath(cid, corpse, killer, mostDamage, unjustified, mostDamage_unjust
result.free(resultId)
end
while deathRecords > maxDeathRecords do
db.query("DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT 1")
deathRecords = deathRecords - 1
local limit = deathRecords - maxDeathRecords
if limit > 0 then
db.asyncQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT " .. limit)
end
if byPlayer == 1 then
local targetGuild = player:getGuild()
targetGuild = targetGuild and targetGuild:getId() or 0
if targetGuild ~= 0 then
local killerGuild = killerCreature:getGuild()
local killerGuild = killer:getGuild()
killerGuild = killerGuild and killerGuild:getId() or 0
if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(cid, killerCreature) then
if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(playerId, killer:getId()) then
local warId = false
resultId = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = " .. killerGuild .. " AND `guild2` = " .. targetGuild .. ") OR (`guild1` = " .. targetGuild .. " AND `guild2` = " .. killerGuild .. "))")
if resultId ~= false then
@ -110,7 +113,7 @@ function onDeath(cid, corpse, killer, mostDamage, unjustified, mostDamage_unjust
if warId ~= false then
local playerName = player:getName()
db.query("INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES (" .. db.escapeString(killerName) .. ", " .. db.escapeString(playerName) .. ", " .. killerGuild .. ", " .. targetGuild .. ", " .. os.time() .. ", " .. warId .. ")")
db.asyncQuery("INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES (" .. db.escapeString(killerName) .. ", " .. db.escapeString(playerName) .. ", " .. killerGuild .. ", " .. targetGuild .. ", " .. os.time() .. ", " .. warId .. ")")
addEvent(sendWarStatus, 1000, killerGuild, targetGuild, warId, playerName, killerName)
end
end

View File

@ -1,8 +1,7 @@
1. Add below line to XML file: data/creaturescripts/creaturescripts.xml
<event type="login" name="znote_syncoutfits" script="syncoutfit.lua" />
2. Register event in login.lua: data/creaturescripts/scripts/login.lua
player:registerEvent("znote_syncoutfits")
3. Place Lua file syncoutfit.lua in folder: data/creaturescripts/scripts/
3. Place Lua file syncoutfit.lua in folder: data/creaturescripts/scripts/

View File

@ -2,7 +2,7 @@
-- can be added to data/global.lua if you want to use eternal storage for another purpose than this.
-- Regular TFS global storage values get reset every time server reboots. This does not.
local function getEternalStorage(key, parser)
local value = result.getDataString(db.storeQuery("SELECT `value` FROM `znote_global_storage` WHERE `key` = ".. key .. ";"), "value")
local value = result.getString(db.storeQuery("SELECT `value` FROM `znote_global_storage` WHERE `key` = ".. key .. ";"), "value")
if not value then
if parser then
return false
@ -22,6 +22,36 @@ local function setEternalStorage(key, value)
return true
end
-- SQL Query to execute: --
--[[
ALTER TABLE `znote_players` ADD `exphist_lastexp` BIGINT(255) NOT NULL DEFAULT '0',
ADD `exphist1` BIGINT(255) NOT NULL DEFAULT '0',
ADD `exphist2` BIGINT(255) NOT NULL DEFAULT '0',
ADD `exphist3` BIGINT(255) NOT NULL DEFAULT '0',
ADD `exphist4` BIGINT(255) NOT NULL DEFAULT '0',
ADD `exphist5` BIGINT(255) NOT NULL DEFAULT '0',
ADD `exphist6` BIGINT(255) NOT NULL DEFAULT '0',
ADD `exphist7` BIGINT(255) NOT NULL DEFAULT '0',
ADD `onlinetimetoday` BIGINT(20) NOT NULL DEFAULT '0',
ADD `onlinetime1` BIGINT(20) NOT NULL DEFAULT '0',
ADD `onlinetime2` BIGINT(20) NOT NULL DEFAULT '0',
ADD `onlinetime3` BIGINT(20) NOT NULL DEFAULT '0',
ADD `onlinetime4` BIGINT(20) NOT NULL DEFAULT '0',
ADD `onlinetime5` BIGINT(20) NOT NULL DEFAULT '0',
ADD `onlinetime6` BIGINT(20) NOT NULL DEFAULT '0',
ADD `onlinetime7` BIGINT(20) NOT NULL DEFAULT '0',
ADD `onlinetimeall` BIGINT(20) NOT NULL DEFAULT '0';
]]--
-- after that execute: --
--[[
UPDATE `znote_players` AS `z` INNER JOIN `players` AS `p` ON `p`.`id`=`z`.`player_id` SET `z`.`exphist_lastexp`=`p`.`experience`;
]]--
-- TFS 1.X (data/globalevents.xml)
-- <!-- Power Gamers -->
-- <globalevent name="PowerGamers" interval="60000" script="powergamers.lua"/>
function onThink(interval, lastExecution, thinkInterval)
if tonumber(os.date("%d")) ~= getEternalStorage(23856) then
setEternalStorage(23856, (tonumber(os.date("%d"))))
@ -31,31 +61,3 @@ function onThink(interval, lastExecution, thinkInterval)
db.query("UPDATE `znote_players` SET `onlinetimetoday` = `onlinetimetoday` + 60, `onlinetimeall` = `onlinetimeall` + 60 WHERE `player_id` IN (SELECT `player_id` FROM `players_online` WHERE `players_online`.`player_id` = `znote_players`.`player_id`)")
return true
end
-- TFS 1.0 (globalevents.xml)
-- <!-- Power Gamers -->
-- <globalevent name="PowerGamers" interval="60000" script="powergamers.lua"/>
-- SQL (remember to remove all (--) before executing)--
--ALTER TABLE `znote_players` ADD `exphist_lastexp` BIGINT( 255 ) NOT NULL DEFAULT '0',
--ADD `exphist1` BIGINT( 255 ) NOT NULL DEFAULT '0',
--ADD `exphist2` BIGINT( 255 ) NOT NULL DEFAULT '0',
--ADD `exphist3` BIGINT( 255 ) NOT NULL DEFAULT '0',
--ADD `exphist4` BIGINT( 255 ) NOT NULL DEFAULT '0',
--ADD `exphist5` BIGINT( 255 ) NOT NULL DEFAULT '0',
--ADD `exphist6` BIGINT( 255 ) NOT NULL DEFAULT '0',
--ADD `exphist7` BIGINT( 255 ) NOT NULL DEFAULT '0',
--ADD `onlinetimetoday` BIGINT( 20 ) NOT NULL DEFAULT '0',
--ADD `onlinetime1` BIGINT( 20 ) NOT NULL DEFAULT '0',
--ADD `onlinetime2` BIGINT( 20 ) NOT NULL DEFAULT '0',
--ADD `onlinetime3` BIGINT( 20 ) NOT NULL DEFAULT '0',
--ADD `onlinetime4` BIGINT( 20 ) NOT NULL DEFAULT '0',
--ADD `onlinetime5` BIGINT( 20 ) NOT NULL DEFAULT '0',
--ADD `onlinetime6` BIGINT( 20 ) NOT NULL DEFAULT '0',
--ADD `onlinetime7` BIGINT( 20 ) NOT NULL DEFAULT '0',
--ADD `onlinetimeall` BIGINT( 20 ) NOT NULL DEFAULT '0';
---------------
-- after that execute --
-- UPDATE `znote_players` AS `z` INNER JOIN `players` AS `p` ON `p`.`id`=`z`.`player_id` SET `z`.`exphist_lastexp`=`p`.`experience`

View File

@ -1 +0,0 @@
<globalevent name="Znote Shop" interval="30000" script="znoteshop.lua"/>

View File

@ -1,154 +1,155 @@
-- <globalevent name="Znote Shop" interval="30000" script="znoteshop.lua"/>
-- Znote Auto Shop v2.1 for Znote AAC on TFS 1.2+
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,7)
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",
"Instant house purchase"
}
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 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,7)
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",
"Instant house purchase"
}
repeat
local player_id = result.getNumber(orderQuery, 'player_id')
local orderId = result.getNumber(orderQuery, 'id')
local orderType = result.getNumber(orderQuery, 'type')
local orderItemId = result.getNumber(orderQuery, 'itemid')
local orderCount = result.getNumber(orderQuery, 'count')
local served = false
local player = Player(player_id)
if player ~= nil then
local player = Player(player_id)
if player ~= nil then
local description = "Unknown or custom type"
if type_desc[orderType] ~= nil then
description = type_desc[orderType]
end
print("Processing type "..orderType..": ".. description)
print("Processing shop order for: [".. player:getName() .."] type "..orderType..": ".. description)
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
local itemType = ItemType(orderItemId)
-- Get wheight
if player:getFreeCapacity() >= itemType:getWeight(orderCount) then
local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)
-- variable = (condition) and (return if true) or (return if false)
local needslots = itemType:isStackable() and math.floor(orderCount / 100) + 1 or orderCount
if backpack ~= nil and backpack:getEmptySlots(false) >= needslots 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 -- not enough slots
player:sendTextMessage(MESSAGE_STATUS_WARNING, "Your main backpack is full. You need to free up "..needslots.." available slots to get " .. orderCount .. " " .. ItemType(orderItemId):getName() .. "!")
print("Process canceled. [".. player:getName() .."] need more space in his backpack to get " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".")
end
else -- not enough cap
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
local description = "Unknown or custom type"
if type_desc[orderType] ~= nil then
description = type_desc[orderType]
end
print("Processing type "..orderType..": ".. description)
print("Processing shop order for: [".. player:getName() .."] type "..orderType..": ".. description)
-- ORDER TYPE 5 (Outfit and addon)
if orderType == 5 then
served = true
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
local itemType = ItemType(orderItemId)
-- Get weight
if player:getFreeCapacity() >= itemType:getWeight(orderCount) then
local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)
-- variable = (condition) and (return if true) or (return if false)
local needslots = itemType:isStackable() and math.floor(orderCount / 100) + 1 or orderCount
if backpack ~= nil and backpack:getEmptySlots(false) >= needslots 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 received " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".")
else -- not enough slots
player:sendTextMessage(MESSAGE_STATUS_WARNING, "Your main backpack is full. You need to free up "..needslots.." available slots to get " .. orderCount .. " " .. ItemType(orderItemId):getName() .. "!")
print("Process canceled. [".. player:getName() .."] need more space in his backpack to get " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".")
end
else -- not enough cap
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
local itemid = orderItemId
local outfits = {}
-- ORDER TYPE 5 (Outfit and addon)
if orderType == 5 then
served = true
if itemid > 1000 then
local first = math.floor(itemid/1000)
table.insert(outfits, first)
itemid = itemid - (first * 1000)
end
table.insert(outfits, itemid)
local itemid = orderItemId
local outfits = {}
for _, outfitId in pairs(outfits) do
-- Make sure player don't already have this outfit and addon
if not player:hasOutfit(outfitId, orderCount) then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
player:addOutfit(outfitId)
player:addOutfitAddon(outfitId, orderCount)
player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!")
print("Process complete. [".. player:getName() .."] has recieved outfit: ["..outfitId.."] with addon: ["..orderCount.."]")
else -- Already has outfit
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!")
print("Process canceled. [".. player:getName() .."] already have outfit: ["..outfitId.."] with addon: ["..orderCount.."].")
end
end
end
if itemid > 1000 then
local first = math.floor(itemid/1000)
table.insert(outfits, first)
itemid = itemid - (first * 1000)
end
table.insert(outfits, itemid)
-- 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 -- Already has mount
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this mount!")
print("Process canceled. [".. player:getName() .."] already have mount: ["..orderItemId.."].")
end
end
for _, outfitId in pairs(outfits) do
-- Make sure player don't already have this outfit and addon
if not player:hasOutfit(outfitId, orderCount) then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
player:addOutfit(outfitId)
player:addOutfitAddon(outfitId, orderCount)
player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!")
print("Process complete. [".. player:getName() .."] has received outfit: ["..outfitId.."] with addon: ["..orderCount.."]")
else -- Already has outfit
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!")
print("Process canceled. [".. player:getName() .."] already have outfit: ["..outfitId.."] with addon: ["..orderCount.."].")
end
end
end
-- ORDER TYPE 7 (Direct house purchase)
if orderType == 7 then
served = true
local house = House(orderItemId)
-- Logged in player is not neccesarily the player that bough the house. So we need to load player from db.
local buyerQuery = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = "..orderCount.." LIMIT 1")
if buyerQuery ~= false then
local buyerName = result.getDataString(buyerQuery, "name")
result.free(buyerQuery)
if house then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
house:setOwnerGuid(orderCount)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought the house "..house:getName().." on "..buyerName..", be sure to have the money for the rent in the bank.")
print("Process complete. [".. buyerName .."] has recieved house: ["..house:getName().."]")
else
print("Process canceled. Failed to load house with ID: "..orderItemId)
end
else
print("Process canceled. Failed to load player with ID: "..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 received mount: ["..orderItemId.."]")
else -- Already has mount
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this mount!")
print("Process canceled. [".. player:getName() .."] already have mount: ["..orderItemId.."].")
end
end
if not served then -- If this order hasn't been processed yet (missing type handling?)
print("Znote shop: Type ["..orderType.."] not properly processed. Missing Lua code?")
end
else -- Not in protection zone
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 -- player not logged in
print("Skipped one shop order. Reason: Player with id [".. player_id .."] is not online.")
end
-- ORDER TYPE 7 (Direct house purchase)
if orderType == 7 then
served = true
local house = House(orderItemId)
-- Logged in player is not necessarily the player that bough the house. So we need to load player from db.
local buyerQuery = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = "..orderCount.." LIMIT 1")
if buyerQuery ~= false then
local buyerName = result.getString(buyerQuery, "name")
result.free(buyerQuery)
if house then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
house:setOwnerGuid(orderCount)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought the house "..house:getName().." on "..buyerName..", be sure to have the money for the rent in the bank.")
print("Process complete. [".. buyerName .."] has received house: ["..house:getName().."]")
else
print("Process canceled. Failed to load house with ID: "..orderItemId)
end
else
print("Process canceled. Failed to load player with ID: "..orderCount)
end
end
until not result.next(orderQuery)
result.free(orderQuery)
end
return true
end
if not served then -- If this order hasn't been processed yet (missing type handling?)
print("Znote shop: Type ["..orderType.."] not properly processed. Missing Lua code?")
end
else -- Not in protection zone
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 -- player not logged in
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

View File

@ -1,7 +1,6 @@
-- <talkaction words="!report" separator=" " script="adminreport.lua"/>
-- Coded by Dark ShaoOz, modified by Znote
function onSay(cid, words, param, channel)
local player = Player(cid)
function onSay(player, words, param)
local storage = 6708 -- You can change the storage if its already in use
local delaytime = 30 -- Exhaust In Seconds.
if param == '' then

View File

@ -1 +0,0 @@
<talkaction words="!shop" script="znoteshop.lua"/>

View File

@ -1,3 +1,4 @@
-- <talkaction words="!shop" script="znoteshop.lua"/>
-- Znote Shop v1.1 for Znote AAC on TFS 1.2+
function onSay(player, words, param)
local storage = 54073 -- Make sure to select non-used storage. This is used to prevent SQL load attacks.
@ -5,7 +6,7 @@ function onSay(player, words, param)
if player:getStorageValue(storage) <= os.time() then
player:setStorageValue(storage, os.time() + cooldown)
local type_desc = {
"itemids",
"pending premium (skip)",
@ -34,11 +35,11 @@ function onSay(player, words, param)
description = type_desc[q_type]
end
print("Processing type "..q_type..": ".. description)
-- ORDER TYPE 1 (Regular item shop products)
if q_type == 1 then
served = true
-- Get wheight
-- Get weight
if player:getFreeCapacity() >= ItemType(q_itemid):getWeight(q_count) then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
player:addItem(q_itemid, q_count)
@ -90,22 +91,21 @@ function onSay(player, words, param)
-- ORDER TYPE 7 (Direct house purchase)
if orderType == 7 then
served = true
local house = House(orderItemId)
-- Logged in player is not neccesarily the player that bough the house. So we need to load player from db.
local buyerQuery = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = "..orderCount.." LIMIT 1")
if buyerQuery ~= false then
local buyerName = result.getDataString(buyerQuery, "name")
result.free(buyerQuery)
if house then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
house:setOwnerGuid(orderCount)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought the house "..house:getName().." on "..buyerName..", be sure to have the money for the rent in the bank.")
print("Process complete. [".. buyerName .."] has recieved house: ["..house:getName().."]")
end
end
served = true
local house = House(orderItemId)
-- Logged in player is not necessarily the player that bough the house. So we need to load player from db.
local buyerQuery = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = "..orderCount.." LIMIT 1")
if buyerQuery ~= false then
local buyerName = result.getString(buyerQuery, "name")
result.free(buyerQuery)
if house then
db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
house:setOwnerGuid(orderCount)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought the house "..house:getName().." on "..buyerName..", be sure to have the money for the rent in the bank.")
print("Process complete. [".. buyerName .."] has received house: ["..house:getName().."]")
end
end
end
-- Add custom order types here
-- Type 1 is for itemids (Already coded here)
@ -130,4 +130,4 @@ function onSay(player, words, param)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every " .. cooldown .. " seconds. Remaining cooldown: " .. player:getStorageValue(storage) - os.time())
end
return false
end
end

File diff suppressed because one or more lines are too long