• Vote in September Mapping Competition to select a winner!
  • 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
10
Best answers
0
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"/>
 

Rombadr

Premium User
Premium User
Joined
Jan 19, 2020
Messages
201
Best answers
23
Reaction score
128
Do you have your script registered in login.lua?
Lua:
player:registerEvent("FragReward")
 

Demnish

Tibian Hero
Joined
Sep 28, 2011
Messages
387
Best answers
2
Reaction score
53
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:
Top