• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Attacking levels

Amiroslo

Excellent OT User
Joined
Jul 28, 2009
Messages
6,812
Solutions
6
Reaction score
822
Hello,
Can someone make me a script so a player cannot attack any player, he should only attack a player if this player is higher or lower than him by 20lvls no more and no less.

Im using 0.3.6pl1

rep++
 
this would work?
LUA:
function onTarget(cid, target)
	local lvl = getPlayerLevel(cid)
	local lvlTar = getPlayerLevel(target)
 
	if lvl+20 <= lvlTar or lvl-20 >= lvlTar then
		return true
	else
		return false
	end
end

creaturescript.xml
XML:
		<event type="target" name="Anti" event="script" value="anti.lua"/>

?
 
Last edited:
open data/creaturescripts/creaturescripts.xml
paste this:
XML:
<event type="attack" name="lvlrestriction" event="script" value="lvlrestriction.lua"/>

open data/creaturescripts/scripts/ and create lvlrestriction.lua
paste this in it:
LUA:
function onAttack(cid, target)
local dif = 20 -- lvl of difference
local lvlc = getPlayerLevel(cid)
local lvlt = getPlayerLevel(target)

if lvlc + dif >= lvlt and lvlc - dif <= lvlt then
return true
end
return false
end

open data/creaturescripts/scripts/login.lua

paste this :

LUA:
registerCreatureEvent(cid, "lvlrestriction")


that should be it :D

Hope it works! i havent tested, if it has any console error paste it here, if it doesnt work but doesnt have any error then the problem is in the "return" part xd
i guess it should work but you never know xD
 
Last edited:
i did tought about onTarget, but what if someone does a massive attack spell o.O?

so i did it with onAttack that should be the best.

also have to say that i'm impressed xD i posted the script and i saw your post they look almost the same xD
 
:P, i didnt make that, a friend helped me XD
but ty, if any erros ill tell u, repped
Credits to meee ;)

open data/creaturescripts/creaturescripts.xml
paste this:
XML:
<event type="attack" name="lvlrestriction" event="script" value="lvlrestriction.lua"/>

open data/creaturescripts/scripts/ and create lvlrestriction.lua
paste this in it:
LUA:
function onAttack(cid, target)
local dif = 20 -- lvl of difference
local lvlc = getPlayerLevel(cid)
local lvlt = getPlayerLevel(target)

if lvlc + dif >= lvlt and lvlc - dif <= lvlt then
return true
else
return false
end
end

open data/creaturescripts/scripts/login.lua

paste this :

LUA:
registerCreatureEvent(cid, "lvlrestriction")


that should be it :D

Hope it works! i havent tested, if it has any console error paste it here, if it doesnt work but doesnt have any error then the problem is in the "return" part xd
i guess it should work but you never know xD
Great edit! easier to configure now :)
 
Last edited:
don't be so happy, the idea was really good i have to say i did it my self too, but the function you use should not work as he needs xD
so am still the winner (unless he test it and it doesnt work in wich case we both lose xD)

anyway haven't he tested it yet?
 
Back
Top