• 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 Exhaust via mysql

tiddpd

PHP Scripter
Joined
Apr 16, 2008
Messages
331
Reaction score
0
I know there is a way to make spell exhaust with an sql query. I have seen it used in mana runes before.

However I cant find this and I was wondering how? I know how to enter the number into the database but how to you make it decrease to act as spell exhaust. In the case that I want it for is to make a spell last for only so long, it has to be done with sql, lua functions for it wont work because its sort of a flag that will b called in all other spell scripts.
 
Exhaust function, included in TFS 0.3.x:
Lua:
exhaustion =
{
	check = function (cid, storage)
		if(getPlayerStorageValue(cid, storage) >= os.time(t)) then
			return TRUE
		end

		return FALSE
	end,

	get = function (cid, storage)
		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
}
 
Code:
exhaustion.set(cid, storageid, time_in_seconds)
after you've set it, you will have to test against that storage id if the player is still exhausted, like this:
Code:
if exhaustion.check(cid, storageid) == true then
 
ok.. just a general question about this in curiosity of how it works

It sets a storage value for the player for a certain amount of time.. lets say 2 seconds? And after the 2 seconds is the storage value deleted?
 
No, as you can see it in the exhaustion.lua the storage isn't removed. The function just compares times, so there's no redundant function calls - it's very effective.
 
ok well this isnt exactly what im looking for... i need it so that it can be checked in all other spell scripts. For an effect that lasts 10 seconds.

What I am trying to do is say
Code:
if (sql value) then
local mindmg = (twice normal value)
local maxdmg = (twice normal value)
And for 10 seconds the player does double spell damage
 
Well you can use it just like you pointed this out. The storage id you choose is valid (and thus the exhaustion is valid) for all scripts. You just have to make sure you're checking against the same storage id. So if you've set an exhaustion (or be it enhanced spell damage) with exhaustion.set(cid, 2000, 10) you can check for it with if exhaustion.check(cid, 2000) then from within any script.
 
I'll mess around with it and let ya know how it works thanks

Actually would this even work? Meaning will the 'if' statement work since the script is only loaded when the server turns on?
meaning the min and max variables couldnt change? correct me if im wrong.
 
Last edited:
Ok this is what I've came up with and so far it does not work, only whats in the else statement executes.
This isn't the actual spell script, its just for testing purposes.
Can you spot whats wrong with it?
Lua:
function onCastSpell(cid, var)
  if(exhaustion.check(cid, 2000)) then
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "IF statement message.")
  else
    exhaustion.set(cid, 2000, 5)
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "ELSE statement message.")
  end
return TRUE
end
 
Code:
[LEFT] dofile("./data/lib/exhaustion.lua")


[LEFT] function onCastSpell(cid, var)
  if(exhaustion.check(cid, 2000)) then
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "IF statement message.")
  else
    exhaustion.set(cid, 2000, 5)
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "ELSE statement message.")
  end
 return TRUE
 end  [/LEFT]
          [/LEFT]


Mind that the first time it enters it will execute ELSE, after that, within 5 seconds it will execute IF.
 
Back
Top