Check player names and assign bounties correctly
This commit is contained in:
20
init.lua
20
init.lua
@@ -2,7 +2,7 @@ bounty = {}
|
|||||||
bounty.file = core.get_worldpath() .. '/bounty.txt'
|
bounty.file = core.get_worldpath() .. '/bounty.txt'
|
||||||
bounty.data = {}
|
bounty.data = {}
|
||||||
bounty.prizes = false --determines if prizes or amount per points game-mechanic is used
|
bounty.prizes = false --determines if prizes or amount per points game-mechanic is used
|
||||||
if false then
|
if true then
|
||||||
bounty.prizes = 'currency:minegeld_100'
|
bounty.prizes = 'currency:minegeld_100'
|
||||||
bounty.points_per_prize = 20 --per 100 points you get a default:steel_ingot
|
bounty.points_per_prize = 20 --per 100 points you get a default:steel_ingot
|
||||||
else
|
else
|
||||||
@@ -140,22 +140,32 @@ bounty.get_player_bounty = function(player_name)
|
|||||||
return prize
|
return prize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
bounty.player_exists = function(player_name)
|
||||||
|
if not minetest.get_player_by_name(player_name) then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--chatcommands for testing purposes
|
--chatcommands for testing purposes
|
||||||
core.register_chatcommand('bounty', {
|
core.register_chatcommand('bounty', {
|
||||||
params = '',
|
|
||||||
description = 'Place bounty on offenders and increasing the bounty by 20',
|
description = 'Place bounty on offenders and increasing the bounty by 20',
|
||||||
privs = { interact = true },
|
privs = { interact = true },
|
||||||
func = function(name, params)
|
func = function(name, params)
|
||||||
bounty.increase(name, 20)
|
if bounty.player_exists(params) then
|
||||||
|
bounty.increase(params, 20)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
core.register_chatcommand('forgive', {
|
core.register_chatcommand('forgive', {
|
||||||
params = '',
|
|
||||||
description = 'Forgive offender and decrease bounty by 20',
|
description = 'Forgive offender and decrease bounty by 20',
|
||||||
privs = { interact = true },
|
privs = { interact = true },
|
||||||
func = function(name, params)
|
func = function(name, params)
|
||||||
bounty.decrease(name, 20)
|
if bounty.player_exists(params) then
|
||||||
|
bounty.decrease(params, 20)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user