-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathglobalstep.lua
153 lines (133 loc) · 4.85 KB
/
globalstep.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
--[[
Region Areas and Zones
an areas (or region or zone) mod that allows player (depending on privilegs)
- to mark your (region / areas / zones) with name
- to protect (region / areas / zones)
- to invite / ban other players to interact in protected (region / areas / zones)
- to allow / disallow PvP in (region / areas / zones)
- to allow / disable Mobdamage [MvP] in (region / areas / zones)
- to set (region / areas / zones) with an effect like hot, dot, holy, evil
an (region / areas / zones) mod that allows the region_admin (privileg)
- to create an named city (maybe portected)
- set some building plots for the playes, so player can protect ther own (region / areas / zones) in the city
Copyright (c) 2019
ralf Weinert <[email protected]>
Source Code:
https://github.com/downad/raz
License:
GPLv3
]]--
--+++++++++++++++++++++++++++++++++++++++
--
-- Globalstep: create info for the hud
--
--+++++++++++++++++++++++++++++++++++++++
-- loop all connected player
-- find the region of the players position -> get_areas_for_pos
-- create a string with region-name and owner an show it in the hud
-- if there is an effect in the area - do it to the player
local timer = 0
minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local pos = vector.round(player:getpos())
--color for PvP and protected
local color = raz.color["white"] -- default
local protected = false -- true: then color yellow
local PvP = false -- true: then color red
-- both: then purple
-- all pos without any region are wilderness
local hud_stringtext = ""
if raz.pvp_only_in_pvp_regions then
hud_stringtext = raz.default.hud_stringtext --"wilderness"
elseif raz.enable_pvp then
hud_stringtext = raz.default.hud_stringtext_pvp --"wilderness (PvP)"
PvP = true
end
-- attributes are: region_name, owner, protected, guests, PvP, MvP, effect
local region_values = ""
local protected_string = ""
local PvP_string = ""
local effect = ""
local is_effect = false
local effects = {}
timer = timer + dtime
local pos_has_regions = false
-- loop als regions
for region_id, v in pairs(raz.raz_store:get_areas_for_pos(pos)) do
if region_id then
if pos_has_regions == false then
pos_has_regions = true
hud_stringtext = ""
end
-- get region_data as table
local data_table = raz:get_region_datatable(region_id)
-- region_name
local region_name = data_table.region_name
-- owner
local owner = data_table.owner
-- is this region protected?
if data_table.protected then
protected = true
protected_string = " (protected) "
else
protected_string = ""
end
-- PvP - is pvp_only_in_pvp_regions = true
-- then PvP is only allowed in PvP-zones.
-- is PvP allowed in one area at this position PvP is allowed in all.
-- mark this zone as PvP
if data_table.PvP == true and raz.pvp_only_in_pvp_regions == true then
PvP = true
PvP_string = " (PvP) "
end
if data_table.PvP == false and raz.pvp_only_in_pvp_regions == true then
PvP_string = ""
end
-- PvP - is pvp_only_in_pvp_regions = false
-- then PvP is allowed everythere.
-- is PvP = fales in one area at this Position PvP is forbidden in all.
-- mark this zone as PvP
if data_table.PvP == true and raz.pvp_only_in_pvp_regions == false then
PvP_string = " (PvP) "
end
if data_table.PvP == false and raz.pvp_only_in_pvp_regions == false then
PvP = false
PvP_string = ""
end
-- has the region an effect
effect = data_table.effect
if effect ~= "none" and effect ~=nil then
--minetest.log("action", "[" .. raz.modname .. "] player in effect-zone ".. tostring(effect))
is_effect = true
table.insert(effects, effect)
end
local string = "\nZone ("..region_id.."): >"..region_name.."< owned by "..owner.."! "..protected_string..PvP_string
hud_stringtext = hud_stringtext..string
end
end
-- update the hud
if protected == true then
color = raz.color["yellow"]
--minetest.log("action", "[" .. raz.modname .. "] protected == true ".. tostring(color))
end
if PvP == true then
color = raz.color["red"]
--minetest.log("action", "[" .. raz.modname .. "] PvP == true ".. tostring(color))
end
if protected == true and PvP == true then
color = raz.color["purple"]
--minetest.log("action", "[" .. raz.modname .. "] PVP and protected == true ".. tostring(color))
end
if is_effect == true then
color = raz.color["orange"]
--minetest.log("action", "[" .. raz.modname .. "] effect == true ".. tostring(color))
end
raz:update_hud(player,hud_stringtext, color)
-- do region effect
if is_effect == true and timer >= raz.effect.time then
raz:do_effect_to_player(player,effects)
timer = 0
end
end
end)