• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua [0.3.6] Exp Scroll??

Samaster

Raptorserver.ddns.net
Joined
Jun 9, 2013
Messages
291
Reaction score
23
Location
UK
Hi,
I have an exp scroll that increases rate by 1.5x but it deducts time when players are offline. Can someone help me add a feature so it only deducts time when the player is logged in. I'm not very good at coding so I can't tell if this script does that, if so then it doesn't work

XML Script:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Experience Stages Scroll" version="1.0" enabled="yes">
<action itemid="7722" event="script" value="2hour 1.5x expscroll.lua"/>
<creatureevent type="think" name="ExpStage" event="script" value="2hour 1.5x expscroll.lua"/>
<creatureevent type="login" name="ExpStageLogin" event="script" value="2hour 1.5x expscroll.lua"/>
<creatureevent type="death" name="Expdeath" event="script" value="2hour 1.5x expscroll.lua"/>
</mod>

Lua Script:
Code:
local config = {
rate = 1.5,
storage = 1000,
expstorage = 1100,
register = 1200,
time = 3600,
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerStorageValue(cid, config.storage) <= 0 then
local rates = getPlayerRates(cid)
setPlayerStorageValue(cid, config.expstorage, rates[SKILL__LEVEL])
setPlayerStorageValue(cid, config.register, 1)
itemEx=itemid == 7724
doCreatureSay(cid, "Additional experience activated! You're now getting " .. config.rate .. "x your current rate.", TALKTYPE_ORANGE_1, true, cid)
setPlayerStorageValue(cid, config.storage, os.time()+config.time)
doPlayerSetExperienceRate(cid, rates[SKILL__LEVEL]+config.rate)
doRemoveItem(item.uid,1)
registerCreatureEvent(cid, "ExpStage")
else
doCreatureSay(cid, "You are already using an Experience Scroll, wait until it expires to use another.", TALKTYPE_ORANGE_1, true, cid)
end
return true
end
function onThink(cid, interval)
if getPlayerStorageValue(cid, config.register) == 1 then
if getPlayerStorageValue(cid, config.storage) <= os.time() then
doCreatureSay(cid, "The 1.5x Experience bonus has now expired.", TALKTYPE_ORANGE_1, true, cid)
setPlayerStorageValue(cid, config.storage, 0)
setPlayerStorageValue(cid, config.register, 0)
local oldexp = getPlayerStorageValue(cid, config.expstorage)
doPlayerSetExperienceRate(cid, oldexp)
unregisterCreatureEvent(cid, "ExpStage")
end
end
return true
end
function onLogin(cid)
if getPlayerStorageValue(cid, config.register) == 1 then
registerCreatureEvent(cid, "ExpStage")
local rates = getPlayerRates(cid)
doCreatureSay(cid, "You Have experience bonus active, and this multiplied by " .. config.rate .. "x.", TALKTYPE_ORANGE_1, true, cid)
if getPlayerStorageValue(cid, config.storage) > os.time() then
local oldexp = getPlayerStorageValue(cid, config.expstorage)
doPlayerSetExperienceRate(cid, oldexp+config.rate)
end
end
return true
end

function onDeath(cid, corpse, deathList)
if(getPlayerStorageValue(cid, config.storage) == 1) then
doPlayerSetStorageValue(uid, config.storage, -1)
unregisterCreatureEvent(cid, "Expdeath")
end
return true
end
 
Last edited:
Add the first line in a logout script, instead of 63667, use the storage that is used in your script, so 1000.
Then add the second line in login.lua, also change 63667 there to 1000.
 
Add the first line in a logout script, instead of 63667, use the storage that is used in your script, so 1000.
Then add the second line in login.lua, also change 63667 there to 1000.

I'm sorry yo're going to have to explain it a bit more than that. I don't know what you mean :/ :/
 
In a logout script:
Code:
setPlayerStorageValue(cid, 70000, getPlayerStorageValue(cid, 63667) - os.time())
Instead of 63667 use the storage from your script which is 1000 so..: setPlayerStorageValue(cid, 70000, getPlayerStorageValue(cid, 1000) - os.time())


In login.lua:
Code:
setPlayerStorageValue(cid, 63667, getPlayerStorageValue(cid, 70000) + os.time())
Also change 63667 here to 1000 so..: setPlayerStorageValue(cid, 1000, getPlayerStorageValue(cid, 70000) + os.time())
 
In a logout script:
Code:
setPlayerStorageValue(cid, 70000, getPlayerStorageValue(cid, 63667) - os.time())
Instead of 63667 use the storage from your script which is 1000 so..: setPlayerStorageValue(cid, 70000, getPlayerStorageValue(cid, 1000) - os.time())


In login.lua:
Code:
setPlayerStorageValue(cid, 63667, getPlayerStorageValue(cid, 70000) + os.time())
Also change 63667 here to 1000 so..: setPlayerStorageValue(cid, 1000, getPlayerStorageValue(cid, 70000) + os.time())


Okay so I've added that to login.lua.

What's an example of a logout script; can I use playerdeath.lua ?
 
No, a logout script, like a login script, but then logout (this script happens when a player logs out instead of in). So it's similar as login scripts like login.lua, but then instead of in you write out.
Code:
function onLogout(cid)
The type in creaturescripts.xml is logout.
 
No, a logout script, like a login script, but then logout (this script happens when a player logs out instead of in). So it's similar as login scripts like login.lua, but then instead of in you write out.
Code:
function onLogout(cid)
The type in creaturescripts.xml is logout.

I can't find logout.lua. I don't have it, or is it called something else in 0.3.6?
 
If you don't have a script with type logout then just make one.
You can call it logout.lua, matches with login.lua :p
But it doesn't really matter how you call it, also the name doesn't need to be registered same as login scripts.
 
If you don't have a script with type logout then just make one.
You can call it logout.lua, matches with login.lua :p
But it doesn't really matter how you call it, also the name doesn't need to be registered same as login scripts.

Okay so I've just made this logout.lua
Code:
function onLogout(cid)
setPlayerStorageValue(cid, 70000, getPlayerStorageValue(cid, 1000) - os.time())
end

Would this work?
 
No, return true is missing (like this people will be unable to logout), if you add that, it will work.
Okay I've added that. And this on creaturescripts.xml :
Code:
<event type="logout" name="PlayerLogout" event="script" value="logout.lua"/>
 
Back
Top