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

NPCs killables?

Rayeko

Programmer
Joined
Apr 9, 2008
Messages
185
Reaction score
3
Hi

I just wanted to know if it was possible to make NPCs vulnerable, so they can be killed by players. I made it possible to attack NPCs, but nothing inflicts them damage.. Just a poff. Here is my NPC script:

Code:
<?xml version="1.0"?>

<npc name="Eryn" script="data/npc/scripts/default.lua" access="0" attackable="1" walkinterval="7000" lookdir="2">
	<health now="1000" max="1000"/>
<look type="335" head="0" body="57" legs="114" feet="0" addons="3"/>
<parameters>
        <parameter key="message_greet" value="Welcome here, |PLAYERNAME|." />
    </parameters>
</npc>

Thanks in advance!
 
Where should I edit? I thought of that too, so I went into the sources.. I first tried to npc.cpp but don't know what to add, actually xD

Any idea?
 
Atleast in 0.4 there is:
Code:
if(readXMLString(root, "attackable", strValue))
		attackable = booleanString(strValue);

So what i read from that it should be possible to add attackable="yes"

In the npc file
 
Yep.. Its also possible, here.. But the problem is that, when I put attackable = "yes", I can attack the NPC, but.. I don't inflict any damage.. Just appears like "poofs".
But I can't get to find the function where "attackable" takes place.. Where it stablishes that it can be attacked.. u,u
 
Yes, I just tried that.. But, it happens the same.. I think that works as a standard value if attackable is not stablished in the XMl file.. Because, now I can attack all NPCs xD, But.. No damage is inflicted u.u
 
search on otfans, theres a thread that has your answer, if you don't find it in a few hours ill post it, too busy to look
 
@Up

Sorry.. Just searched many times at otfans, also with google, but can't get anything u__u

I would really appreciate if you can give me a link or soemthing like that u,u
 
@Up

Noup ;S I just found one post that was "NPC onDeath", but this function works when the NPC dies, but my problem is that I can't even kill a npc.. I just don't inflict any damage u,u
 
;S
try do it like this:
Code:
function onKill(cid, target, lastHit)
         local name = getCreatureName(target)
         local names = {"Npc", "Npc", "Npc"}
         for name, v in pairs(names) do
             if name == v then
etc
just an example ;s
 
;S
try do it like this:
Code:
function onKill(cid, target, lastHit)
         local name = getCreatureName(target)
         local names = {"Npc", "Npc", "Npc"}
         for name, v in pairs(names) do
             if name == names then
etc
just an example ;s

That's still onKill, to solve this maybe you could use onAttack, onCombat or onTarget.
 
like this?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="hueheuhe" version="1.0" author="hsuasha" contact="in my house" enabled="yes">
	<event type="login" name="npcs" event="script"><![CDATA[
		registerCreatureEvent(cid, "npc")
		return true
	]]></event>
	<event type="target" name="npc" event="script"><![CDATA[
		if isPlayer(cid) and isNpc(target) then
			local name = getCreatureName(target)
			local names = {"Npc", "Npc", "Npc"}
			for name, v in pairs(names) do
				if name == v then
					return true
				end
			end
		end
		return true
	]]></event>
</mod>
or might work like this also
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="hueheuhe" version="1.0" author="hsuasha" contact="in my house" enabled="yes">
	<event type="login" name="npcs" event="script"><![CDATA[
		registerCreatureEvent(cid, "npc")
		return true
	]]></event>
	<event type="target" name="npc" event="script"><![CDATA[
		if isNpc(target) then
			local name = {}
			table.insert(name, getCreatureName(target))
		end
		for name, v in pairs(name) do
			if isNpc(v) then
				return true
			end
		end
		return true
	]]></event>
</mod>

or this
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="hueheuhe" version="1.0" author="hsuasha" contact="in my house" enabled="yes">
	<event type="login" name="npcs" event="script"><![CDATA[
		registerCreatureEvent(cid, "npc")
		return true
	]]></event>
	<event type="target" name="npc" event="script"><![CDATA[
		if isNpc(target) then
			local name = {}
			table.insert(name, getCreatureName(target))
		end
		for _, names in ipairs(name) do
			if isNpc(names) then
				return true
			end
		end
		return true
	]]></event>
</mod>
not sure, try all lol
 
Last edited:
like this?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="hueheuhe" version="1.0" author="hsuasha" contact="in my house" enabled="yes">
	<event type="login" name="npcs" event="script"><![CDATA[
		registerCreatureEvent(cid, "npc")
		return true
	]]></event>
	<event type="target" name="npc" event="script"><![CDATA[
		if isPlayer(cid) and isNpc(target) then
			local name = getCreatureName(target)
			local names = {"Npc", "Npc", "Npc"}
			for name, v in pairs(names) do
				if name == v then
					return true
				end
			end
		end
		return true
	]]></event>
</mod>
or might work like this also
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="hueheuhe" version="1.0" author="hsuasha" contact="in my house" enabled="yes">
	<event type="login" name="npcs" event="script"><![CDATA[
		registerCreatureEvent(cid, "npc")
		return true
	]]></event>
	<event type="target" name="npc" event="script"><![CDATA[
		if isNpc(target) then
			local name = {}
			table.insert(name, getCreatureName(target))
		end
		for name, v in pairs(name) do
			if isNpc(v) then
				return true
			end
		end
		return true
	]]></event>
</mod>

Nope ;S Still with the same error.. Nothing happens u,u just poffs and block hits, but no damage.. u,u Even with spells.

I thought something like "onAttack", and making like "doCreatureAddHealth(npc, -10)" something like that.. But can't do it so that the damage is the same as if using a normal spell to a monster or player..
 
try this ;S
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="hueheuhe" version="1.0" author="hsuasha" contact="in my house" enabled="yes">
	<event type="login" name="npcs" event="script"><![CDATA[
		registerCreatureEvent(cid, "npc")
		return true
	]]></event>
	<event type="target" name="npc" event="script"><![CDATA[
		if isNpc(target) then
			local name = {}
			table.insert(name, getCreatureName(target))
		end
		for _, v in pairs(name) do
			if isNpc(v) then
				return doCreatureAddHealth(target, -(getCreatureMaxHealth(target)))
			end
		end
		return true
	]]></event>
</mod>
 
Nope.. Still not working.. This is weird ;S I think there must be something stopping the NPC from losing health ;S Maybe on the sources.. But I didn't found anything yesterday u,u

Edit:
LOL Just changed "type=target" to "type=attack" and it worked xDD But, now I must figure out how to make so that the damage inflicted to the NPC is obtained from a formula, depending on the spell the player used or from the weapon he used :/ and that can be a little bit complicated, I think u,u

Edit2: It only works when attacking with weapon. If spells are used, nothing happens xD

Edit3: Also, when the NPC is killed with the script, it doesn't dies. It stands there without HP. Althought I put "corpse=6080" in the npc.xml file u,u
 
Last edited:
Back
Top