-- ordered as in creaturescripts.xml
local events = {
'TutorialCockroach',
'ElementalSpheresOverlords',
'BigfootBurdenVersperoth',
'BigfootBurdenWarzone',
'BigfootBurdenWeeper',
'BigfootBurdenWiggler',
'SvargrondArenaKill',
'NewFrontierShardOfCorruption',
'NewFrontierTirecz',
'ServiceOfYalaharDiseasedTrio',
'ServiceOfYalaharAzerus',
'ServiceOfYalaharQuaraLeaders',
'InquisitionBosses',
'InquisitionUngreez',
'KillingInTheNameOfKills',
'MastersVoiceServants',
'SecretServiceBlackKnight',
'ThievesGuildNomad',
'WotELizardMagistratus',
'WotELizardNoble',
'WotEKeeper',
'WotEBosses',
'WotEZalamon',
'PlayerDeath',
'AdvanceSave',
'AdvanceRookgaard',
'PythiusTheRotten',
'DropLoot'
}
local function onMovementRemoveProtection(cid, oldPosition, time)
local player = Player(cid)
if not player then
return true
end
local playerPosition = player:getPosition()
if (playerPosition.x ~= oldPosition.x or playerPosition.y ~= oldPosition.y or playerPosition.z ~= oldPosition.z) or player:getTarget() then
player:setStorageValue(Storage.combatProtectionStorage, 0)
return true
end
addEvent(onMovementRemoveProtection, 1000, cid, oldPosition, time - 1)
end
function onLogin(player)
local loginStr = 'Welcome to ' .. configManager.getString(configKeys.SERVER_NAME) .. '!'
if player:getLastLoginSaved() <= 0 then
loginStr = loginStr .. ' Please choose your outfit.'
player:sendTutorial(1)
else
if loginStr ~= '' then
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
end
loginStr = string.format('Your last visit was on %s.', os.date('%a %b %d %X %Y', player:getLastLoginSaved()))
end
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
local playerId = player.uid
-- Stamina
Game.getStorageValue("stamina")[playerId] = 0
-- Promotion
local vocation = player:getVocation()
local promoted = player:isPromoted()
if player:isPremium() then
local value = player:getStorageValue(Storage.Promotion)
if promoted and value ~= 1 then
player:setStorageValue(Storage.Promotion, 1)
elseif not promoted and value == 1 then
player:setVocation(vocation:getPromotion())
end
elseif promoted then
player:setVocation(vocation:getDemotion())
end
-- Events
for i = 1, #events do
player:registerEvent(events[i])
end
if player:getStorageValue(Storage.combatProtectionStorage) <= os.time() then
player:setStorageValue(Storage.combatProtectionStorage, os.time() + 10)
onMovementRemoveProtection(playerId, player:getPosition(), 10)
end
home_market_spend = 0
home_market_items = {}
home_market_items_msg = ""
for i = 1, 30 do
-- don't let them send milions of trash and then get it at once!
local a = db.storeQuery("SELECT * FROM `onlogin_sendtoinbox` WHERE `player_id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
if a then
local it_id = Player(cid):getInbox():addItem(result.getDataInt(a, "itemtype"), result.getDataInt(a, "count"), true, 1)
it_id:setAttribute(1, result.getDataInt(a, "actionid"))
it_id:setAttribute(4, result.getDataString(a, "description"))
it_id:setAttribute(8, result.getDataString(a, "text"))
it_id:setAttribute(32, getPlayerNameByGUID(result.getDataInt(a, "writer_guid")))
it_id:setAttribute(16, getPlayerNameByGUID(result.getDataInt(a, "written_at")))
home_market_spend = home_market_spend + result.getDataInt(a, "price")
table.insert(home_market_items, {getItemName(result.getDataInt(a, "itemtype")), result.getDataInt(a, "count")})
db.query("DELETE FROM `onlogin_sendtoinbox` WHERE `player_id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
else
break
end
end
if #home_market_items > 0 then
for i = 1, #home_market_items do
home_market_items_msg = home_market_items_msg .. i_ar(home_market_items[i][1], home_market_items[i][2]) .. " " .. i_n(home_market_items[i][1], home_market_items[i][2])
if #home_market_items ~= 1 and i ~= #home_market_items then
home_market_items_msg = home_market_items_msg .. ", "
end
end
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Store]: During your absence, players sold you " .. #home_market_items .. " item(s) for " .. home_market_spend .. " gold coins in total.")
if #home_market_items < 31 then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Store]: Items you bought: " .. home_market_items_msg)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Store]: Check your inbox to see items you received.")
end
return true
end