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

Useing Toilettes

Exmortis

Member
Joined
Jun 27, 2008
Messages
189
Reaction score
5
I need a script to make it possible to use toilettes.
TFS 0.2.7
When you rightclick a *excuse my language* shithole looking thing In Tibia, you get like 500 mana or so.
ID: 8653


I gotta learn how to script :/
 
Last edited:
Don't you mean left click?

Lua:
local es,s = 120,12354 -- exhaustion in seconds, storage value.
function onUse(cid,item,toPosition,itemEx,fromPosition)
	if exhaustion.check(cid,s) then
		return doPlayerSendCancel(cid,'You can only use this each '..es..' seconds.') and false
	end
	doSendMagicEffect(getThingPos(itemEx),CONST_ME_LOSEENERGY)
	doCreatureAddMana(cid,500)
	exhaustion.set(cid,s,es)
	return true
end
 
Last edited:
Thanks for makeing the script, what i forgot to tell you was that i'm useing TFS 0.2.7.
Sorry for the trouble. :/
Rep+ for you anyway
 
Version without storage use:
PHP:
local es,s = 120, {} -- exhaustion in seconds, table with exhaustion
function onUse(cid,item,toPosition,itemEx,fromPosition)
	if s[cid] ~= nil and s[cid] > os.time() then
		return doPlayerSendCancel(cid,'You can only use this each '..es..' seconds.') and false
	end
	doSendMagicEffect(getThingPos(itemEx),CONST_ME_LOSEENERGY)
	doCreatureAddMana(cid,500)
	s[cid] = os.time() + es
	return true
end
Don't add useless storages to database <_<
 
I get the following error: data/actions/scripts/showers/toilette.lua:3: attempt to index global 'exhaustion' <a nil value>
 
data/actions/actions.xml
If you want every tiolette to make the same thing then add:
XML:
<action itemid="xxxx" event="script" value="toilette.lua"/>
If you just want 1 or some then add uniqueid on them at RME and add:
XML:
<action uniqueid="xxxx" event="script" value="toilette.lua"/>

data/actions/scripts/toilette.lua
Lua:
local message = "Put the message you want to appear after you use the toilette"
function onUse(cid, item, frompos, item2, topos)
doPlayerAddMana(cid, 500)
doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,message) ---- If you don't want messages displayed then erase this line
return true
end

If someone can add exhaustion to this, it would be awesome.
 
Is it possible to make it addspeed for like 4min or so?
I made the message say "You took a dump and feel alot lighter."
So It would be a laugh if you actually run faster :p
 
Instead of storages, you prefer potential memory leaks?
If your server is online for 1000 hours you can change 'cid' to getPlayerGUID(cid) :peace:
When playerStorage will be stored 'binary' in database and max. key value will be 2kk I'll use storage everywhere ^_^
------------------------------------
In some scripts it's needed to store cid's in place of playerStorage (you can check if player logout/die without creaturescripts)
 
Here you go:
Lua:
local message = "Put the message you want to appear after you use the toilette"
local speed = x --- Put the speed you'd like
function onUse(cid, item, frompos, item2, topos)
doPlayerAddMana(cid, 500)
doChangeSpeed(cid, speed)
doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,message) ---- If you don't want messages displayed then erase this line
return true
end

If someone can just put exhaustion to the toilette, and end to the speed then it would be awesome!

Uhm, try this one, I don't know if it will work though.
Lua:
local message = "Put the message you want to appear after you use the toilette"
local speed = x --- Put the speed you'd like
local time = x --- Put the time you'd like (it will be multiplied by 1000)
function onUse(cid, item, frompos, item2, topos)
doPlayerAddMana(cid, 500)
doChangeSpeed(cid, speed)
addEvent(doChangeSpeed, time*1000, cid, -speed)
doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,message) ---- If you don't want messages displayed then erase this line
return true
end

If this works, it will give end to the speed
 
Last edited:
If someone can just put exhaustion to the toilette, and end to the speed then it would be awesome!
PHP:
local exhaustion = 120 -- exhaustion in seconds
local speedValue = 420 -- speed change
local speedTime = 60 -- time in seconds
local mana = 500 -- mana change

local tmpStorages = {} -- table with exhaustion / do not modify
function onUse(cid,item,toPosition,itemEx,fromPosition)
    if tmpStorages[getPlayerGUID(cid)] ~= nil and tmpStorages[getPlayerGUID(cid)] > os.time() then
        return doPlayerSendCancel(cid,'You can only use this each '.. exhaustion ..' seconds.') and false
    end
    doSendMagicEffect(getThingPos(itemEx),CONST_ME_LOSEENERGY)
    doCreatureAddMana(cid, mana)
    addEvent(function(cid, speedChange) return isPlayer(cid) and doChangeSpeed(cid, speedChange) end, speedTime * 1000, cid, -speedValue)
    doChangeSpeed(cid, speedValue)
    tmpStorages[getPlayerGUID(cid)] = os.time() + exhaustion
    return true
end
Script with speed change, configurable time and lower memory use ^_^

@UP
Check my addEvent use. You can define new function in addEvent!
 
Last edited:
@Up: Great man. Seems like the script is over (if it works :p)
Btw, is this script correct? (learning :<)
Lua:
local message = "Put the message you want to appear after you use the toilette"
local speed = x --- Put the speed you'd like
local time = x --- Put the time you'd like (it will be multiplied by 1000)
local storage = 15000
local exhaustion = x
function onUse(cid, item, frompos, item2, topos)
if getGlobalStorageValue(storage) < os.time()
doPlayerAddMana(cid, 500)
doChangeSpeed(cid, speed)
addEvent(doChangeSpeed, time*1000, cid, -speed)
doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,message) ---- If you don't want messages displayed then erase this line
setGlobalStorageValue(storage, os.time() + exhaustion)
else
doPlayerSendCancel(cid, "You must wait "..exhaustion.." minutes to use the toilette again")
return true
end
 
I get the following error: data/actions/scripts/showers/toilette.lua:3: attempt to index global 'exhaustion' <a nil value>

Just add this to your lib
Lua:
exhaustion =
{
	check = function (cid, storage)
		if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
			return false
		end

		return getPlayerStorageValue(cid, storage) >= os.time(t)
	end,

	get = function (cid, storage)
		if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
			return false
		end

		local exhaust = getPlayerStorageValue(cid, storage)
		if(exhaust > 0) then
			local left = exhaust - os.time(t)
			if(left >= 0) then
				return left
			end
		end

		return false
	end,

	set = function (cid, storage, time)
		setPlayerStorageValue(cid, storage, os.time(t) + time)
	end,

	make = function (cid, storage, time)
		local exhaust = exhaustion.get(cid, storage)
		if(not exhaust) then
			exhaustion.set(cid, storage, time)
			return true
		end

		return false
	end
}

Don't remember if that distro has the function to get flag values... if it doesn't have.. then remove this
Lua:
		if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
			return false
		end
 
@UP
Rep+ for your help (that can help author of thread with other scripts), but next time read all answers in thread.
 
Last edited:
Back
Top