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

Solved A looping event that causes errors when a player logs out.

Ecstacy

Mothafuckaaa
Joined
Dec 26, 2008
Messages
3,836
Reaction score
108
Location
The Netherlands
Hey,

I'm having a problem with a looping event, and is caused when the player logs out, since the player can't be found anymore by the game and the script adds a certain percentage of hp&mana per second.

The exact error is (luaGetCreatureStorage) creature not found. and as stated above, I know why it is caused,
But I would like to know if there is any way to avoid this error (maybe C++ coding?) since I wouldn't want this error to be spammed i.e. when 20 players log out at the same time.

The script in case you might need it.
script:
Lua:
local configs = {
  percent = 1.5, -- percent of max mana that will be added
  interval = 1*1000, -- time to add mana again
  storage = 12002
}
local function addMana(cid, interval, storage, perc)
	if(getPlayerStorageValue(cid,storage) == 1)then
		if (getCreatureMana(cid) < getCreatureMaxMana(cid)) then
			doCreatureAddMana(cid, getCreatureMaxMana(cid)/100*perc)
		end
		if (getCreatureHealth(cid) < getCreatureMaxHealth(cid)) then
			doCreatureAddHealth(cid, getCreatureMaxHealth(cid)/100*perc)
			doSendMagicEffect(getThingPos(cid),CONST_ME_TELEPORT)
		end
		addEvent(addMana, interval, cid, interval,storage,perc)
	end
	return true
end
 
function onEquip(cid, item, slot)
	setPlayerStorageValue(cid,configs.storage,1)
	addEvent(addMana, 0, cid, configs.interval,configs.storage,configs.percent)
	return true
end
 
function onDeEquip(cid, item, slot)
	stopEvent(addMana)
	setPlayerStorageValue(cid,configs.storage,0)
	return false
end
 
Lua:
if not isPlayer(cid) then 
	return true 
end
Like this if the script can't find the player it stops from there.

Well I be damned!

I've really thought about how I would be able to accomplish the error to be fixed, I also considered trying this,
but since every function, isPlayer(cid) too, relies on the cid I thought it would just cause the same error.

But you've proved my wrong.
Thanks alot :)
 
Back
Top