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

Npc Guard

Hompas

Homer
Joined
Jul 15, 2011
Messages
20
Reaction score
0
Hello, i was woundering if someone can script me a Npc Guard. And when a monster come
the Npc guard kill it with one hit, it's possible?

-Players wont get the loot
-Guard walking normal
-Npc Guard using SD or sword, you decide.

And one more request, how to make a guard stand still? like Rl Tibia..
-I want i to stand south.

Thanks!:)
 
Looking for something exactly like this except npc doesn't use SD, only melee (dmg 50-90) configurable) nor stand still, just attacks any monster that could be lured into the city.
 
There is an example NPC in default TFS datapack which hunts skulled players. Just edit target search function to use isMonster function instead of getCreatureSkullType.

I got this error

Code:
[11/08/2011 14:33:15] Lua Script Error: [Npc interface] 
[11/08/2011 14:33:15] data/npc/scripts/cityguard.lua:onThink
[11/08/2011 14:33:15] data/npc/scripts/cityguard.lua:9: attempt to call global 'getCreatureSkullType' (a nil value)
[11/08/2011 14:33:15] stack traceback:
[11/08/2011 14:33:15] 	[C]: in function 'getCreatureSkullType'
[11/08/2011 14:33:15] 	data/npc/scripts/cityguard.lua:9: in function 'ismonster'
[11/08/2011 14:33:15] 	data/npc/scripts/cityguard.lua:36: in function 'updateTarget'
[11/08/2011 14:33:15] 	data/npc/scripts/cityguard.lua:71: in function <data/npc/scripts/cityguard.lua:70>
 
but i got shit now, onthink? i did not add you last code

Code:
[11/08/2011 15:24:21] The Forgotten Server - Version 0.2.10 (Mystic Spirit).
[11/08/2011 15:24:21] A server developed by Talaturen, Kornholijo, Elf, and Fallen.
[11/08/2011 15:24:21] Visit our forum for updates, support, and resources: http://otland.net/.

[11/08/2011 15:24:21] >> Loading config
[11/08/2011 15:24:21] >> Loading RSA key
[11/08/2011 15:24:22] >> Testing SQL connection... SQLite.
[11/08/2011 15:24:22] >> Loading bans
[11/08/2011 15:24:22] >> Loading vocations
[11/08/2011 15:24:22] >> Loading commands
[11/08/2011 15:24:22] >> Loading items
[11/08/2011 15:24:22] >> Loading script systems
[11/08/2011 15:24:23] >> Loading monsters
[11/08/2011 15:24:23] >> Loading outfits
[11/08/2011 15:24:23] >> Loading admin protocol config
[11/08/2011 15:24:23] >> Loading experience stages
[11/08/2011 15:24:23] >> Using plaintext passwords
[11/08/2011 15:24:23] >> Checking world type... PVP
[11/08/2011 15:24:23] >> Loading map
[11/08/2011 15:24:24] > Map size: 2048x2048.
[11/08/2011 15:24:24] > Map loading time: 0.937 seconds.
[11/08/2011 15:24:24] Notice: Map load (relational) took : 0 s
[11/08/2011 15:24:24] >> Initializing gamestate
[11/08/2011 15:24:25] >> Loaded all modules, server starting up...
[11/08/2011 15:24:26] >> Forgotten Server Online!


[11/08/2011 15:24:27] Lua Script Error: [Npc interface] 
[11/08/2011 15:24:27] data/npc/scripts/cityguard.lua:onThink
[11/08/2011 15:24:27] data/npc/scripts/cityguard.lua:36: attempt to call global 'isMonster' (a nil value)
[11/08/2011 15:24:27] stack traceback:
[11/08/2011 15:24:27] 	[C]: in function 'isMonster'
[11/08/2011 15:24:27] 	data/npc/scripts/cityguard.lua:36: in function 'updateTarget'
[11/08/2011 15:24:27] 	data/npc/scripts/cityguard.lua:71: in function <data/npc/scripts/cityguard.lua:70>
 
