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

Monster script - When you trap a deer it attacks you (It is possible?)

SpO0KIe

:)
Joined
Feb 28, 2010
Messages
192
Solutions
1
Reaction score
5
As the title said!

I would like a script for the monster "Deer" that makes it attack a player when it is trapped and it will only attack the player who stands closest to the deer. Is is even possible to make a script like this?:D

(I'm not sure if this is the right board but I think so).
 
Last edited:
Lua:
function onCombat(cid, target)
	local p = getThingPos(cid)
	for x = p.x-1, p.x+1 do
		for y = p.y-1, p.y+1 do
			if not (p.x == x and p.y == y) and doTileQueryAdd(cid, {x=x, y=y, z=p.z}) == 1 then
				return false
			end
		end
	end
	return true
end
Remove it from login.lua, and add it to the monster file(s):
Code:
	<script>
		<event name="DeerAttack"/>
	</script>
 
OK I will try it but I'm not sure where to put everything.

I made a new script (deerattack.lua) in data\creaturescripts\scripts where I used this:
Lua:
function onCombat(cid, target)
	local p = getThingPos(cid)
	for x = p.x-1, p.x+1 do
		for y = p.y-1, p.y+1 do
			if not (p.x == x and p.y == y) and doTileQueryAdd(cid, {x=x, y=y, z=p.z}) == 1 then
				return false
			end
		end
	end
	return true
end
And added this line in the creaturescripts.xml file.
Code:
<event type="combat" name="DeerAttack" event="script" value="deerattack.lua"/>
Then I went over to the deer.xml in monsters folder and added
Code:
	<script>
		<event name="DeerAttack"/>
	</script>
as you said. And still the deer does not attack me when I trap it. Hmm.... :(
Did I do it right?

EDIT: Btw I will give Rep+ to all of you who tried to help me :thumbup:
 
You have to add a melee attack.
Code:
	<attacks>
		<attack name="melee" interval="2000" min="0" max="-2"/>
	</attacks>
 
Done it already and it didn't work...
I can add that I am using TFS 0.4. If you can, can you try this on a TFS 0.4 server and see if it works for you?
 
Okay then let's debug the script, fyi it works just fine in 0.3.6
Lua:
function onCombat(cid, target)
	local p = getThingPos(cid)
	for x = p.x-1, p.x+1 do
		for y = p.y-1, p.y+1 do
			if not (p.x == x and p.y == y) then
				doCreatureSay(cid, tostring(doTileQueryAdd(cid, {x=x, y=y, z=p.z})), TALKTYPE_ORANGE_1)
				if doTileQueryAdd(cid, {x=x, y=y, z=p.z}) == 1 then
					return false
				end
			end
		end
	end
	return true
end
getting any numbers now?
 
Okay then let's debug the script, fyi it works just fine in 0.3.6
Lua:
function onCombat(cid, target)
	local p = getThingPos(cid)
	for x = p.x-1, p.x+1 do
		for y = p.y-1, p.y+1 do
			if not (p.x == x and p.y == y) then
				doCreatureSay(cid, tostring(doTileQueryAdd(cid, {x=x, y=y, z=p.z})), TALKTYPE_ORANGE_1)
				if doTileQueryAdd(cid, {x=x, y=y, z=p.z}) == 1 then
					return false
				end
			end
		end
	end
	return true
end
getting any numbers now?

(cid) - get numbers if you attack any monster.
 
they should be orange and should show up on the creature (in this case, deer) every time it tries to attack
 
Back
Top