• 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 KD count unjustified

Fortera Global

Intermediate OT User
Joined
Nov 20, 2015
Messages
1,180
Solutions
2
Reaction score
117
This is a script to add kills and death in the char, the famous KD.
I would like to just to get kills/death If the killer is not within a pvp zone area.

I want to say that: if you are in pvp area, you will not count kill/death for not getting unjustified.

tfs 1.2


Lua:
function onKill(creature, target)
 
    if creature:isPlayer() and target:isPlayer() then
      return true
    end
 
    creature:say("+1 Kill", TALKTYPE_ORANGE_1)
    creature:setStorageValue(167912, math.max(0, creature:getStorageValue(167912)) + 1)
   
    return true
end
function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    creature:say("+1 Death", TALKTYPE_ORANGE_1)
    creature:setStorageValue(167913, math.max(0, creature:getStorageValue(167913)) + 1)
    return true
end
 
Solution
Lua:
function onKill(creature, target)
    if creature:isPlayer() and target:isPlayer() and not Tile(creature:getPosition()):hasFlag(TILESTATE_PVPZONE) then   
        creature:say("+1 Kill", TALKTYPE_ORANGE_1)
        creature:setStorageValue(167912, math.max(0, creature:getStorageValue(167912)) + 1)
    end
    return true
end
function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    if not Tile(creature:getPosition()):hasFlag(TILESTATE_PVPZONE) then
        creature:say("+1 Death", TALKTYPE_ORANGE_1)
        creature:setStorageValue(167913, math.max(0, creature:getStorageValue(167913)) + 1)
    end
    return true
end
Does that even work? It returns true if killer and victim is a player, does it ever get to +1 kill unless your killing a monster?

Edit:

Add to end of:
forgottenserver/position.lua at master · otland/forgottenserver · GitHub

Lua:
function Position:isInRadius(northWest, southEast)
    if  self.x >= northWest.x and self.x <= southEast.x
    and self.y >= northWest.y and self.y <= southEast.y
    and self.z >= northWest.z and self.z <= southEast.z then
        return true
    end
    return false
end

Then in creaturescripts etc you can use:
Lua:
local zone = {
    northWest = Position(20, 20, 6),
    southEast = Position(40, 40, 8)
}
local creaturePos = creature:getPosition()
local targetPos = target:getPosition()

if creaturePos:isInRadius(zone.northWest, zone.southEast)
and targetPos:isInRadius(zone.northWest, zone.southEast) then
    creature:say("+1 Kill", TALKTYPE_ORANGE_1)
    creature:setStorageValue(167912, math.max(0, creature:getStorageValue(167912)) + 1)
end
 
Last edited:
Does that even work? It returns true if killer and victim is a player, does it ever get to +1 kill unless your killing a monster?

Edit:

Add to end of:
forgottenserver/position.lua at master · otland/forgottenserver · GitHub

Lua:
function Position:isInRadius(northWest, southEast)
    if  self.x >= northWest.x and self.x <= southEast.x
    and self.y >= northWest.y and self.y <= southEast.y
    and self.z >= northWest.z and self.z <= southEast.z then
        return true
    end
    return false
end

Then in creaturescripts etc you can use:
Lua:
local zone = {
    northWest = Position(20, 20, 6),
    southEast = Position(40, 40, 8)
}
local creaturePos = creature:getPosition()
local targetPos = target:getPosition()

if creaturePos:isInRadius(zone.northWest, zone.southEast)
and targetPos:isInRadius(zone.northWest, zone.southEast) then
    creature:say("+1 Kill", TALKTYPE_ORANGE_1)
    creature:setStorageValue(167912, math.max(0, creature:getStorageValue(167912)) + 1)
end


This above script works, I wish it did not work if the player is on tile PvPzone
 
Lua:
function onKill(creature, target)
    if creature:isPlayer() and target:isPlayer() and not Tile(creature:getPosition()):hasFlag(TILESTATE_PVPZONE) then   
        creature:say("+1 Kill", TALKTYPE_ORANGE_1)
        creature:setStorageValue(167912, math.max(0, creature:getStorageValue(167912)) + 1)
    end
    return true
end
function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    if not Tile(creature:getPosition()):hasFlag(TILESTATE_PVPZONE) then
        creature:say("+1 Death", TALKTYPE_ORANGE_1)
        creature:setStorageValue(167913, math.max(0, creature:getStorageValue(167913)) + 1)
    end
    return true
end
 
Solution
Back
Top