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

reward for killing within the area

pisquila

New Member
Joined
Nov 14, 2023
Messages
28
Reaction score
3
When killing the player in a certain area, gain an item.
but it cannot be from the same IP or the same guide.


item: 6527
quantity: 10
 

Attachments

Solution
If you're using TFS 0.4, you can achieve this using creaturescripts. I haven’t worked with 0.4 in a while, but this should work. If it doesn’t, give me a shout..
LUA:
function onKill(cid, target)
    if not isPlayer(cid) or not isPlayer(target) then
        return true
    end

    local fromPos = {x = 4260, y = 5719, z = 6}
    local toPos = {x = 4263, y = 5722, z = 6}

    local killerPos = getCreaturePosition(cid)
    local victimPos = getCreaturePosition(target)

    if killerPos.z == fromPos.z and victimPos.z == fromPos.z
        and killerPos.x >= fromPos.x and killerPos.x <= toPos.x
        and killerPos.y >= fromPos.y and killerPos.y <= toPos.y
        and victimPos.x >= fromPos.x and victimPos.x <= toPos.x
        and...
If you're using TFS 0.4, you can achieve this using creaturescripts. I haven’t worked with 0.4 in a while, but this should work. If it doesn’t, give me a shout..
LUA:
function onKill(cid, target)
    if not isPlayer(cid) or not isPlayer(target) then
        return true
    end

    local fromPos = {x = 4260, y = 5719, z = 6}
    local toPos = {x = 4263, y = 5722, z = 6}

    local killerPos = getCreaturePosition(cid)
    local victimPos = getCreaturePosition(target)

    if killerPos.z == fromPos.z and victimPos.z == fromPos.z
        and killerPos.x >= fromPos.x and killerPos.x <= toPos.x
        and killerPos.y >= fromPos.y and killerPos.y <= toPos.y
        and victimPos.x >= fromPos.x and victimPos.x <= toPos.x
        and victimPos.y >= fromPos.y and victimPos.y <= toPos.y then

        local killerIP = getPlayerIp(cid)
        local victimIP = getPlayerIp(target)
        if killerIP == victimIP then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You cannot gain rewards for killing a player with the same IP.")
            return true
        end

        local itemId = 6527
        local quantity = 10
        if doPlayerAddItem(cid, itemId, quantity) then
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You received " .. quantity .. " of item ID " .. itemId .. " for killing a player in the designated area!")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Could not add item. Check your inventory space.")
        end
    end

    return true
end
XML Registration:
Add this to your creaturescripts.xml:
XML:
<event type="kill" name="PvpReward" event="script" value="pvp_reward.lua"/>
Register the Event In your login.lua, register the creature event like this:
LUA:
registerCreatureEvent(cid, "PvpReward")
 
Solution
If you're using TFS 0.4, you can achieve this using creaturescripts. I haven’t worked with 0.4 in a while, but this should work. If it doesn’t, give me a shout..
LUA:
function onKill(cid, target)
    if not isPlayer(cid) or not isPlayer(target) then
        return true
    end

    local fromPos = {x = 4260, y = 5719, z = 6}
    local toPos = {x = 4263, y = 5722, z = 6}

    local killerPos = getCreaturePosition(cid)
    local victimPos = getCreaturePosition(target)

    if killerPos.z == fromPos.z and victimPos.z == fromPos.z
        and killerPos.x >= fromPos.x and killerPos.x <= toPos.x
        and killerPos.y >= fromPos.y and killerPos.y <= toPos.y
        and victimPos.x >= fromPos.x and victimPos.x <= toPos.x
        and victimPos.y >= fromPos.y and victimPos.y <= toPos.y then

        local killerIP = getPlayerIp(cid)
        local victimIP = getPlayerIp(target)
        if killerIP == victimIP then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You cannot gain rewards for killing a player with the same IP.")
            return true
        end

        local itemId = 6527
        local quantity = 10
        if doPlayerAddItem(cid, itemId, quantity) then
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You received " .. quantity .. " of item ID " .. itemId .. " for killing a player in the designated area!")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Could not add item. Check your inventory space.")
        end
    end

    return true
