• 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:
Yeah, maybe like a custom spell or something. Check if it has nowhere to run, its slow to do it in Lua though.
 
you can try to make it easier- put melee attacks and keep the distance of deers from players. they will attack when close perhaps also, not only trapped, but i'd pick that as its easiest.
 
Just use an onAttack event in creature scripts. .-. Make it run away on max health, and the onAttack checks for nearest free tile, it there is a free tile, it returns false, if there isn't it returns true. .-.
 
Ok, thanks for your answers but I am not a scripter so I have no idea of how to make this script... Maybe some of you can try? :p
Or you could try to explain (to a noob) how to make this script so I could try to put something together :D
 
Create a script called deerattack.lua and put it in CreatureScripts:
Lua:
function onCombat(cid, target)
	if isPlayer(cid) then
		return true
	end

	local pos, newPos = getCreaturePos(cid), getClosestFreeTile(cid, getCreaturePos(cid))
	if (newPos.x - pos.x) > 1 or (newPos.y - pos.y) > 1 or (newPos.z - pos.z) > 0 then
		return false
	end
	return true
end

Then put something like:
Code:
<event type="combat" name="DeerAttack" event="script" value="deerattack.lua"/>

Then go to your Deer.xml and replace everything with:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Deer" nameDescription="a deer" race="blood" experience="0" speed="150" manacost="260">
	<health now="25" max="25"/>
	<look type="31" corpse="5970"/>
	<targetchange interval="2000" chance="20"/>
	<strategy attack="100" defense="0"/>
	<flags>
		<flag summonable="1"/>
		<flag attackable="1"/>
		<flag hostile="1"/>
		<flag illusionable="1"/>
		<flag convinceable="1"/>
		<flag pushable="1"/>
		<flag canpushitems="0"/>
		<flag canpushcreatures="0"/>
		<flag targetdistance="1"/>
		<flag staticattack="90"/>
		<flag runonhealth="25"/>
	</flags>
	<script>
		<event name="DeerAttack"/>
	</script>
	<attacks>
		<attack name="melee" interval="2000" skill="10" attack="2"/>
	</attacks>
	<defenses armor="2" defense="2"/>
	<immunities>
		<immunity physical="0"/>
		<immunity energy="0"/>
		<immunity fire="0"/>
		<immunity poison="0"/>
		<immunity lifedrain="0"/>
		<immunity paralyze="0"/>
		<immunity outfit="0"/>
		<immunity drunk="0"/>
		<immunity invisible="0"/>
	</immunities>
	<loot>
		<item id="3976" countmax="10" chance="50000"/><!-- worm -->
		<item id="2666" countmax="4" chance="100000"/><!-- meat -->
	</loot>
</monster>
 
Thanks for the script but it doesn't seem to work.. The deer does turn towards me and then run away but when I trap it it doesn't attack me :S

EDIT: I also got this error in the console: " [Warining - Monster::Monster] Unknown event name - deerattack "
 
Last edited:
Raise the attack a bit more and make sure it is hostile. Also, add:
Lua:
print("Deer: I am now trapped.")

Under:
Lua:
if (newPos.x - pos.x) > 1 or (newPos.y - pos.y) > 1 or (newPos.z - pos.z) > 0 then

To see if the check works.
 
It still doesn't work. No errors in console and no actions at all.

Here's a screen shot of how I trapped the deer:
2wdu1jm.png
 
Lua:
function onCombat(cid, target)
	if isPlayer(cid) then
		return true
	end
 
	local pos = getCreaturePos(cid)
	if not getClosestFreeTile(cid, pos) then
		return false
	end
	return true
end

Try this script. Should work.
 
Wopps.. My bad, I meant
Code:
registerCreatureEvent(cid, "DeerAttack")

I copied the wrong one:D
But as you said, it doesn't work :S
 
Last edited:
Back
Top