• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

CreatureEvent Level Protection

Syntax

Developer
Joined
Oct 10, 2007
Messages
2,890
Reaction score
459
Location
Texas
Uhm this has been done a million times over AFAIK but someone requested something like it, just thought I'd put it here incase anyone was silently looking for it. It's a simple level protection script, most of its explained in the script itself. If you don't know how to install it then you probably shouldn't be here.

Code:
[FONT=Courier New][COLOR=#008000][I]--LEVEL_THRESHOLD is how many levels your victim can be away from your own level
--Example: Threshold of 10 means a player with level 100 can people at level 90 to level 110[/I][/COLOR]
[COLOR=#0000FF][B]local[/B][/COLOR] LEVEL_THRESHOLD [COLOR=#FF0000]=[/COLOR] 10
 
[COLOR=#0000FF][B]local[/B][/COLOR] [COLOR=#0000FF][B]function[/B][/COLOR] isPlayerAboveThreshold[COLOR=#FF0000]([/COLOR]cid[COLOR=#FF0000],[/COLOR] target[COLOR=#FF0000])[/COLOR]
 
    [COLOR=#008000][I]-- This makes sure we are only processing statchanges made by PvP[/I][/COLOR]
    [COLOR=#0000FF][B]if[/B][/COLOR][COLOR=#FF0000]([/COLOR]isPlayer[COLOR=#FF0000]([/COLOR]target[COLOR=#FF0000])[/COLOR][COLOR=#FF0000])[/COLOR][COLOR=#0000FF][B]then[/B][/COLOR]
 
        [COLOR=#008000][I]-- We need to get the players levels of course[/I][/COLOR]
        [COLOR=#0000FF][B]local[/B][/COLOR] attackerLvl[COLOR=#FF0000],[/COLOR] targetLvl [COLOR=#FF0000]=[/COLOR] getPlayerLevel[COLOR=#FF0000]([/COLOR]cid[COLOR=#FF0000])[/COLOR][COLOR=#FF0000],[/COLOR] getPlayerLevel[COLOR=#FF0000]([/COLOR]target[COLOR=#FF0000])
[/COLOR] 
        [COLOR=#008000][I]-- Now we shall check the actual threshold vs. the ideal one[/I][/COLOR]
        [COLOR=#0000FF][B]if[/B][/COLOR][COLOR=#FF0000]([/COLOR]math[COLOR=#FF0000].[/COLOR]abs[COLOR=#FF0000]([/COLOR]attackerLvl [COLOR=#FF0000]-[/COLOR] targetLvl[COLOR=#FF0000])[/COLOR] &gt LEVEL_THRESHOLD[COLOR=#FF0000])[/COLOR][COLOR=#0000FF][B]then[/B][/COLOR]
 
            [COLOR=#008000][I]-- OMG it's above the limit! We shall report back with what we found![/I][/COLOR]
            [COLOR=#0000FF][B]return[/B][/COLOR] [COLOR=#0000FF][B]true[/B][/COLOR]
 
        [COLOR=#0000FF][B]end[/B][/COLOR]
    [COLOR=#0000FF][B]end[/B][/COLOR]
 
    [COLOR=#008000][I]-- At least one condition was not met. We shall say false![/I][/COLOR]
    [COLOR=#0000FF][B]return[/B][/COLOR] [COLOR=#0000FF][B]false[/B][/COLOR]
[COLOR=#0000FF][B]end[/B][/COLOR]
 
[COLOR=#0000FF][B]function[/B][/COLOR] onStatsChange[COLOR=#FF0000]([/COLOR]cid[COLOR=#FF0000],[/COLOR] attacker[COLOR=#FF0000],[/COLOR] [COLOR=#0080C0][B]type[/B][/COLOR][COLOR=#FF0000],[/COLOR] combat[COLOR=#FF0000],[/COLOR] value[COLOR=#FF0000])[/COLOR]
    [COLOR=#0000FF][B]if[/B][/COLOR][COLOR=#FF0000]([/COLOR]isPlayerAboveThreshold[COLOR=#FF0000]([/COLOR]attacker[COLOR=#FF0000],[/COLOR] cid[COLOR=#FF0000])[/COLOR][COLOR=#FF0000])[/COLOR][COLOR=#0000FF][B]then[/B][/COLOR]
        [COLOR=#0000FF][B]return[/B][/COLOR] [COLOR=#0000FF][B]false[/B][/COLOR]
    [COLOR=#0000FF][B]end[/B][/COLOR]
    [COLOR=#0000FF][B]return[/B][/COLOR] [COLOR=#0000FF][B]true[/B][/COLOR]
[COLOR=#0000FF][B]end[/B][/COLOR]
 
[COLOR=#0000FF][B]function[/B][/COLOR] onTarget[COLOR=#FF0000]([/COLOR]cid[COLOR=#FF0000],[/COLOR] target[COLOR=#FF0000])[/COLOR]
    [COLOR=#0000FF][B]if[/B][/COLOR][COLOR=#FF0000]([/COLOR]isPlayerAboveThreshold[COLOR=#FF0000]([/COLOR]cid[COLOR=#FF0000],[/COLOR] target[COLOR=#FF0000])[/COLOR][COLOR=#FF0000])[/COLOR][COLOR=#0000FF][B]then[/B][/COLOR]
        [COLOR=#0000FF][B]return[/B][/COLOR] [COLOR=#0000FF][B]false[/B][/COLOR]
    [COLOR=#0000FF][B]end[/B][/COLOR]
    [COLOR=#0000FF][B]return[/B][/COLOR] [COLOR=#0000FF][B]true[/B][/COLOR]
[COLOR=#0000FF][B]end[/B][/COLOR]
[/FONT]
 
Uhm this has been done a million times over AFAIK but someone requested something like it, just thought I'd put it here incase anyone was silently looking for it. It's a simple level protection script, most of its explained in the script itself. If you don't know how to install it then you probably shouldn't be here.

Great idea, but I was wondering about function onStatsChange(cid, attacker, type, combat, value). If player A is 90 and player B is 200 can player B heal player A? Cos AFAIK onStatsChange is used for every kind of combat.

Lua:
STATSCHANGE_HEALTHGAIN = 0
STATSCHANGE_HEALTHLOSS = 1
STATSCHANGE_MANAGAIN = 2
STATSCHANGE_MANALOSS = 3
that's what I found in lib.
So IMO, if I may, you could use either:
Lua:
if(type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then

or

Lua:
function onCombat(cid, target)
    if(isPlayerAboveThreshold(cid, target)) then
        return false
    end
    return true
end

Because as I remember onCombat() was onStatsChange + onTarget. :D
 
Can you make protection against crash:
While server started after login you have 30 seconds protection (players/monsters cant attack you and you cannot attack players/monsters) ?:w00t:
 
Can you make protection against crash:
While server started after login you have 30 seconds protection (players/monsters cant attack you and you cannot attack players/monsters) ?:w00t:

Set a storage value to 1 onlogin (with an addEvent to set the storage value back to -1 after 30 seconds) and check onstatschange if they have this storage value set to 1 (then falsify combat).
 
Back
Top