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

Event scroll. TFS 1.2

Scracky1

New Member
Joined
Oct 2, 2017
Messages
15
Solutions
1
Reaction score
0
So what im looking for is a script that will allow the usage of an item to start an event.
Im pretty bad at Lua and im not sure how to execute this.

For an example, I want a scroll that starts and event that changes the exp rate for the whole server to x2 for 30min. Not just for a single player.

Or if this doll is used the zombie event starts, etc etc.

I'd love for someone to make the script for me, if that is not possible I'd like some pointers on how to do it.
Im trying to learn Lua but it's going slow haha.


<3
 
Solution
Event Exp scroll (idk if this script will work, my 1st script):
Also u need to add lane to your creaturescripts and register this in login.lua
Code:
function onKill(creature, target)

   local multiplier = 10 -- 10% percent more than default
   local storage = 99999
   
   if Game.getStorageValue(storage) < 1 then
       return true
   end
    if not target:isMonster() then
        return true
    end
   if creature:isPlayer() then
       for id, damage in pairs(monster:getDamageMap()) do
           local player = Player(id)
           if player then
               local amount = target:getType():getExperience()
               local stage = Game.getExperienceStage(creature:getLevel())
               local final = (amount * stage *...
Event Exp scroll (idk if this script will work, my 1st script):
Also u need to add lane to your creaturescripts and register this in login.lua
Code:
function onKill(creature, target)

   local multiplier = 10 -- 10% percent more than default
   local storage = 99999
   
   if Game.getStorageValue(storage) < 1 then
       return true
   end
    if not target:isMonster() then
        return true
    end
   if creature:isPlayer() then
       for id, damage in pairs(monster:getDamageMap()) do
           local player = Player(id)
           if player then
               local amount = target:getType():getExperience()
               local stage = Game.getExperienceStage(creature:getLevel())
               local final = (amount * stage * (multiplier / 100))
               player:addExperience(math.floor(final), true)
           end
       end
   end
end
Exp scroll in actions, you need add lane to your actions.xml
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

   local group = player:getGroup():getId()
   local storage = 99999
   local howlong = 20 -- minutes
   
   if Game.getStorageValue(storage) >= 1 then
       player:sendCancelMessage("Happy HOURS are active now, you cannot double it.")
       return true
   end
   if player:isPlayer() and group > 3 then
       Game.setStorageValue(storage, 1)
       Game.broadcastMessage("Happy HOURS! Everyone will receive additional 10% of exp from each killed monster for another 20 minutes!", MESSAGE_STATUS_WARNING)
       addEvent(function()
           Game.setStorageValue(storage, -1)
       end, howlong * 1000 * 60)
   else
       player:sendCancelMessage("You need to be GM to start this event.")
       return true
   end
   return true
end
 
Solution
Event Exp scroll (idk if this script will work, my 1st script):
Also u need to add lane to your creaturescripts and register this in login.lua
Code:
function onKill(creature, target)

   local multiplier = 10 -- 10% percent more than default
   local storage = 99999
  
   if Game.getStorageValue(storage) < 1 then
       return true
   end
    if not target:isMonster() then
        return true
    end
   if creature:isPlayer() then
       for id, damage in pairs(monster:getDamageMap()) do
           local player = Player(id)
           if player then
               local amount = target:getType():getExperience()
               local stage = Game.getExperienceStage(creature:getLevel())
               local final = (amount * stage * (multiplier / 100))
               player:addExperience(math.floor(final), true)
           end
       end
   end
end
Exp scroll in actions, you need add lane to your actions.xml
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

   local group = player:getGroup():getId()
   local storage = 99999
   local howlong = 20 -- minutes
  
   if Game.getStorageValue(storage) >= 1 then
       player:sendCancelMessage("Happy HOURS are active now, you cannot double it.")
       return true
   end
   if player:isPlayer() and group > 3 then
       Game.setStorageValue(storage, 1)
       Game.broadcastMessage("Happy HOURS! Everyone will receive additional 10% of exp from each killed monster for another 20 minutes!", MESSAGE_STATUS_WARNING)
       addEvent(function()
           Game.setStorageValue(storage, -1)
       end, howlong * 1000 * 60)
   else
       player:sendCancelMessage("You need to be GM to start this event.")
       return true
   end
   return true
end
when checking Game.getStorageValue the value returned can be nil which results in a nil comparison with a number value, create a variable to hold the value like
local val = Game.getStorageValue(storage)
if val and val < 1 then

player:isPlayer() is useless because a player userdata is already passed through onUse which is why it's called player in the first place

also there's no group above 3 that exists by default, the highest is 3, so you should use group >= 3 not group > 3

in your addEvent you don't have to create an anonymous function to set the storage value, you can simply use addEvent(Game.setStorageValue, howlong* 1000 * 60, storage, -1)
 
Event Exp scroll (idk if this script will work, my 1st script):
Also u need to add lane to your creaturescripts and register this in login.lua
Code:
function onKill(creature, target)

   local multiplier = 10 -- 10% percent more than default
   local storage = 99999
 
   if Game.getStorageValue(storage) < 1 then
       return true
   end
    if not target:isMonster() then
        return true
    end
   if creature:isPlayer() then
       for id, damage in pairs(monster:getDamageMap()) do
           local player = Player(id)
           if player then
               local amount = target:getType():getExperience()
               local stage = Game.getExperienceStage(creature:getLevel())
               local final = (amount * stage * (multiplier / 100))
               player:addExperience(math.floor(final), true)
           end
       end
   end
end
Exp scroll in actions, you need add lane to your actions.xml
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

   local group = player:getGroup():getId()
   local storage = 99999
   local howlong = 20 -- minutes
 
   if Game.getStorageValue(storage) >= 1 then
       player:sendCancelMessage("Happy HOURS are active now, you cannot double it.")
       return true
   end
   if player:isPlayer() and group > 3 then
       Game.setStorageValue(storage, 1)
       Game.broadcastMessage("Happy HOURS! Everyone will receive additional 10% of exp from each killed monster for another 20 minutes!", MESSAGE_STATUS_WARNING)
       addEvent(function()
           Game.setStorageValue(storage, -1)
       end, howlong * 1000 * 60)
   else
       player:sendCancelMessage("You need to be GM to start this event.")
       return true
   end
   return true
end

Wow thanks mate!

Changed some values and specified 'monster' and now its working like a charm! <3
 
Last edited:
Back
Top