• 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 Creature Storage - quite complex enquiry

sestorme

Member
Joined
Dec 9, 2011
Messages
272
Reaction score
6
Location
Birmingham, UK
Code:
local thing = getThingFromPos(cpos) 
        if thing.uid > 0 and isCreature(thing.uid) and thing.uid ~= cid then

		doChangeSpeed(thing.uid, -130)
	   	doSendMagicEffect(getThingFromPos(cpos), 20)
		doCreatureSetStorage(thing.uid, 2000, 8)

				function run(left)
					if (left > 0) then
						if isCreature(thing.uid) then
							doSendMagicEffect(getCreaturePosition(thing.uid),7)
								if getCreatureStorage(thing.uid, 2000) <= 0 then
									doChangeSpeed(thing.uid, 130)
								elseif getCreatureStorage(thing.uid, 2000) >= 0.5 then
										doCreatureSetStorage(thing.uid, 2000, (getCreatureStorage(thing.uid, 2000) - 1))
										addEvent(run, 500, left)
								end
						end
					end
				end
				run(1)

Quick explanation what it is. On certain position target unit gets slowed by -130 movement speed. Then addEvent is started to create fancy animation of this effect. I need to have current time of slow stored as it's time is crucial and could be extended by various set of actions, that's why I need to keep a track of how much of slow is remaining on CreatureStorage. Problem appears when I get in touch with two units marked as thing.uid, one remains slowed and another one that is affected by the same spell before the end of the previous one's duration has it's movement speed increased. That only happens because spell's cooldown is lower than it's slow duration. There are absolutely no problems otherwise. Anyone could have a suggestion how to sort it out? Thanks, rep'd.
 
I'm trying to understand the situation, please correct me.

You have some kind of tile/position that triggers this (or...?)
If a target unit steps in it, it is slowed by -130 movement speed.
addEvent begins animation effect.
Time of being "slowed" is important, remaining time is stored.

This is where I am lost.

When you get in touch with two units. What do you mean by this?
One remains slowed and another one that is affect by the same spell before the end of the previous. What spell? Do you mean slowed spell? What is previous?)
That only happens because spell's cooldown is lower than slow duration. Wait, what spell?

I'm reallllllllllly confused, though I might not be reading properly, if so, I apologize.
 
There is a spell that picks thing.uid Spell has two seconds cooldown/exhaust. When I cast first time one unit (thing.uid) gets nicely slowed, everything works fine, and so it remains slowed for 4 seconds. If I would wait for 4 seconds with casting same spell again it would normally restore it's speed to the normal one. However, if I will cast the same spell on another unit which is again getting associated to thing.uid, it's somehow overriding previous thing.uid and instead of restoring speed to the previous one it remains slowed and new thing.uid is getting +130 speed itself. Basicly, all I need to do is to have a different local for each thing.uid(somehow?!).
 
So basically it's just like paralyze rune, except it lasts for 4 seconds and is used as a spell, right?
It's been a long day for me, my brain is fried, I really am sorry if I am not thinking hard enough.
 
Basicly, it's a custom spell, and this slow is quite crucial as I am very, very far in making first AoS/MobA game on Tibia OTS. What I need is to local these two separate thing.uid targets different so they won't override each other. It is like a paralyze, but due to the nature of the server I need to keep the track of exact time of slow remaining and it's strength.

What is happening that as soon as one target is already slowed and it's within slow duration and someone else is affected by the same spell, then new target is classed as a new thing.uid replacing the old target and old target is never having it's speed restored and new one gains it. If there is any possibility to gather like a CreatureId or any special number for each target that would absolutely sort my issue.
 
Yeah, I know exactly what your problem is now, let me think how I could tackle the issue, bear with my damn brain.
 
As I said, this is quite complex and advanced. I don't come on here with easy questions :) I learnt scripting on Warcraft 3 platform. It's quite similar, in here it's all in writting, that's the only difference. If I get that running I will release something that nobody has made on OTS platform ever before. I am nearly positive there is a way to do it, I just couldn't find the way just yet.
 
If you send the thing.uid off to another function, it will do its thing individually.
For example:

Lua:
local function slowTarget(uid)
	doChangeSpeed(uid, 530)
end

local thing = getThingFromPos(cpos)
    if thing.uid > 0 and isCreature(thing.uid) and thing.uid ~= cid then
		doChangeSpeed(thing.uid, -530)
		doSendMagicEffect(getThingFromPos(cpos), 20)
		doCreatureSetStorage(thing.uid, 2000, 8)
		addEvent(slowTarget, 4000, thing.uid)

What this does is it sends the UID "number" to the function and takes care of business individually.
It wouldn't overlap and all that crap that you deal with in your code, you may test it if you don't understand what I mean.

I did not write the rest of the stuff, I'm too worn out, when I get time tomorrow I might help you out.
 
I mean, here's the problem. This slow could be extended in a various ways, that I why I need to keep a looping Event that is constantly checking CreatureStorage whether it could have been extended. For instance, if I would cast this spell on the same unit twice, it wouldn't matter as this slowTarget would just restore the speed regardless of any circumstances after four seconds. In my script it constantly checks the value to see if the target's speed should be already restored. That's the main problem. I've heard every unit/monster in OTS have it's own original creature number. For every player it's one and only original number, for monsters it's being passed further once monster have been slain. Is there any way to use this information in the script?
 
this now goes before the onCastSpell function:
Lua:
local function run(thing, left)
	if isCreature(thing) then
		doSendMagicEffect(getThingPos(thing), 7)
		if left == 1 then
			doChangeSpeed(thing, 130)
		else
			addEvent(run, 500, thing, left - 1)
		end
	end
end
the rest of your code:
Code:
	local thing = getTopCreature(cpos).uid
	if thing ~= 0 and thing ~= cid then
		doChangeSpeed(thing, -130)
		doSendMagicEffect(cpos, 20)
		run(thing, 8)
 
Back
Top