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

Chain Lightning and Chain Heal

  • Thread starter Thread starter Deleted member 49793
  • Start date Start date
D

Deleted member 49793

Guest
Basicly as the title says im looking for a Chain Lightning and Chain Heal spell

Basicly Chain Lightning...
shoot at target, looks like hmm hit them then bounces to a random target on screen dealing same damage, then to another and another (bounces 4 times)... Cannot bounce more than 3 squares OR through walls etc.

Chain Heal...
shoot at target, looks like exori san hit them then bounces to a random target on screen healing same amount, then to another and another (bounces 4 times)... Cannot bounce more than 3 squares OR through walls etc.

Thanks Guys

Rep for who helps :D
 
Code:
function onCastSpell(cid, var)
	local creatures, targets = getSpectators(variantToPosition(var), 3, 3), {}

	while #targets < (#creatures > 3 and 3 or #creatures - 1) do
		local target = creatures[math.random(#creatures)]
		if not isInArray(targets, target) and isSightClear(variantToPosition(var), getThingPosition(target)) and cid ~= target then
			table.insert(targets)
		end
	end

	for k, v in ipairs(targets) do
		if k == 1 then
			doSendDistanceShoot(variantToPosition(var), getThingPosition(v), CONST_ANI_ENERGY)
		elseif k < #targets then
			doSendDistanceShoot(getThingPosition(targets[k - 1]), getThingPosition(v), CONST_ANI_ENERGY)
		end

		doTargetCombatHealth(cid, v, COMBAT_ENERGYDAMAGE, -100, -200, CONST_ME_ENERGYHIT)
	end

	return true
end
 
Not working:
LUA:
[15:5:33.609] [Error - Spell Interface]
[15:5:33.609] data/spells/scripts/new.lua:onCastSpell
[15:5:33.609] Description:
[15:5:33.609] data/spells/scripts/new.lua:4: attempt to get length of local 'creatures' (a nil value)
[15:5:33.609] stack traceback:
[15:5:33.609]   data/spells/scripts/new.lua:4: in function <data/spells/scripts/new.lua:1>
 
It's fixed script from post above, but it's still not good (no config and player can use spell without target?!):
PHP:
function onCastSpell(cid, var)
	local creatures, targets = getSpectators(variantToPosition(var), 3, 3), {}
	if creatures ~= nil then
		while #targets < (#creatures > 3 and 3 or #creatures - 1) do
			local target = creatures[math.random(#creatures)]
			if not isInArray(targets, target) and isSightClear(variantToPosition(var), getThingPosition(target)) and cid ~= target then
				table.insert(targets)
			end
		end

		for k, v in ipairs(targets) do
			if k == 1 then
				doSendDistanceShoot(variantToPosition(var), getThingPosition(v), CONST_ANI_ENERGY)
			elseif k < #targets then
				doSendDistanceShoot(getThingPosition(targets[k - 1]), getThingPosition(v), CONST_ANI_ENERGY)
			end

			doTargetCombatHealth(cid, v, COMBAT_ENERGYDAMAGE, -100, -200, CONST_ME_ENERGYHIT)
		end
	end
	return true
end
 
Do you have needtarget="1" in spells.xml?
...
getSpectators(variantToPosition(var), 3, 3)
...
When you use 'needtarget' I think in 'var' is 'uid' of player attacked (of course you must convert var to number - variantToNumber(var)). Am I right?

Then it should be:
PHP:
function onCastSpell(cid, var)
    local creatures, targets = getSpectators(getThingPosition(variantToNumber(var)), 3, 3), {}
    if creatures ~= nil then
        while #targets < (#creatures > 3 and 3 or #creatures - 1) do
            local target = creatures[math.random(#creatures)]
            if not isInArray(targets, target) and isSightClear(getThingPosition(variantToNumber(var)), getThingPosition(target)) and cid ~= target then
                table.insert(targets)
            end
        end

        for k, v in ipairs(targets) do
            if k == 1 then
                doSendDistanceShoot(getThingPosition(variantToNumber(var)), getThingPosition(v), CONST_ANI_ENERGY)
            elseif k < #targets then
                doSendDistanceShoot(getThingPosition(targets[k - 1]), getThingPosition(v), CONST_ANI_ENERGY)
            end

            doTargetCombatHealth(cid, v, COMBAT_ENERGYDAMAGE, -100, -200, CONST_ME_ENERGYHIT)
        end
    end
    return true
end
EDIT:
@VirrageS
Do not remove 'needtarget'
 
Code:
[16:54:25.437] [Error - Spell Interface]
[16:54:25.437] data/spells/scripts/new.lua:onCastSpell
[16:54:25.437] Description:
[16:54:25.437] attempt to index a function value
[16:54:25.437] stack traceback:
[16:54:25.437]  [C]: in function 'isSightClear'
[16:54:25.437]  data/spells/scripts/new.lua:6: in function <data/spells/scripts/
new.lua:1>
:(
 
I don't know how to script that but i know someone made simliar like this a chaining sd on otfans or otland not sure wich you can use search fucntion maybe you get results.
 
Back
Top