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

neutral monster

Capaverde

New Member
Joined
Sep 30, 2007
Messages
107
Reaction score
4
how about making a monster that behaves passively, like sheep, until it is attacked, then it turns hostile to only those who attacked it?
is it possible with creaturescripts?

- - - Updated - - -

I was thinking of something like this


Lua:
local targetlist = {n=0}
local hostile = false
local lasthitcreature = 0
local target = 0

function onThink(cid, interval)
	local m = getLastHitCreature(cid)
	if m ~= lasthitcreature then
		lasthitcreature = m
		if not targetlist[m] then
			if targetlist.n == 0 then
				target = m
			end
			targetlist[m] = true
			targetlist.n = targetlist.n+1
		end
	end
	if not hostile and targetlist.n > 0 then
		cleartargetlist(cid)
		setneutral(cid, true)	--neutral means it wont add 
		sethostile(cid, true)
		hostile = true
		for k,v in pairs(targetlist) do
			doMonsterAddtoTargetList(cid,k)
		end
	elseif hostile and targetlist.n == 0 then
		sethostile(cid, false)
		hostile = false
	end
	if targetlist.n > 0 then
		if not isCreature(target) then --to know if it is alive
			targetlist[target] = nil
			targetlist.n = targetlist.n-1
			target = getMonsterTarget(cid)
		end
	end
end
 
ok, it works
just had to do some source edits

right now its

Lua:
--[[local targetlist = {n=0}
local hostile = false
local lasthitcreature = 0
local target = 0
local origRAH = 8
local maxHealth = 25
local first = true
local lastHealth = 25]]

function onThink(cid, interval)
	local i = monsters[cid]
	if not monsters[cid] then	--just spawned, first onThink
		monsters[cid] = {
			targetlist = {n=0},
			hostile = false,
			lasthitcreature = 0,
			target = 0,
			origRAH = 8,
			maxHealth = 25,
			first = true,
			lastHealth = 25
			}
		setRunAwayHealth(cid, monsters[cid].maxHealth)
		return
	end
	if getCreatureHealth(cid) < i.lastHealth then	--I was hit by something!!
	i.lastHealth = getCreatureHealth(cid)
	local m = getLastHitCreature(cid)
		if m ~= i.lasthitcreature then
			i.lasthitcreature = m
			if not i.targetlist[m] then
				if i.targetlist.n == 0 then
					i.target = m
				end
				i.targetlist[m] = true
				i.targetlist.n = i.targetlist.n+1
				if hostile then
					doMonsterAddtoTargetList(cid,m)
				end
			end
		end
	end
	if not i.hostile and i.targetlist.n > 0 then
		--debugPrint("oloko")
		clearTargetList(cid)
		setNeutral(cid, 1)	--neutral means it wont add 
		setHostile(cid, 1)
		i.hostile = true
		setRunAwayHealth(cid, i.origRAH)
		for k,v in pairs(i.targetlist) do
			if k ~= "n" then
				doMonsterAddtoTargetList(cid,k)
			end
		end
		return	--so it can select the target
	elseif i.hostile and i.targetlist.n == 0 then
		--debugPrint("krai")
		setHostile(cid, 0)
		setNeutral(cid, 0)
		i.hostile = false
		setRunAwayHealth(cid, i.maxHealth)
		i.lasthitcreature = 0	--reset
	end
	if i.targetlist.n > 0 then
		if getCreatureTarget(cid) ~= i.target then --getCreatureHealth(target) <= 0 then -- -- --to know if it is alive
			--debugPrint("desapareceu, nova target eh "..getCreatureTarget(cid))
			i.targetlist[i.target] = nil
			i.targetlist.n = i.targetlist.n-1
			i.target = getCreatureTarget(cid)
		else
			--debugPrint(getCreatureName(i.target))
			--debugPrint(getCreatureHealth(target))
		end
	end
end
 
Last edited:
Back
Top Bottom