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

CreatureEvent Level Difference Protection

Keraxel

Ω Obfuscator Ω
Joined
Feb 2, 2008
Messages
941
Reaction score
5
Location
Republic of Poland
Idea: http://otland.net/f35/level-diference-protection-pvp-22098/

The script allows for attack only players with level which is lower or highter from typed number (config.maxDiff).
Also I've added percent type so you can set it in percents. For example:
Code:
maxDiff = 30
player1 level - 100
player2 level - 131 - 31% more than player1 

So theese players cannot attack each other.

Works only with TFS 0.3.3+

data/creaturescripts/scripts/levelDiff.lua
Lua:
local config = {
diffType = 1, -- 1 = NORMAL/ 2 = PERCENT
maxDiff = 30
}
function onCombat(cid, target)
	if isPlayer(cid) ~= TRUE or isPlayer(target) ~= TRUE then
		return TRUE
	end

	if config. diffType == 1 then -- if NORMAL
		if math.abs(getPlayerLevel(cid) - getPlayerLevel(target)) > config.maxDiff then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER)
			return FALSE
		end
	elseif config.diffType == 2 then --if PERCENT
		local levels = {getPlayerLevel(cid), getPlayerLevel(target)}
		table.sort(levels)
		if (((levels[2] - levels[1]) * 100) / levels[1]) > config.maxDiff then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER)
			return FALSE
		end
	else
		print("DEBUG: Wrong config.diffType")
	end
	return TRUE
end

data/creaturescripts/creaturescripts.xml
PHP:
<event type="combat" name="KillProtection" script="levelDiff.lua" />

data/creaturescripts/scripts/login.lua,
Before:
Lua:
return TRUE
Add:
Lua:
registerCreatureEvent(cid, "KillProtection")

Regards,
Keraxel.
 
Last edited:
I'm a bit curious, does this only work for melee/distance or for magic aswell?

I'm not really familiar with onAttack()


sincerly, Exhibition
 
On my server players cant attack with meele or dist, but they can with magics :S I have copied the script dident change anything, what could be wrong? Forgotten 0.3b3
 
Eh ;/ Probably there's a bug in onAttack. On 0.3.1pl2 I've got crash with this script ;S It only can be repaired by TFS devels ;)
 
Nice script =o

But I think runes can still be used, because they have nothing to do with the onAttack event...
 
Hm, what about player casting a spell without marking other player to attack?
 
This is not maded by COLANDUS? :O
A one nice time I saw it with one Colandus post with other forum!!!

But Nice, if its from you: Congratulations!!!

If you take it from other forum and pasted it here: I think the credits is the minimum you will use!!! :p

See you!
 
Back
Top