# TFS 1.X+onKill

#### theduck

##### Member
Lua:
``````function onKill(creature, target)
local player = Player(creature)
local frags = player:getStorageValue(356086)

if target:isPlayer() then
player:setStorageValue(356086, player:getStorageValue(356086) + 1)

if(frags >= 5) then
print(test)
elseif(frags >= 51) then
print(test)
elseif(frags >= 131) then
print(test)
elseif(frags >= 151) then
print(test)
elseif(frags >= 201) then
print(test)
elseif(frags >= 301) then
print(test)
elseif(frags >= 351) then
print(test)
elseif(frags > 751) then
print(test)
end
end
return true
end``````

I am trying to make sure that every time the player kills someone he gets storage and if the number of frags (storage)
is greater do X do something if it is less than y do something else is not working

Solution
Start checking the highest amount of frags first, otherwise the if statement will fall into the first matching block. For example, if you have 120 frags, it will still only fall into the 5 frags block, because it's the first one that matches.

Lua:
``````local storageKey = 356086

function onKill(creature, target)
local player = Player(creature)

if target:isPlayer() then
local frags = math.max(0, player:getStorageValue(storageKey)) + 1
player:setStorageValue(storageKey, frags)

if frags > 751 then
someFunction()
elseif frags >= 351 then
someOtherFunction()
elseif frags >= 301 then
yetAnotherFunction()
end
end

return true
end``````

#### Alpha

##### Relentless
Start checking the highest amount of frags first, otherwise the if statement will fall into the first matching block. For example, if you have 120 frags, it will still only fall into the 5 frags block, because it's the first one that matches.

Lua:
``````local storageKey = 356086

function onKill(creature, target)
local player = Player(creature)

if target:isPlayer() then
local frags = math.max(0, player:getStorageValue(storageKey)) + 1
player:setStorageValue(storageKey, frags)

if frags > 751 then
someFunction()
elseif frags >= 351 then
someOtherFunction()
elseif frags >= 301 then
yetAnotherFunction()
end
end

return true
end``````

Replies
3
Views
195
Replies
17
Views
444
Replies
0
Views
79
Replies
6
Views
268
Replies
6
Views
241
Replies
3
Views
170
Replies
15
Views
414
Replies
3
Views
123
Replies
5
Views
230
Replies
0
Views
56