From 678689eb5842870572900193af0c721be0a2ca88 Mon Sep 17 00:00:00 2001 From: Apelta <54854228+TSafa-23@users.noreply.github.com> Date: Fri, 18 Dec 2020 19:37:48 -0600 Subject: [PATCH] Add crosshair for sniper rifles (#721) * Upload rifle_crosshair.png Image used for rifle crosshair. Created by PiMonkey. * sniper_rifles: Add crosshair for rifles via HUD HUD-driven crosshair for sniper rifles. NOTE: scale_const is set to 4, this may be changed by preference. * Increase size slightly Co-authored-by: LoneWolfHT --- mods/pvp/sniper_rifles/init.lua | 18 ++++++++++++++++++ .../textures/rifle_crosshair.png | Bin 0 -> 1080 bytes 2 files changed, 18 insertions(+) create mode 100644 mods/pvp/sniper_rifles/textures/rifle_crosshair.png diff --git a/mods/pvp/sniper_rifles/init.lua b/mods/pvp/sniper_rifles/init.lua index d40e223..eec979d 100644 --- a/mods/pvp/sniper_rifles/init.lua +++ b/mods/pvp/sniper_rifles/init.lua @@ -11,6 +11,12 @@ local scoped = {} -- Timer for scope-check globalstep local timer = 0.2 +-- List of IDs for players scoped, for use in hide_scope(). NOTE: for HUD overlay +local scoped_hud_id = {} + +-- Scale constant, for crosshair. This is to ensure the crosshair will be centered. +local scale_const = 6 + local default_physics_overrides = { speed = 0.1, jump = 0 @@ -27,10 +33,19 @@ local function show_scope(name, item_name, fov_mult) end scoped[name] = item_name + scoped_hud_id[name] = player:hud_add({ + hud_elem_type = "image", + position = {x = 0.5, y = 0.5}, + offset = {x = (-65*scale_const)/2, y = (-65*scale_const)/2}, + text = "rifle_crosshair.png", + scale = {x = scale_const, y = scale_const}, + alignment = {x = 1, y = 1}, + }) -- e.g. if fov_mult == 8, then FOV = 1/8 * current_FOV, a.k.a 8x zoom player:set_fov(1 / fov_mult, true) physics.set(name, "sniper_rifles:scoping", rifles[item_name].physics_overrides) player:hud_set_flags({ wielditem = false }) + end local function hide_scope(name) @@ -40,9 +55,12 @@ local function hide_scope(name) end scoped[name] = nil + player:hud_remove(scoped_hud_id[name]) + scoped_hud_id[name] = nil player:set_fov(0) physics.remove(name, "sniper_rifles:scoping") player:hud_set_flags({ wielditem = true }) + end local function on_use(stack, user, pointed) diff --git a/mods/pvp/sniper_rifles/textures/rifle_crosshair.png b/mods/pvp/sniper_rifles/textures/rifle_crosshair.png new file mode 100644 index 0000000000000000000000000000000000000000..79daabe9651b4f6dd1563a9f035eaa400ff18253 GIT binary patch literal 1080 zcmV-81jqY{P)EX>4Tx04R}tkv&MmP!xqvTct%R4rUN>$WR5rqNs?YRIvyaN?V~-2a}inL6e3g z#l=x@EjakISaoo5*44pP5CnffoE)7LU8KbOl0u6ZFFfAIdG{RNyASX;Doi!ICID5l zj8r@(W^=1z@D(BWAYdG$5;OHgdNBjf`nsoHs=Fx9^6vYydX>D%0G~)a$8^IY-XNaY zv~Ou|O;qJ6P^uRx(uLY2t{YYLxHK zx~y>C;;dF`taVTR!f;+&Npqdn5aL)u0!fIFQ9~IOScuZDkzyi6=P?iepyN-HOD0zt zj2sK7LWSh`!T;d*Y|X;dq?;6u0o^aQ{V@y#cY$Wzw!e>UyLkcxo`EZ^?XNa~*-z5z zZ7p&H^lbwd*KJMS11@)ffhS!uBu5I+@)rug`x$*x4(PuHde+>zwa#(+0Ay%Z%QwKm zAuv*;>~)WKhdSr>Z%=D}Kdwb`zoLsywEzGB24YJ`L;(K){{a7>y{D4^000SaNLh0L z01FcU01FcV0GgZ_00007bV*G`2jmC=6%iDgBS~fe00J~gL_t(|+U;B0Zo?o9H6&91 z|7WA6K)i=#lE;#8Gc++Asp>;oz{kfIS^yXr7}%j2&ExjDQs%?`H9eVx?PPo;&n*DF z0AK}x836Rfx{y4-HP+oYB(Gm%ue^;X&+W;0>m7|>4i@VYB#)6H<&&}8g#h1plM(lr z@EvnN#>eo^@H__zXUcfDCcrUyqJ)GaCFVFHt2)rEUz)LzsZtfKNf%7E-Kb<~qDYmh zPMt}BYth6cVj|(7phCi=IlwZG%aId~dW)hQ5vl@?ncNyA_)ZH}4Hdc2T5T&=Vhn|^ zDjleHLxL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