• 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 [TFS 1.0] Script/item for double-exp with duration?

Romantix

Omnipotent
Joined
Apr 27, 2010
Messages
131
Reaction score
2
Location
Australia
Hello Otland,

I need a script for an item (onUse) that adds double experience for a set duration (24 hours)..

Happy to pay a scripter for their efforts :)

Kind Regards,

Romantix
 
Solution
Use the event onGainExperience.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)
    if player:getStorageValue(1234) >= os.time() then
        return true
    end
   
    player:setStorageValue(1234, os.time() + 86400)
    Item(item.uid):remove(1)
    return true
end

function Player:onGainExperience(source, exp, rawExp)
    if self:getStorageValue(1234) >= os.time() then
        exp = exp * 2
    end
    return exp
end
Use the event onGainExperience.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)
    if player:getStorageValue(1234) >= os.time() then
        return true
    end
   
    player:setStorageValue(1234, os.time() + 86400)
    Item(item.uid):remove(1)
    return true
end

function Player:onGainExperience(source, exp, rawExp)
    if self:getStorageValue(1234) >= os.time() then
        exp = exp * 2
    end
    return exp
end
 
Solution
Heya!

Added the following to events:

<event class="Player" method="onGainExperience" enabled="1"/>

Added the following to actions, with your script provided.

<action itemid="12662" script="custom/exp.lua"/>

@Ninja

No success. (Sorry for spam)
 
Last edited by a moderator:
@Damc - I believe so sir, perhaps I might be a little confused by your question though, do you mind sharing specifics behind the "group_id"? (in SQL presumably..)

When a player has group_id 1, it means he/she's just a normal player with regular playing rights. A group_id of 3 would be "god". In some cases, there will be things that will not work for "god" characters, simply because it's unnecessary. For all of your testing, you should do it on a character that has group_id of 1.
 
@Evan - Thank you for the clarity.

Well understood, i thought group ID may have only been associated to players, not accounts. I will check it out tonight.

Thank you VERY much! :)

Kind Regards,

Romantix.

@Evan - Ok mate, restested on a fresh account with no success :(

Any ideas behind the cause?
 
Last edited by a moderator:
Does the server spit out any errors? I've copy-pasted the script into current TFS 1.0 and it works. Maybe you've already registered an another action event on that item?
 
The thing is, the "onUse" works... just not the double exp...

Alongside that but no errors are presented in the console.

Typically if I was missing "onGainExperience" from my TFS, it would present an error right? =/

@Damc
 
That's strange... I have no idea why it isn't working. Does the events/scripts/player.lua file look like this:
Code:
[... other functions ...]
function Player:onGainExperience(source, exp, rawExp)
   if self:getStorageValue(1234) >= os.time() then
  exp = exp * 2
  end
  return exp
end
[... other functions ...]
?
 
@Damc - ahhh, I didn't add that to player.lua, now its working.

However, even with this set time, it appears the storage tables cannot be manually removed from the database. (it sticks to player)

Once the duration expires... will the double exp no longer last? Sorry if this sounds like a primitive question..
 
@Damc - ahhh, I didn't add that to player.lua, now its working.

However, even with this set time, it appears the storage tables cannot be manually removed from the database. (it sticks to player)

Once the duration expires... will the double exp no longer last? Sorry if this sounds like a primitive question..
If you modify the database when the server is running and the player is online then most likely any changes you've made will be lost, as the server stores most player data locally for performance reasons. When he/she logs out, any changes get overwritten. Once the bonus expires it should be possible to get it again. You can test it by setting the duration to a few seconds and then see if it works like you expect it to ;).
 
You may not be able to achieve this, I have a custom TFS 1.0... you're likely missing the attributes, but I believe it can be attained from the nightlies revision.

@1268995 /
@EwR

In short:

1. events/scripts/player.lua:

function Player:eek:nGainExperience(source, exp, rawExp)
if self:getStorageValue(1234) >= os.time() then
exp = exp * 2
end
return exp
end

2. actions.xml

<action itemid="12662" script="custom/exp.lua"/>

custom/exp.lua is the script/folder location

3. events.xml

<event class="Player" method="onGainExperience" enabled="1"/>

:)
 
When i add this to my events.xml and kill a monster i only seem to get normal exp (5exp from a rat) and its not recognizing my stages or config file setup, anyone got an idea?
 
When i add this to my events.xml and kill a monster i only seem to get normal exp (5exp from a rat) and its not recognizing my stages or config file setup, anyone got an idea?

You need to activate the event in your xml file, if it isen't activated already.
Otherwise restart the server.
And you need to set the storage value; 1234 to like os.time() + 60 * 1000 to give the player 1 min extra.
 
Back
Top