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

[SPELL] Advanced FEAR

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,855
Solutions
18
Reaction score
665
Hello.
Anyone can write this spell:
- When we cast spell on target (we must target person/monster before cast spell), the target is fearing for 5 seconds.

What's the spell doing?:
Target is randomly moving, he cannot attack/cast spells, above his head animation of skull is showing for 5 seconds (after fear dissapear the animation is dissapear too)

TFS 0.3.6pl1

Thanks in advance,
Fresh.
 
Last edited:
It's spell fear based on WoW's one. I did it long time ago so if there will be any errors I will try to correct it.
There is one problem - player can attack and cast spell (maybe later I will add something to correct it but I'm not sure about that).


LUA:
local config = {
	fearStorage = 48462, -- free storage
	fearTimes = 10, -- in miliseconds
	fearWalkInterval = 500, -- in miliseconds
	range = {2, 2}
}

function doCreatureFear(target, times, interval, storage)
	if isCreature(target) and times > 0 then
		local p, newPos = getThingPos(target), {}
		local fearDirections = {
			[0] = {{{x=p.x,y=p.y-1,z=p.z}}, {{x=p.x+1,y=p.y,z=p.z}, {x=p.x-1,y=p.y,z=p.z}, {x=p.x-1,y=p.y-1,z=p.z}, {x=p.x+1,y=p.y-1,z=p.z}}},
			[1] = {{{x=p.x+1,y=p.y,z=p.z}}, {{x=p.x,y=p.y+1,z=p.z}, {x=p.x,y=p.y-1,z=p.z}, {x=p.x+1,y=p.y-1,z=p.z}, {x=p.x+1,y=p.y+1,z=p.z}}},
			[2] = {{{x=p.x,y=p.y+1,z=p.z}}, {{x=p.x+1,y=p.y,z=p.z}, {x=p.x-1,y=p.y,z=p.z}, {x=p.x-1,y=p.y+1,z=p.z}, {x=p.x+1,y=p.y+1,z=p.z}}},
			[3] = {{{x=p.x-1,y=p.y,z=p.z}}, {{x=p.x,y=p.y+1,z=p.z}, {x=p.x,y=p.y-1,z=p.z}, {x=p.x-1,y=p.y-1,z=p.z}, {x=p.x-1,y=p.y+1,z=p.z}}},
			[4] = {{{x=p.x,y=p.y+1,z=p.z}, {x=p.x-1,y=p.y,z=p.z}}, {{x=p.x-1,y=p.y-1,z=p.z}, {x=p.x+1,y=p.y+1,z=p.z}, {x=p.x-1,y=p.y+1,z=p.z}}},
			[5] = {{{x=p.x+1,y=p.y,z=p.z}, {x=p.x,y=p.y+1,z=p.z}}, {{x=p.x-1,y=p.y+1,z=p.z}, {x=p.x+1,y=p.y-1,z=p.z}, {x=p.x+1,y=p.y+1,z=p.z}}},
			[6] = {{{x=p.x,y=p.y-1,z=p.z}, {x=p.x-1,y=p.y,z=p.z}}, {{x=p.x+1,y=p.y-1,z=p.z}, {x=p.x-1,y=p.y+1,z=p.z}, {x=p.x-1,y=p.y-1,z=p.z}}},
			[7] = {{{x=p.x+1,y=p.y,z=p.z}, {x=p.x,y=p.y-1,z=p.z}}, {{x=p.x-1,y=p.y-1,z=p.z}, {x=p.x+1,y=p.y+1,z=p.z}, {x=p.x+1,y=p.y-1,z=p.z}}}
		}

		local fear = fearDirections[getCreatureStorage(target, storage)]
		for _, pos in pairs(fear[1]) do
			if doTileQueryAdd(target, pos, 0, false) == RETURNVALUE_NOERROR then
				if getTilePzInfo(pos) ~= true then
					table.insert(newPos, pos)
				end
			end
		end
			
		if #newPos == 0 then
			for _, pos in pairs(fear[2]) do
				if doTileQueryAdd(target, pos, 0, false) == RETURNVALUE_NOERROR then
					if getTilePzInfo(pos) ~= true then
						table.insert(newPos, pos)
					end
				end
			end
		end

		if #newPos ~= 0 then
			doTeleportThing(target, newPos[math.random(#newPos)])
		end
	
		doSendAnimatedText(getThingPos(target), 'Fear', TEXTCOLOR_GREY)
		addEvent(doCreatureFear, interval, target, times - 1, interval, storage)
	end
end

function doCreatureStopFear(target, storage)
	if isCreature(target) then
		doCreatureSetNoMove(target, false)
		doCreatureSetStorage(target, storage, -1)
	end
end

function onCastSpell(cid, var)
	local list, p, targets = getSpectators(getThingPos(cid), config.range[1], config.range[2]), getThingPos(cid), {}

	if #list > 0 then
		for i = 1, #list do
			if cid ~= list[i] then
				table.insert(targets, list[i])
			end
		end
	end

	if #targets > 0 then
		for i = 1, #targets do
			if isPlayer(targets[i]) or isMonster(targets[i]) then
				if getCreatureStorage(targets[i], config.fearStorage) > 0 then
					return false
				end

				doAddCondition(targets[i], createConditionObject(CONDITION_INFIGHT, 1000 * 60))				
				doSendDistanceShoot(p, getThingPos(targets[i]), CONST_ANI_DEATH)
				
				doCreatureSetStorage(targets[i], config.fearStorage, getDirectionTo(getThingPos(cid), getThingPos(targets[i])))
				doCreatureSetNoMove(targets[i], true)
				
				doCreatureFear(targets[i], config.fearTimes, config.fearWalkInterval, config.fearStorage)
				addEvent(doCreatureStopFear, config.fearTimes * config.fearWalkInterval, targets[i], config.fearStorage)
			end
		end
	end
	return true
end
 

Similar threads

Back
Top