end
XML Registration:
Add this to your creaturescripts.xml:
XML:
<event type="kill" name="PvpReward" event="script" value="pvp_reward.lua"/>
Register the Event In your login.lua, register the creature event like this:
LUA:
registerCreatureEvent(cid, "PvpReward")
It's working. But it's not right. When killing the player, he gets the item, but the message appears Could not add item. Check your inventory space, even though there is space in the bp
 
It's working. But it's not right. When killing the player, he gets the item, but the message appears Could not add item. Check your inventory space, even though there is space in the bp
Try this lmk what gonna happen
LUA:
function onKill(cid, target)
    if not isPlayer(cid) or not isPlayer(target) then
        return true
    end

    local fromPos = {x = 4260, y = 5719, z = 6}
    local toPos = {x = 4263, y = 5722, z = 6}

    local killerPos = getCreaturePosition(cid)
    local victimPos = getCreaturePosition(target)

    if killerPos.z == fromPos.z and victimPos.z == fromPos.z
        and killerPos.x >= fromPos.x and killerPos.x <= toPos.x
        and killerPos.y >= fromPos.y and killerPos.y <= toPos.y
        and victimPos.x >= fromPos.x and victimPos.x <= toPos.x
        and victimPos.y >= fromPos.y and victimPos.y <= toPos.y then

        local killerIP = getPlayerIp(cid)
        local victimIP = getPlayerIp(target)
        if killerIP == victimIP then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You cannot gain rewards for killing a player with the same IP.")
            return true
        end

        local itemId = 6527
        local quantity = 10
        doPlayerAddItem(cid, itemId, quantity)
        local itemCount = getPlayerItemCount(cid, itemId)
        if itemCount >= quantity then
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You received " .. quantity .. " of item ID " .. itemId .. " for killing a player in the designated area!")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Could not add item. Check your inventory space.")
        end
    end

    return true
end
 
if its something like an event, add storage / table (when player start to participate the event) with playerId so u can check if player participating event, instead of scan every kill xx tiles
 
Try this lmk what gonna happen
LUA:
function onKill(cid, target)
    if not isPlayer(cid) or not isPlayer(target) then
        return true
    end

    local fromPos = {x = 4260, y = 5719, z = 6}
    local toPos = {x = 4263, y = 5722, z = 6}

    local killerPos = getCreaturePosition(cid)
    local victimPos = getCreaturePosition(target)

    if killerPos.z == fromPos.z and victimPos.z == fromPos.z
        and killerPos.x >= fromPos.x and killerPos.x <= toPos.x
        and killerPos.y >= fromPos.y and killerPos.y <= toPos.y
        and victimPos.x >= fromPos.x and victimPos.x <= toPos.x
        and victimPos.y >= fromPos.y and victimPos.y <= toPos.y then

        local killerIP = getPlayerIp(cid)
        local victimIP = getPlayerIp(target)
        if killerIP == victimIP then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You cannot gain rewards for killing a player with the same IP.")
            return true
        end

        local itemId = 6527
        local quantity = 10
        doPlayerAddItem(cid, itemId, quantity)
        local itemCount = getPlayerItemCount(cid, itemId)
        if itemCount >= quantity then
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You received " .. quantity .. " of item ID " .. itemId .. " for killing a player in the designated area!")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Could not add item. Check your inventory space.")
        end
    end

    return true
end



continue with the same "error". It would be possible to put it so that if the player does not have space, the item goes to deport. or even remove this thing about not having space, and the player receives the item normally without this "error".
 
to make your system work properly, use onDeath. With onDeath, you can add the reward directly to the corpse and have more control over when the script is triggered after a player dies
LUA:
local fromPos = {x = 4260, y = 5719, z = 6}
local toPos = {x = 4263, y = 5722, z = 6}
  local function isInArena(pos)
        return pos.x >= fromPos.x and pos.x <= toPos.x
           and pos.y >= fromPos.y and pos.y <= toPos.y
           and pos.z == fromPos.z
    end

