• 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 [TFS 1.3][HELP] - Frag Reward

dredwan

New Member
Joined
Feb 9, 2013
Messages
20
Reaction score
2
I want to make a Server War with the classic script for war: "reward for killing players", but in my sever console, there's not error and the gameserver there's not rewardfrag...
How to fix it?

Code:
function onKill(cid, target, lastHit)

    local attackPlayer = Player(target)

    local reward = {
            item = 2152,
            count = 2
            }

    if not attackPlayer then
        return true
    end

    for id, damage in pairs(attackPlayer:getDamageMap()) do
        local player = Player(id)
        if player then
            if player:getIp() ~= target:getIp() then
                local experience = attackPlayer:getExperience()
                local expFormula = (experience * expMultiplier)
                local bonusExpFormula = (experience * bonusExpMultiplier)
                player:addExperience(math.floor(expFormula), true)
                player:addItem(item, count)
            end
        end
    end
end



<event type="kill" name="FragReward" script="fragreward.lua"/>
 
Here is my pvpreward.lua, I added some comments to make it easier to understand.
Add it into creaturescripts or copy stuff from it to your own:
Lua:
-- Reward and amount
local config = {
    itemDrop = ITEM_PLATINUM_COIN,
    itemAmount = 1
}

function onDeath(player, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    -- Let's make sure non-viable players can't generate a reward
    if getPlayerFlagValue(player, PlayerFlag_NotGenerateLoot) or player:getVocation():getId() == VOCATION_NONE then
        return false
    end

    local master = killer:getMaster()
    -- If the killer is a player the killer should get rewarded (duh?)
    if killer:isPlayer() then
        killer:addItem(config.itemDrop, config.itemAmount)
        return true
    -- When a player's summon kills another player the summoner should get rewarded (master = summoner, we defined it above)
    elseif killer:isMonster() and master:isPlayer() then
        master:addItem(config.itemDrop, config.itemAmount)
        return true
    end
    -- If none of these are met, there will be no reward
    return false
end
creaturescripts.xml:
Lua:
<event type="death" name="PVP Reward" script="pvpreward.lua" />

In login.lua at the bottom:
Lua:
player:registerEvent("PVP Reward")

Now you should probably review the code before using it live.
Because it may or may not work differently when several players are involved.

There is after all a function in onDeath that is called mostDamage.
I have a feeling that should be used, but I can't test it right now.

If not, then several players might get the reward, which can turn into an abusive nightmare if they use their imagination.
 
Last edited:
can someone convert this to revscript?
Here is my pvpreward.lua, I added some comments to make it easier to understand.
Add it into creaturescripts or copy stuff from it to your own:
Lua:
-- Reward and amount
local config = {
    itemDrop = ITEM_PLATINUM_COIN,
    itemAmount = 1
}

function onDeath(player, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    -- Let's make sure non-viable players can't generate a reward
    if getPlayerFlagValue(player, PlayerFlag_NotGenerateLoot) or player:getVocation():getId() == VOCATION_NONE then
        return false
    end

    local master = killer:getMaster()
    -- If the killer is a player the killer should get rewarded (duh?)
    if killer:isPlayer() then
        killer:addItem(config.itemDrop, config.itemAmount)
        return true
    -- When a player's summon kills another player the summoner should get rewarded (master = summoner, we defined it above)
    elseif killer:isMonster() and master:isPlayer() then
        master:addItem(config.itemDrop, config.itemAmount)
        return true
    end
    -- If none of these are met, there will be no reward
    return false
end
creaturescripts.xml:
Lua:
<event type="death" name="PVP Reward" script="pvpreward.lua" />

In login.lua at the bottom:
Lua:
player:registerEvent("PVP Reward")

Now you should probably review the code before using it live.
Because it may or may not work differently when several players are involved.

There is after all a function in onDeath that is called mostDamage.
I have a feeling that should be used, but I can't test it right now.

If not, then several players might get the reward, which can turn into an abusive nightmare if they use their imagination.
Not working in tfs 1.5 can somebody convert it, please? thank
 
have converted to revscript but is not working
Lua:
local creatureevent = CreatureEvent("kill_rewards")

local config = {
    itemDrop = ITEM_PLATINUM_COIN,
    itemAmount = 2
}
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    -- Let's make sure non-viable players can't generate a reward
    if getPlayerFlagValue(player, PlayerFlag_NotGenerateLoot) or player:getVocation():getId() == VOCATION_NONE then
        return false
    end

    local master = killer:getMaster()
    -- If the killer is a player the killer should get rewarded (duh?)
    if killer:isPlayer() then
        killer:addItem(config.itemDrop, config.itemAmount)
        return true
    -- When a player's summon kills another player the summoner should get rewarded (master = summoner, we defined it above)
    elseif killer:isMonster() and master:isPlayer() then
        master:addItem(config.itemDrop, config.itemAmount)
        return true
    end
    -- If none of these are met, there will be no reward
    return false
end

creatureevent:register()

local login = CreatureEvent("kill_rewards")

function login.onLogin(player)
    player:registerEvent("kill_rewards")
    return true
end

login:register()
 
Back
Top