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

Lua Challenge on certain monsters?

sestorme

Member
Joined
Dec 9, 2011
Messages
272
Reaction score
6
Location
Birmingham, UK
Is there any chance to set a challenge spell to work on certain monsters only? And is there a chance to put SPELL on Item function? : function onUse(cid, item, frompos, item2, topos)

Any help greatly appreciated +rep
 
You could check for creatures in a nearby area and then call the function doChallengeCreature, or something along that line, when the creature equals one of the creatures you want to be able to be challenged
 
Something like this should do the trick
LUA:
local challengeMonsters = {
"Demon",
"Rat",
"Bear"
}

function onUse(cid, item, frompos, item2, topos)
local cpos = getCreaturePosition(cid)
local pos = {
[1] = {x=cpos.x-1,	y=cpos.y,	z=cpos.z,	stackpos=253},
[2] = {x=cpos.x-1,	y=cpos.y-1,	z=cpos.z,	stackpos=253},
[3] = {x=cpos.x,	y=cpos.y-1,	z=cpos.z,	stackpos=253},
[4] = {x=cpos.x+1,	y=cpos.y,	z=cpos.z,	stackpos=253},
[5] = {x=cpos.x+1,	y=cpos.y+1,	z=cpos.z,	stackpos=253},
[6] = {x=cpos.x,	y=cpos.y+1,	z=cpos.z,	stackpos=253},
[7] = {x=cpos.x-1,	y=cpos.y+1,	z=cpos.z,	stackpos=253},
[8] = {x=cpos.x+1,	y=cpos.y-1,	z=cpos.z,	stackpos=253}
}
local thing = 0
for i = 1,#pos do
	thing = getThingFromPos(pos[i])
	if isCreature(thing) then
		if isInArray(challengeMonsters,getCreatureName(thing)) then
			doChallengeCreature(cid, thing)
		end
	end
end
return true
end
 
Try
LUA:
function onUse(cid, item, fromPos, itemEx, toPos)
	if (isMonster(itemEx.uid) and not getCreatureMaster(itemEx.uid) ~= cid) then
		doChallengeCreature(cid, itemEx.uid)
		doSendMagicEffect(toPos, CONST_ME_MAGIC_RED)
	end

	return true
end
 
Oh.. I didn't read whole thread. Try this version
LUA:
local config = 
{
	"Dragon", "Dog" --[[, and other monsters ]]
}

function onUse(cid, item, fromPos, itemEx, toPos)
	if (isMonster(itemEx.uid) and not getCreatureMaster(itemEx.uid) ~= cid and isInArray(config, getCreatureName(itemEx.uid))) then
		doChallengeCreature(cid, itemEx.uid)
		doSendMagicEffect(toPos, CONST_ME_MAGIC_RED)
	end
 
	return true
end
 
LUA:
local config = 
{
	"Dragon", "Dog" --[[, and other monsters ]]
}
 
function onUse(cid, item, fromPos, itemEx, toPos)
	if (isMonster(itemEx.uid) and getCreatureMaster(itemEx.uid) ~= cid and isInArray(config, getCreatureName(itemEx.uid))) then
		doChallengeCreature(cid, itemEx.uid)
		doSendMagicEffect(toPos, CONST_ME_MAGIC_RED)
	end
 
	return true
end
 
Back
Top