function onDeath(cid, corpse, deathList)
    if not isPlayer(cid) then
       return true
     end

    if not isInArena(getCreaturePosition(cid)) then
    return true
   end

    local killer = deathList and deathList[1]
    if not killer or not isPlayer(killer) then
       return true
     end

   if getPlayerIp(killer) == getPlayerIp(cid) then
        doPlayerSendTextMessage(killer, MESSAGE_STATUS_CONSOLE_RED, "You cannot gain rewards for killing a player with the same IP.")
        return true
    end

    local itemId = 6527
    local quantity = 10
    local playerName = getPlayerName(killer)
    local success = false

    local backpack = getPlayerSlotItem(killer, CONST_SLOT_BACKPACK)
    if backpack and backpack.uid > 0 and isContainer(backpack.uid) and getContainerSlotsFree(backpack.uid) > 0 then
        local added = doAddContainerItem(backpack.uid, itemId, quantity)
        if added and added > 0 then
            doPlayerSendTextMessage(killer, MESSAGE_EVENT_ADVANCE, "You received " .. quantity .. " of item ID " .. itemId .. " in your backpack!")
            success = true
        end
    end
    if not success then
        local parcel = doCreateItemEx(2595, 1)
        if parcel then
                doAddContainerItem(parcel, itemId, quantity)
                doPlayerSendMailByName(playerName, parcel, getTownId(killer))
                doPlayerSendTextMessage(killer, MESSAGE_EVENT_ADVANCE, "Your backpack was full. The reward was sent to your depot.")
        else
            doPlayerSendTextMessage(killer, MESSAGE_STATUS_CONSOLE_RED, "Failed to create parcel.")
        end
    end

    return true
end
don't forget to add in creaturescripts.xml
Code:
<event type="death" name="PvpReward" event="script" value="pvp_reward.lua"/>
and in login.lua
Code:
registerCreatureEvent(cid, "PvpReward")
 
Last edited:
to make your system work properly, use onDeath. With onDeath, you can add the reward directly to the corpse and have more control over when the script is triggered after a player dies
LUA:
  local function isInArena(pos)
        return pos.x >= fromPos.x and pos.x <= toPos.x
           and pos.y >= fromPos.y and pos.y <= toPos.y
           and pos.z == fromPos.z
    end

function onDeath(cid, corpse, deathList)
    if not isPlayer(cid) then
       return true
     end

    local fromPos = {x = 4260, y = 5719, z = 6}
    local toPos = {x = 4263, y = 5722, z = 6}

    if not isInArena(getCreaturePosition(cid)) then
    return true
   end

    local killer = deathList and deathList[1]
    if not killer or not isPlayer(killer) then
       return true
     end

   if getPlayerIp(killer) == getPlayerIp(cid) then
        doPlayerSendTextMessage(killer, MESSAGE_STATUS_CONSOLE_RED, "You cannot gain rewards for killing a player with the same IP.")
        return true
    end

    local itemId = 6527
    local quantity = 10
    local playerName = getPlayerName(killer)
    local success = false

    local backpack = getPlayerSlotItem(killer, CONST_SLOT_BACKPACK)
    if backpack and backpack.uid > 0 and isContainer(backpack.uid) and getContainerSlotsFree(backpack.uid) > 0 then
        local added = doAddContainerItem(backpack.uid, itemId, quantity)
        if added and added > 0 then
            doPlayerSendTextMessage(killer, MESSAGE_EVENT_ADVANCE, "You received " .. quantity .. " of item ID " .. itemId .. " in your backpack!")
            success = true
        end
    end
    if not success then
        local parcel = doCreateItemEx(2595, 1)
        if parcel then
                doAddContainerItem(parcel, itemId, quantity)
                doPlayerSendMailByName(playerName, parcel, getTownId(killer))
                doPlayerSendTextMessage(killer, MESSAGE_EVENT_ADVANCE, "Your backpack was full. The reward was sent to your depot.")
        else
            doPlayerSendTextMessage(killer, MESSAGE_STATUS_CONSOLE_RED, "Failed to create parcel.")
        end
    end

    return true
