• Vote in November 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!

TFS 1.X+ onKill

theduck

Member
Joined
Dec 6, 2018
Messages
245
Reaction score
18
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
Premium User
Joined
Apr 3, 2011
Messages
440
Solutions
21
Reaction score
200
Location
South Korea
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
 
Solution
Top