Guest User

login.lua

a guest
Aug 14th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.86 KB | None | 0 0
  1. function onLogin(cid)
  2.  
  3.     doPlayerOpenChannel(cid, 0x04) --opens game-chat
  4.  
  5.     local events = {
  6.         "RemoveBlesses", --Register the kill/die event
  7.         "Give_Bag_After_Death", --Register the Give_Bag_After_Death
  8.         "lootMessage", --Register loot message
  9.         "SkillStagesAdvance", --Skills stage system
  10.     }
  11.    
  12.     -- Register events
  13.     for i = 1, #events do
  14.         registerCreatureEvent(cid, events[i])
  15.     end
  16.  
  17.     -- Register the Stage event
  18.     if getBooleanFromString(getConfigInfo("experience_stages"), false) then
  19.         registerCreatureEvent(cid, "ExpStage")
  20.         checkStageChange(cid)
  21.     end
  22.  
  23.     -- Skills stage system
  24.     local stagesVocation = getPlayerVocation(cid)
  25.     if stagesVocation > 4 then
  26.         stagesVocation = stagesVocation - 4
  27.     end
  28.     local targetVocation = skillStagesConfig[stagesVocation]
  29.     if targetVocation then
  30.         for skill, targetSkillStage in pairs(targetVocation) do
  31.             if skill == SKILL_MAGLEVEL then
  32.                 nowSkill = getPlayerMagLevel(cid)
  33.             else
  34.                 nowSkill = getPlayerSkill(cid, skill)
  35.             end
  36.             local skillRate = 1
  37.             for level, rate in pairs(targetSkillStage) do
  38.                 if nowSkill >= level[1] and nowSkill <= level[2] then
  39.                     skillRate = rate
  40.                 end
  41.             end
  42.             doPlayerSetRate(cid, skill, skillRate)
  43.         end
  44.     end
  45.  
  46.     -- Add a backpack if it is a relogin after a death
  47.     if getPlayerStorageValue(cid, STORAGE_DEATH_BAG) == 1 then
  48.         if getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).uid == 0 and getPlayerStorageValue(cid, getConfigInfo("storage_sendrook")) ~= 1 then
  49.             local item_bag = doCreateItemEx(ITEM_BAG, 1)
  50.             doPlayerAddItemEx(cid, item_bag, false, CONST_SLOT_BACKPACK)
  51.         end
  52.         setPlayerStorageValue(cid, STORAGE_DEATH_BAG, -1)
  53.     end
  54.  
  55.     --Handle character sent to newbie island from main
  56.     if getPlayerStorageValue(cid, getConfigInfo("storage_sendrook")) == 1 then
  57.         -- first items
  58.         if (getPlayerSex(cid) == 0) then
  59.             doPlayerAddItem(cid, 2651, 1)
  60.         else
  61.             doPlayerAddItem(cid, 2650, 1) -- jacket
  62.         end
  63.         local club = doCreateItemEx(2382, 1) -- club
  64.         doPlayerAddItemEx(cid, club, true, CONST_SLOT_LEFT)
  65.         local bp = doPlayerAddItem(cid, 1987, 1) -- bag
  66.         doAddContainerItem(bp, 2050, 1) -- torch
  67.         doAddContainerItem(bp, 2674, 2) -- apples
  68.         -- remove house
  69.         local house = House.getHouseByOwner(cid)
  70.         if(house) then
  71.             house:setOwner(0) --Remove the house from the player, the server takes care of the rest
  72.         end
  73.         -- reset storage
  74.         setPlayerStorageValue(cid, getConfigInfo("storage_sendrook"), -1)
  75.     end
  76.  
  77.     -- Remove blesses if necessary
  78.     if getPlayerStorageValue(cid, STORAGE_REMOVE_BLESSES) == 1 then
  79.         local i = 1
  80.         while i <= 5 do
  81.             doPlayerRemoveBless(cid, i)
  82.             i = i + 1
  83.         end
  84.         setPlayerStorageValue(cid, STORAGE_REMOVE_BLESSES, -1)
  85.     end
  86.  
  87.     -- Promotes player if necessary
  88.     if(isPremium(cid)) then
  89.         if(getPlayerStorageValue(cid, STORAGE_PROMOTION) == 1 and getPlayerVocation(cid) <= 4) then
  90.             doPlayerSetVocation(cid, getPlayerVocation(cid)+4)
  91.             doPlayerRemoveSkillLossPercent(cid, 30)
  92.             setPlayerStorageValue(cid, STORAGE_PROMOTION, -1)
  93.         end
  94.         if(getPlayerStorageValue(cid, STORAGE_PREMIUM_ACCOUNT) == 1) then
  95.             setPlayerStorageValue(cid, STORAGE_PREMIUM_ACCOUNT, -1)
  96.         end
  97.         return true
  98.     end
  99.  
  100.     -- Player is not premium - remove premium privileges
  101.     if(getPlayerStorageValue(cid, STORAGE_PREMIUM_ACCOUNT) == -1) then
  102.  
  103.         -- Change outfit
  104.         local outfit = getCreatureOutfit(cid)
  105.         local lookType = outfit.lookType
  106.         if (getPlayerSex(cid) == 0) then
  107.             if lookType < 136 or lookType > 139 then
  108.                 lookType = 136
  109.             end
  110.         else
  111.             if lookType < 128 or lookType > 131 then
  112.                 lookType = 128
  113.             end
  114.         end
  115.         doCreatureChangeOutfit(cid, {lookType = lookType, lookHead = outfit.lookHead, lookBody = outfit.lookBody, lookLegs = outfit.lookLegs, lookFeet = outfit.lookFeet})
  116.  
  117.         -- Clean house
  118.         local house = House.getHouseByOwner(cid)
  119.         if(house) and getBooleanFromString(getConfigInfo("house_only_premium"), true) then
  120.             house:setOwner(0) --Remove the house from the player, the server takes care of the rest
  121.         end
  122.        
  123.         -- Make sure player moves to free account zone and has a free account temple
  124.         if getPlayerTown(cid) == 11 then -- Rookgaard
  125.             doTeleportThing(cid, getTownTemplePosition(11))
  126.         elseif getPlayerTown(cid) >= 6 and getPlayerTown(cid) <= 9 then -- if player temple is a Premium town
  127.             doPlayerSetTown(cid, 3) -- Thais
  128.             doTeleportThing(cid, getTownTemplePosition(3))
  129.         else
  130.             doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
  131.         end
  132.        
  133.         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your premium account expired. You lost your Premium Account privileges.")
  134.         setPlayerStorageValue(cid, STORAGE_PREMIUM_ACCOUNT, 1)
  135.     end
  136.  
  137.     -- Remove promotion
  138.     local isPromo = (getPlayerVocation(cid) > 4 and isPremium(cid) == false)
  139.     if(isPromo) then
  140.         doPlayerSetVocation(cid, getPlayerVocation(cid)-4)
  141.         doPlayerRemoveSkillLossPercent(cid, -30)
  142.         setPlayerStorageValue(cid, STORAGE_PROMOTION, 1)
  143.     end
  144.  
  145.     return true
  146. end
Add Comment
Please, Sign In to add comment