• 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 Help me with spell in npc.

tompan

Member
Joined
Dec 13, 2008
Messages
646
Reaction score
23
Location
Sweden
I have search for it and tried alot diferent but cant fix this.
I want this npc to shoot spears but i dont know how.. i cant get that effect so it flies from the npc to the target.
help me please. :)


Code:
local target = 0
local prevTarget = 0
local maxChaseDistance = 30
local origPos = 0
local lastAttack = 0
local followTimeout = 10
 
local attacks = {
	min = -50,
	max = -100
}
 
local function isSkulled(cid)
	if(getCreatureSkullType(cid) >= SKULL_RED) then
		return true
	end
 
	return false
end
 
local function goToOrigPos()
	target = 0
	lastAttack  = 0
	selfFollow(0)
end
 
local function updateTarget()
	if(not isCreature(target)) then
	elseif(not isSkulled(target)) then
		selfSay("Now, behave in the future.")
	end
 
	if(target == 0) then
		local list = getSpectators(getNpcPos(), 9, 9, false)
		for i = 1, table.getn(list) do
			local _target = list[i]
			if(_target ~= 0) then
				if(isCreature(_target) and isSkulled(_target)) then
					if(not getTilePzInfo(getCreaturePosition(_target))) then
						if(selfFollow(_target)) then
							target = _target
							if(target ~= prevTarget) then
								selfSay("We do not tolerate people like you here!")
							end
 
							prevTarget = target
							break
						end
					end
				end
			end
		end
	end
end
 
function onCreatureAppear(cid)
	if(cid == getNpcCid()) then
		origPos = getNpcPos()
	end
end
 
function onCreatureDisappear(cid)
	if(cid == target) then
		goToOrigPos()
	end
end
 
function onCreatureMove(creature, oldPos, newPos)
	return true
end
 
function onThink()
	updateTarget()
 
	if(target == 0) then
		return
	end
 
	local playerPos = getCreaturePosition(target)
	local myPos = getNpcPos()
 
	if(myPos.z ~= playerPos.z) then
		goToOrigPos()
		return
	end
 
	if(math.abs(myPos.x - origPos.x) > maxChaseDistance or math.abs(myPos.y - origPos.y) > maxChaseDistance) then
		selfSay("I'll catch you next time.")
		goToOrigPos()
		return
	end
 
	if(lastAttack == 0) then
		lastAttack = os.clock()
	end
 
	if(os.clock() - lastAttack > followTimeout) then
		selfSay("You got me this time, but just wait.")
		goToOrigPos()
		return
	end
 
	if((math.abs(playerPos.x - myPos.x) <= 10) and (math.abs(playerPos.y - myPos.y) <= 10)) then
		doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, attacks.min, attacks.max, CONST_ANI_SUDDENDEATH)
		lastAttack = os.clock()
	end
 
	return true
end
 
end of the script you find this

Code:
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, attacks.min, attacks.max, CONST_ANI_SUDDENDEATH)

change to this

Code:
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, attacks.min, attacks.max, CONST_ANI_SPEAR)
 
end of the script you find this

Code:
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, attacks.min, attacks.max, CONST_ANI_SUDDENDEATH)

change to this

Code:
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, attacks.min, attacks.max, CONST_ANI_SPEAR)


Already tried this and it doesnt work. the sudden death doesnt work propertly either.
Bogart's way should work just dont know how to place it.
 
Already tried this and it doesnt work. the sudden death doesnt work propertly either.
Bogart's way should work just dont know how to place it.

Write if it didnt work and any errors!

End of the page add it like i did:

Code:
if((math.abs(playerPos.x - myPos.x) <= 10) and (math.abs(playerPos.y - myPos.y) <= 10)) then
		doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, attacks.min, attacks.max, CONST_ANI_SUDDENDEATH)
                            doSendDistanceShoot(frompos, topos, type[, player]) 
		lastAttack = os.clock()
	end
 
	return true
end
 
well my distro is fucked so cant copy the error, but its says unexpected symbol near ','
and line 105, wich is doSendDistanceShoot(frompos, topos, type[, player])
so i believe its the thing in red thats bugging it.
 
Back
Top