• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua [TFS 1.3][HELP] - Frag Reward

dredwan

New Member
Joined
Feb 9, 2013
Messages
19
Reaction score
1
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"/>
 

Demnish

Tibian Hero
Joined
Sep 28, 2011
Messages
390
Solutions
2
Reaction score
59
Location
Sweden
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:

johnsamir

Banned User
Joined
Oct 13, 2009
Messages
555
Solutions
5
Reaction score
98
Location
Nowhere
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
 

johnsamir

Banned User
Joined
Oct 13, 2009
Messages
555
Solutions
5
Reaction score
98
Location
Nowhere
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()
 
Top