end
don't forget to add in creaturescripts.xml
Code:
<event type="death" name="PvpReward" event="script" value="pvp_reward.lua"/>
and in login.lua
Code:
registerCreatureEvent(cid, "PvpReward")


without any error in the console, but the player is not receiving the item when killing him
 
yes, it was in the arena and without the same IP. the player does not receive the item. One question, are you doing it for tfs 0.4?
yes its for 0.4 and must work good u tested it after i edited?
if you don't have function getContainerSlotsFree
LUA:
function getContainerSlotsFree(container)
         return getContainerCap(container)-getContainerSize(container)
end
 
sim, é para 0.4 e deve funcionar bem. Você testou depois que eu editei?
se você não tiver a função getContainerSlotsFree
LUA:
função getContainerSlotsFree(container)
         retornar getContainerCap(container)-getContainerSize(container)
fim[/CÓDIGO]
[/QUOTE]


Não funcionou...   
Você conseguiria fazer isso funcionar, só para matar o outro jogador e pegar o item, e eles não podem ser do mesmo IP?   

Você não precisa adicionar essa função se o jogador não tiver espaço no BP.



[QUOTE]

[/QUOTE]


It didn't work...
Would you be able to make this one work, just to kill the other player and get the item, and they can't be from the same IP?

You don't need to add this function if the player doesn't have space in the bp.



function onKill(cid, target)
if not isPlayer(cid) or not isPlayer(target) then
return true
end

local fromPos = {x = 4260, y = 5719, z = 6}
local toPos = {x = 4263, y = 5722, z = 6}

local killerPos = getCreaturePosition(cid)
local victimPos = getCreaturePosition(target)

if killerPos.z == fromPos.z and victimPos.z == fromPos.z
and killerPos.x >= fromPos.x and killerPos.x <= toPos.x
and killerPos.y >= fromPos.y and killerPos.y <= toPos.y
and victimPos.x >= fromPos.x and victimPos.x <= toPos.x
and victimPos.y >= fromPos.y and victimPos.y <= toPos.y then

local killerIP = getPlayerIp(cid)
local victimIP = getPlayerIp(target)
if killerIP == victimIP then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You cannot gain rewards for killing a player with the same IP.")
return true
end

local itemId = 6527
local quantity = 10
if doPlayerAddItem(cid, itemId, quantity) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You received " .. quantity .. " of item ID " .. itemId .. " for killing a player in the designated area!")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Could not add item. Check your inventory space.")
end
end

return true
end
 
i don't know what you need but if you need it onkill

LUA:
local fromPos = {x = 4260, y = 5719, z = 6}
local toPos = {x = 4263, y = 5722, z = 6}

local function isInArena(pos)
    return pos.x >= fromPos.x and pos.x <= toPos.x
       and pos.y >= fromPos.y and pos.y <= toPos.y
       and pos.z == fromPos.z
end

local function getContainerSlotsFree(container)
    return getContainerCap(container) - getContainerSize(container)
end

function onKill(cid, target)
    if not isPlayer(cid) or not isPlayer(target) then
        return true
    end

    if not isInArena(getCreaturePosition(target)) then
        return true
    end

    if getPlayerIp(cid) == getPlayerIp(target) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You cannot gain rewards for killing a player with the same IP.")
        return true
    end

    local itemId = 6527
    local quantity = 10
    local playerName = getPlayerName(cid)
    local success = false

    local backpack = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
    if backpack and backpack.uid > 0 and isContainer(backpack.uid) and getContainerSlotsFree(backpack.uid) > 0 then
        local added = doAddContainerItem(backpack.uid, itemId, quantity)
        if added and added > 0 then
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You received " .. quantity .. " of item ID " .. itemId .. " in your backpack!")
            success = true
        end
    end

    if not success then
        local parcel = doCreateItemEx(2595, 1)
        if parcel then
            doAddContainerItem(parcel, itemId, quantity)
            doPlayerSendMailByName(playerName, parcel, getTownId(cid))
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Your backpack was full. The reward was sent to your depot.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Failed to create parcel.")
        end
    end

    return true
