juju scripting documentation
  • Scripting Documentation
  • Creating a script
    • Necessities
      • Example Script
      • Example Script 2
      • Example Script 3
  • Documentation
    • Elements
      • Element Properties
      • Element API
    • Utility Functions
  • Da Hood
    • Signals
    • Functions
Powered by GitBook
On this page
  1. Creating a script
  2. Necessities

Example Script 2

This script changes the colors of the 2d and 3d hit marker when the part hit is the Head.

-- >> variables

local juju = juju
    local get_flag = juju["get_flag"]
local delay = task["delay"]

-- >> core

local twod_hit_marker = juju["find_element"]("2d hit marker", "color")
local threed_hit_marker = juju["find_element"]("3d hit marker", "color")


local set_old = function(d2, d3)
    twod_hit_marker:set_colorpicker(d2)
    threed_hit_marker:set_colorpicker(d3)
end

local hit_callback = function(player, part)
    if part["Name"] == "Head" then
        local color = get_flag("hit_marker_headshot_color")
        local old_d2_color = get_flag("d2_hit_marker_color")
        local old_d3_color = get_flag("d3_hit_marker_color")
        twod_hit_marker:set_colorpicker(color)
        threed_hit_marker:set_colorpicker(color)
        delay(0, set_old, old_d2_color, old_d3_color) -- >> restore flags asap
    end
end

juju["create_element"]({
    ["name"] = "hit marker headshot color"
}, {
    ["colorpicker"] = {
        ["color_flag"] = "hit_marker_headshot_color",
        ["default_color"] = Color3.fromRGB(0,255,0),
        ["transparency_flag"] = "hit_marker_headshot_transparency",
        ["default_transparency"] = 0
    }
})

local signal = juju["get_signal"]("on_local_bullet_confirmed")
local callbacks = signal["callbacks"]

-- >> insert it as the first one so we can set the fflag before the hitmarker runs

for i = #callbacks, 1, -1 do
    callbacks[i + 1] = callbacks[i]
end
callbacks[1] = hit_callback

-- >> clean up 

juju["on_unload"](function()
    -- >> remove callback and restore old table positions
    for i = 1, #callbacks - 1 do
        callbacks[i] = callbacks[i + 1] 
    end
    callbacks[#callbacks] = nil
end)

-- >> loaded 

juju["create_notification"]("loaded hitmarker head color lua by xander", 1)
PreviousExample ScriptNextExample Script 3

Last updated 3 months ago