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

Pvp Protection script

Exhale19

New Member
Joined
Oct 20, 2016
Messages
3
Reaction score
0
Hi Guys. Im searching pvp protection script, which players with for example 50-149, can not attack players with 150+. I've got something like that, but it doesn't work. Do you have any idea^^?

local stages = {
{ from = 50, to = 149 },
{ from = 150, to = 350},
{ from = 350, to = 999}

}

function onCombat(cid, target)
local level = getPlayerLevel(cid)
if isPlayer(target) == TRUE then
local target_level = getPlayerLevel(target)
for i = 1, #stages do
if level >= stages.from and level <= stages.to then
if target_level >= stages.from and target_level <= stages.to then
return TRUE
else
doPlayerSendCancel(cid, "You are not allowed to attack this Player.")
end
end
end
 
have you tried return false when you send cancel?
also use [.code] codehere [./code] tags without the . to post code
Code:
 codehere
 
Okey, im sorry, im new here^^. This doesnt work anyway :x, have other ideas? ;x
When you write a script you should try to properly indent it so that you can see its level of execution. This makes it easier to troubleshoot the issue. I've went ahead and done that for you but also added in the missing end keywords. Try the script again and see if it works now as intended.
Code:
local stages = {
    { from = 50, to = 149 },
    { from = 150, to = 350},
    { from = 350, to = 999}
}

function onCombat(cid, target)
    local level = getPlayerLevel(cid)
    if isPlayer(target) == TRUE then
        local target_level = getPlayerLevel(target)
        for i = 1, #stages do
            if level >= stages.from and level <= stages.to then
                if target_level >= stages.from and target_level <= stages.to then
                    return TRUE
                else
                    doPlayerSendCancel(cid, "You are not allowed to attack this Player.")
                end
            end
        end -- this was added
    end -- so was this
end
 
Code:
                   return doPlayerSendCancel(cid, "You are not allowed to attack this Player.")
                end
            end
        end -- this was added
    end -- so was this
    return true -- will remove weird bugs if used with older tfs versions
end
 
Lel :D
Code:
stages[i]

Code:
local stages = {
    { from = 50, to = 149 },
    { from = 150, to = 350},
    { from = 350, to = 999}
}

function onCombat(cid, target)
    local level = getPlayerLevel(cid)
    if isPlayer(target) == TRUE then
        local target_level = getPlayerLevel(target)
        for i = 1, #stages do
            if level >= stages[i].from and level <= stages[i].to and target_level >= stages[i].from and target_level <= stages[i].to then
                return TRUE
            else
                return doPlayerSendCancel(cid, "You are not allowed to attack this Player.")
            end
        end -- this was added
    end -- so was this
    return true
end
 
Lel :D
Code:
stages[i]

Code:
local stages = {
    { from = 50, to = 149 },
    { from = 150, to = 350},
    { from = 350, to = 999}
}

function onCombat(cid, target)
    local level = getPlayerLevel(cid)
    if isPlayer(target) == TRUE then
        local target_level = getPlayerLevel(target)
        for i = 1, #stages do
            if level >= stages[i].from and level <= stages[i].to and target_level >= stages[i].from and target_level <= stages[i].to then
                return TRUE
            else
                return doPlayerSendCancel(cid, "You are not allowed to attack this Player.")
            end
        end -- this was added
    end -- so was this
    return true
end
You are on a roll!
 
Back
Top