Add playereffects.has_effect_type

This commit is contained in:
Wuzzy 2016-08-11 18:23:30 +02:00
parent fb04c57da9
commit e1a72e8206
2 changed files with 19 additions and 0 deletions

View File

@ -192,6 +192,13 @@ Returns all active effects of a player.
##### Return value ##### Return value
A table of all `effect`s which belong to the player. If the player does not exist, this function returns an empty table. A table of all `effect`s which belong to the player. If the player does not exist, this function returns an empty table.
#### `playereffects.has_effect_type(playername, effect_type_id)`
Returns `true` iff the provided player has an effect of the specified effect type, `false` otherwise.
##### Parameters
* `playername`: Name of the player to check the existance of the effect type for
* `effect_type_id`: Identifier of the effect type.
## Examples ## Examples
This mod comes with extensive examples. The examples are disabled by default. Edit `settings.lua` to enable the examples. See `examples.lua` to find out how they are programmed. The examples are only for demonstration purposes. They are not intended to be used in an actual game. This mod comes with extensive examples. The examples are disabled by default. Edit `settings.lua` to enable the examples. See `examples.lua` to find out how they are programmed. The examples are only for demonstration purposes. They are not intended to be used in an actual game.
@ -216,3 +223,5 @@ These commands apply (or try to) apply an effect to you. You will get a response
#### Testing #### Testing
* `stresstest [number]`: Applies `number` dummy effects which dont do anything to you. Iff omitted, `number` is assumed to be 100. This command is there to test the performance of this mod for absurdly large effect numbers. * `stresstest [number]`: Applies `number` dummy effects which dont do anything to you. Iff omitted, `number` is assumed to be 100. This command is there to test the performance of this mod for absurdly large effect numbers.

View File

@ -297,6 +297,16 @@ function playereffects.get_player_effects(playername)
end end
end end
function playereffects.has_effect_type(playername, effect_type_id)
local pe = playereffects.get_player_effects(playername)
for i=1,#pe do
if pe[i].effect_type_id == effect_type_id then
return true
end
end
return false
end
--[=[ Saving all data to file ]=] --[=[ Saving all data to file ]=]
function playereffects.save_to_file() function playereffects.save_to_file()
local save_time = os.time() local save_time = os.time()