end
 
have you even set the positions?


yes!
the player does not receive the item!
Post automatically merged:

i don't know what you need but if you need it onkill

LUA:
local fromPos = {x = 4260, y = 5719, z = 6}
local toPos = {x = 4263, y = 5722, z = 6}

local function isInArena(pos)
    return pos.x >= fromPos.x and pos.x <= toPos.x
       and pos.y >= fromPos.y and pos.y <= toPos.y
       and pos.z == fromPos.z
end

local function getContainerSlotsFree(container)
    return getContainerCap(container) - getContainerSize(container)
end

function onKill(cid, target)
    if not isPlayer(cid) or not isPlayer(target) then
        return true
    end

    if not isInArena(getCreaturePosition(target)) then
        return true
    end

    if getPlayerIp(cid) == getPlayerIp(target) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You cannot gain rewards for killing a player with the same IP.")
        return true
    end

    local itemId = 6527
    local quantity = 10
    local playerName = getPlayerName(cid)
    local success = false

    local backpack = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
    if backpack and backpack.uid > 0 and isContainer(backpack.uid) and getContainerSlotsFree(backpack.uid) > 0 then
        local added = doAddContainerItem(backpack.uid, itemId, quantity)
        if added and added > 0 then
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You received " .. quantity .. " of item ID " .. itemId .. " in your backpack!")
            success = true
        end
    end

    if not success then
        local parcel = doCreateItemEx(2595, 1)
        if parcel then
            doAddContainerItem(parcel, itemId, quantity)
            doPlayerSendMailByName(playerName, parcel, getTownId(cid))
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Your backpack was full. The reward was sent to your depot.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Failed to create parcel.")
        end
    end

    return true
end


the player is not receiving the item.
Post automatically merged:

This one is giving the prize, but I wanted to remove this neologic of not having space does not receive the prize. Could you remove this function?


function onKill(cid, target)
if not isPlayer(cid) or not isPlayer(target) then
return true
end

local fromPos = {x = 3904, y = 314, z = 7}
local toPos = {x = 3994, y = 374, z = 7}

local killerPos = getCreaturePosition(cid)
local victimPos = getCreaturePosition(target)

if killerPos.z == fromPos.z and victimPos.z == fromPos.z
and killerPos.x >= fromPos.x and killerPos.x <= toPos.x
and killerPos.y >= fromPos.y and killerPos.y <= toPos.y
and victimPos.x >= fromPos.x and victimPos.x <= toPos.x
and victimPos.y >= fromPos.y and victimPos.y <= toPos.y then

local killerIP = getPlayerIp(cid)
local victimIP = getPlayerIp(target)
if killerIP == victimIP then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You cannot gain rewards for killing a player with the same IP.")
return true
end

local itemId = 6527
local quantity = 10
if doPlayerAddItem(cid, itemId, quantity) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You received " .. quantity .. " of item ID " .. itemId .. " for killing a player in the designated area!")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Could not add item. Check your inventory space.")
end
end

return true
end
 
yes!
the player does not receive the item!
Post automatically merged:




the player is not receiving the item.
Post automatically merged:

This one is giving the prize, but I wanted to remove this neologic of not having space does not receive the prize. Could you remove this function?
LUA:
local fromPos = {x = 4260, y = 5719, z = 6}
local toPos = {x = 4263, y = 5722, z = 6}

local function isInArena(pos)
    return pos.x >= fromPos.x and pos.x <= toPos.x
       and pos.y >= fromPos.y and pos.y <= toPos.y
       and pos.z == fromPos.z
end

function onKill(cid, target)
    if isPlayer(cid) and isPlayer(target) and isInArena(getCreaturePosition(target)) then
        doPlayerAddItem(cid, 6527, 10)
    end
    return true
end
test

Edit----- for mc rewards
Add this
LUA:
if getPlayerIp(cid) ~= getPlayerIp(target) then
before
LUA:
doPlayerAddItem(cid, 6527, 10)/CODE]
 
Last edited:
Back
Top