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

10 kills and a reward

Phemus

Member
Joined
Jun 16, 2012
Messages
149
Solutions
2
Reaction score
12
I'm working on a war server and I'm trying to make a script where someone kills 10 players and he receives a reward like a soul orb. If the player gets killed before reaching to 10 kills, he would need to start again. The problem is that i don't know how to start the script. I hope that can someone can help and create the script for me. I hope you understand.

Thank you.
 
Wich distro do you use?

tfs 1.0 (not tested)
PHP:
function onKill(cid, target)
    local playerTarget = Player(target)
    if playerTarget then
        local player = Player(cid)
        player:setStorageValue(10001, player:getStorageValue(10001) + 1)
        if player:getStorageValue(10001) >= 10 then
            player:setStorageValue(10001, 0)
            player:addItem("soul orb")
        end
    end
    return true
end

function onLogin(cid)
    local player = Player(cid)
    player:setStorageValue(10001, 0)
    player:registerEvent('pvp-kill')
    return true
end
 
You can just change the metatables to TFS 0.2/0.3 functions.
Remove local playerTarget = Player(target) and local player = Player(cid), then change everything that starts with player: to TFS 0.2/0.3 functions.
Example
Code:
player:setStorageValue(10001, 0)
To
Code:
setPlayerStorageValue(cid, 10001, 0)

~~~~

Code:
if player:getStorageValue(10001) >= 10 then
To
Code:
if getPlayerStorageValue(cid, 10001) >= 10 then

Etc

~~~~

And this
Code:
if playerTarget then
To
Code:
if isPlayer(target) then
 
Last edited:
I don't think it works, it doesn't give me the item at the 6th kill. Do i have to add the line registerCreatureEvent(cid, "pvp-kill") in login.lua? Also, this is the script when i changed it to TFS 0.2/0.3

PHP:
function onKill(cid, target)
    if isPlayer(target) then
        local player = Player(cid)
        setPlayerStorageValue(cid, 10001, getPlayerStorageValue(cid, 10001) + 1)
        if getPlayerStorageValue(cid, 10001) >= 6 then
            setPlayerStorageValue(cid, 10001, 0)
            doPlayerAddItem(cid, 5944, 1)
        end
    end
    return true
end

function onLogin(cid)
    local player = Player(cid)
    setPlayerStorageValue(cid, 10001, 0)
    player:registerEvent('pvp-kill')
    return true
end

where it says, "player:registerEvent('pvp-kill')" and "local player = Player(cid)" are those functions for 0.2/0.3? If not how do i change it?
 
Remove
Code:
local player = Player(cid)
This is for TFS 1.0.
Also change player:registerEvent to registerCreatureEvent like you posted.
You can register it in any login script btw, in this one or in login.lua.
 
Okay, I already did that. But, still it doesn't give me the reward. I changed to 3 kills, but nothing happens.
This is the script:
PHP:
function onKill(cid, target)
    if isPlayer(target) then
        setPlayerStorageValue(cid, 10001, getPlayerStorageValue(cid, 10001) + 1)
        if getPlayerStorageValue(cid, 10001) >= 3 then
            setPlayerStorageValue(cid, 10001, 0)
            doPlayerAddItem(cid, 5944, 1)
        end
    end
    return true
end

function onLogin(cid)
    setPlayerStorageValue(cid, 10001, 0)
    registerCreatureEvent('pvp-kill')
    return true
end
 
How did you added the kill script and which server do you use?

You can add this btw also in login.lua
Code:
setPlayerStorageValue(cid, 10001, 0)
registerCreatureEvent('pvp-kill')

Or if the storage should only reset after death and not relog, then add setPlayerStorageValue(cid, 10001, 0) to a death or preparedeath script.
 
What do you mean? I added it to creaturescripts and then in creaturescripts.xml I added this:
PHP:
<event type="kill" name="pvp-kill" event="script" value="soulorb.lua"/>
I'm using TFS 0.4
 
If it should only reset after death, you can add
Code:
setPlayerStorageValue(cid, 10001, 0)
In a script that is registered in login.lua with function onDeath or function onPrepareDeath (you can just add it under the function).
Then register the kill script in login.lua.
You can add prints or textmessages to the kill script to see if it's loading.
 
Back
Top