-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
playerblips: various improvements (#225)
* playerblips: use LF, move main script, modify meta tags * playerblips: cleanup code * playerblips: add optional playercolors integration * playerblips: add blip_range setting * playerblips: fix settings config so they appear in admin panel Due to the changes to the setting names which were necesarry for admin to recognize the settings as public, this commit breaks backwards compatibility. Server admins will need to set their settings again via admin panel. The major version was bumped accordingly. * playerblips: add isElement checks to fix occasional debug errors Other resources (including race) delete blips attached to players, even those created by other resources. * playerblips: include playerblips in freeroam, remove duplicate code * playerblips: update resource authors * playerblips: fix event handlers * playerblips: gravy * playerblips: add missing error check
- Loading branch information
Showing
5 changed files
with
133 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,55 @@ | ||
<meta> | ||
<info author="Noki" type="script" name="playerblips"/> | ||
<script src="playerblips.lua" type="server"/> | ||
<settings> | ||
<setting name="use_team_colors" value="false"/> <!-- Set to true to enable, anything else will not use teams. Default: false --> | ||
<setting name="blip_color" value="[ [ 0, 255, 0 ] ]"/> <!-- Default blip color if se_team_colors is not enabled. Default: [ [ 0, 255, 0 ] ] --> | ||
<setting name="blip_size" value="2"/> <!-- Size of a player blip. Default: 2 --> | ||
<setting name="blip_alpha" value="255"/> <!-- Alpha value of a player blip (0 - 255). Default: 255 --> | ||
</settings> | ||
<oop>true</oop> | ||
</meta> | ||
<meta> | ||
<info name="Player Blips" author="Noki, jlillis" version="2.0.0" type="script" description="Attaches blips to players."/> | ||
<oop>true</oop> | ||
<script src="server/main.lua" type="server"/> | ||
<settings> | ||
<setting | ||
name="*use_team_colors" | ||
value="false" | ||
friendlyname="Use team colors" | ||
group="Color settings" | ||
accept="true,false" | ||
desc="Use team colors for player blips." | ||
/> | ||
<setting | ||
name="*use_nametag_colors" | ||
value="true" | ||
friendlyname="Use nametag colors" | ||
group="Color settings" | ||
accept="true,false" | ||
desc="Use nametag colors for player blips. Takes precedence over team colors." | ||
/> | ||
<setting | ||
name="*blip_color" | ||
value="[[0, 255, 0]]" | ||
friendlyname="Default blip color" | ||
group="Color settings" | ||
accept="" | ||
desc="Default blip color. Used if team and nametag colors are not used." | ||
/> | ||
<setting | ||
name="*blip_size" | ||
value="2" | ||
friendlyname="Blip size" | ||
group="Blip settings" | ||
accept="1-25" | ||
desc="Player blip size." | ||
/> | ||
<setting | ||
name="*blip_alpha" | ||
value="255" | ||
friendlyname="Blip transparency" | ||
group="Blip settings" | ||
accept="0-255" | ||
desc="Player blip transparency." | ||
/> | ||
<setting | ||
name="*blip_range" | ||
value="16383" | ||
friendlyname="Blip visibility range" | ||
group="Blip settings" | ||
accept="0-65535" | ||
desc="Player blip visibility range on the minimap. Blips are always visible on the map." | ||
/> | ||
</settings> | ||
</meta> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
local useTeams = get("*use_team_colors") == "true" | ||
local useNametags = get("*use_nametag_colors") == "true" | ||
local blipSize = get("*blip_size") | ||
local blipAlpha = get("*blip_alpha") | ||
local color = get("*blip_color") | ||
local blipRange = get("*blip_range") | ||
local colors = {} | ||
local blips = {} | ||
|
||
local function resourceStart() | ||
for i, player in ipairs(Element.getAllByType("player")) do | ||
createPlayerBlip(player) | ||
end | ||
|
||
local playercolorsResource = getResourceFromName("playercolors") | ||
if playercolorsResource and getResourceState(playercolorsResource) ~= "running" then | ||
outputDebugString("playerblips: playercolors resource not running; using blip_color. Restart this resource after starting playercolors.", 4, 255, 125, 0) | ||
useNametags = false | ||
end | ||
|
||
if not (useTeams or useNametags) then | ||
addCommandHandler("setblipcolor", setBlipColor) | ||
end | ||
end | ||
addEventHandler("onResourceStart", resourceRoot, resourceStart) | ||
|
||
function createPlayerBlip(player) | ||
if (not player or not isElement(player) or player.type ~= "player") then return false end | ||
local r, g, b | ||
if (useTeams and player.team) then | ||
r, g, b = player.team:getColor() | ||
elseif useNametags then | ||
r, g, b = getPlayerNametagColor(player) | ||
elseif (colors[player]) then | ||
r, g, b = colors[player][1], colors[player][2], colors[player][3] | ||
else | ||
r, g, b = color[1], color[2], color[3] | ||
end | ||
if isElement(blips[player]) then | ||
blips[player]:setColor(r, g, b, blipAlpha) | ||
else | ||
blips[player] = Blip.createAttachedTo(player, 0, blipSize, r, g, b, blipAlpha, 0, blipRange) | ||
end | ||
end | ||
|
||
function setBlipColor(player, _, r, g, b) | ||
r, g, b = tonumber(r), tonumber(g), tonumber(b) | ||
if (r and g and b) then | ||
if (r >= 0 and r <= 255 and g >= 0 and g <= 255 and b >= 0 and b <= 255) then | ||
colors[player] = {r, g, b} | ||
createPlayerBlip(player) | ||
else | ||
outputChatBox("Couldn't change blip color - numbers must be between 0 and 255", player, 255, 0, 0) | ||
end | ||
else | ||
outputChatBox("Couldn't change blip color - invalid arguments specified", player, 255, 0, 0) | ||
end | ||
end | ||
|
||
function destroyPlayerBlip(player) | ||
if (not player or not isElement(player) or player.type ~= "player") then return false end | ||
if isElement(blips[player]) then | ||
blips[player]:destroy() | ||
end | ||
blips[player] = nil | ||
colors[player] = nil | ||
end | ||
|
||
addEventHandler("onPlayerQuit", root, function() | ||
destroyPlayerBlip(source) | ||
end) | ||
addEventHandler("onPlayerWasted", root, function() | ||
destroyPlayerBlip(source) | ||
end) | ||
addEventHandler("onPlayerSpawn", root, function() | ||
createPlayerBlip(source) | ||
end) |