Lua:
local t = {}
local combat = {
	type = COMBAT_PHYSICALDAMAGE,
	min = -999999,
	max = -999999,
	effect = 206,
	disteffect = 40
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local radX, radY = 8, 8
local timeBetweenAttack = 1 -- seconds
 
function onThink()
	local npc, _t = getNpcId(), {}
	local p, f = getThingPos(npc)
	for _, cid in ipairs(getSpectators(p, radX, radY) or {}) do
		if isMonster(target) then
			if not f then
				selfFocus(cid)
				f = true
			end
			local new = not t[cid]
			if new or os.clock() - t[cid][1] >= timeBetweenAttack then
				local _p = getThingPos(cid)
				if not getTileInfo(_p).protection and isSightClear(p, _p, false) then
					if isMonster(target) then
						_t[cid] = {os.clock(), (new or os.clock() - t[cid][1] >= 20) and 1 or t[cid][2] + 1.5}
						selfSay("Monsters are not allowed here!")
						doTargetCombatHealth(npc, cid, combat.type, combat.min * _t[cid][2], combat.max * _t[cid][2], combat.effect)
						doSendDistanceShoot(p, _p, combat.disteffect)
					end
				end
			else
				_t[cid] = {t[cid][1], 1}
			end
		end
	end
	if not f then
		selfFocus(0)
	end
	t = _t
	npcHandler:onThink()
end

Not tested.
 
@Diath:

Lua:
function isMonster(cid)
	return isCreature(cid) and cid >= AUTOID_MONSTERS and cid < AUTOID_NPCS
end

function isNpc(cid)
	return isCreature(cid) and cid >= AUTOID_NPCS
end
 
did not work.. :(

Code:
[11/08/2011 16:24:28] The Forgotten Server - Version 0.2.10 (Mystic Spirit).
[11/08/2011 16:24:28] A server developed by Talaturen, Kornholijo, Elf, and Fallen.
[11/08/2011 16:24:28] Visit our forum for updates, support, and resources: http://otland.net/.

[11/08/2011 16:24:28] >> Loading config
[11/08/2011 16:24:28] >> Loading RSA key
[11/08/2011 16:24:28] >> Testing SQL connection... SQLite.
[11/08/2011 16:24:28] >> Loading bans
[11/08/2011 16:24:28] >> Loading vocations
[11/08/2011 16:24:28] >> Loading commands
[11/08/2011 16:24:28] >> Loading items
[11/08/2011 16:24:28] >> Loading script systems
[11/08/2011 16:24:30] >> Loading monsters
[11/08/2011 16:24:32] >> Loading outfits
[11/08/2011 16:24:32] >> Loading admin protocol config
[11/08/2011 16:24:32] >> Loading experience stages
[11/08/2011 16:24:32] >> Using plaintext passwords
[11/08/2011 16:24:32] >> Checking world type... PVP
[11/08/2011 16:24:32] >> Loading map
[11/08/2011 16:24:33] > Map size: 2048x2048.
[11/08/2011 16:24:34] > Map loading time: 1.578 seconds.
[11/08/2011 16:24:35] Notice: Map load (relational) took : 0 s
[11/08/2011 16:24:35] >> Initializing gamestate
[11/08/2011 16:24:35] >> Loaded all modules, server starting up...
[11/08/2011 16:24:37] >> Forgotten Server Online!


[11/08/2011 16:24:37] Lua Script Error: [Npc interface] 
[11/08/2011 16:24:37] data/npc/scripts/cityguard.lua:onThink
[11/08/2011 16:24:37] data/npc/scripts/cityguard.lua:18: attempt to call global 'getNpcId' (a nil value)
[11/08/2011 16:24:37] stack traceback:
[11/08/2011 16:24:37] 	[C]: in function 'getNpcId'
[11/08/2011 16:24:37] 	data/npc/scripts/cityguard.lua:18: in function <data/npc/scripts/cityguard.lua:17>
 
Back
Top