Jump to content

Help with a quick function?


Bean

Recommended Posts

I'm basically trying to make it so the player can toggle their own radar GUI, here's the code I made, and I'm very, very new to this, if I could possibly get some help here?

function toggleradar(command, onoff, thePlayer) 
if onoff="1" then 
setPlayerHudComponent(root, "radar", true, thePlayer) 
outputChatBox("Radar was turned on.") 
else 
if onoff="0" then 
setPlayerHudComponent(root, "radar", false, thePlayer) 
outputChatBox("Radar was turned off.") 
else 
outputChatBox("Syntax: /setradar [1=on], [0=off]" 
end 
addCommandHandler("setradar", toggleradar) 

Link to comment

try

local toggleradar = createRadarArea ( -2183.5678710938, 705.67950439453, 40, -40, 0, 255, 0, 175 ) -- REPLACE these numbers if needed. 
local localplayer = getLocalPlayer 
if onoff="1" then 
setPlayerHudComponent(root, "radar", true, localplayer) 
outputChatBox("Radar was turned on.") 
else 
if onoff="0" then 
setPlayerHudComponent(root, "radar", false, localplayer) 
outputChatBox("Radar was turned off.") 
else 
outputChatBox("Syntax: /setradar [1=on], [0=off]" 
end 
addCommandHandler("setradar", toggleradar) 

If localplayer doesn't work replace it with thePlayer and remove

local localplayer = getLocalPlayer 

Edited by Guest
Link to comment

'setPlayerHudComponent' doesn't exist, try this:

function toggleradar(_, onoff, thePlayer) 
    if onoff=="1" then 
        showPlayerHudComponent("radar", true) 
        outputChatBox("Radar was turned on.") 
    elseif onoff=="0" then 
        showPlayerHudComponent("radar", false) 
        outputChatBox("Radar was turned off.") 
    else 
        outputChatBox("Syntax: /setradar [1=on], [0=off]", 
    end 
end 
addCommandHandler("setradar", toggleradar) 

Link to comment

If you're making is client side then,

function toggleRadar( commandName, argument ) 
    if ( argument ~= nil ) then 
         
        local argument = tostring( argument ) 
        if ( argument == '1' ) then 
             
            showPlayerHudComponent('radar', true) 
            outputChatBox('Radar was turned on.', 0, 200, 0) 
        elseif ( argument == '0' ) then 
         
            showPlayerHudComponent('radar', false) 
            outputChatBox('Radar was turned off.', 200, 0, 0) 
        else 
            outputChatBox('SYNTAX: /'.. commandName ..' [ 1/2 ]', 255, 255, 255) 
        end 
    else 
        outputChatBox('SYNTAX: /'.. commandName ..' [ 1/0 ]', 255, 255, 255) 
    end  
end 
addCommandHandler('setradar', toggleRadar, false, false ) 

or if you're making it serverside,

function toggleRadar( thePlayer, commandName, argument ) 
    if ( argument ~= nil ) then 
         
        local argument = tostring( argument ) 
        if ( argument == '1' ) then 
             
            showPlayerHudComponent(thePlayer, 'radar', true) 
            outputChatBox('Radar was turned on.', thePlayer, 0, 200, 0) 
        elseif ( argument == '0' ) then 
         
            showPlayerHudComponent(thePlayer, 'radar', false) 
            outputChatBox('Radar was turned off.', thePlayer, 200, 0, 0) 
        else 
            outputChatBox('SYNTAX: /'.. commandName ..' [ 1/2 ]', thePlayer, 255, 255, 255) 
        end 
    else 
        outputChatBox('SYNTAX: /'.. commandName ..' [ 1/0 ]', thePlayer, 255, 255, 255) 
    end  
end 
addCommandHandler('setradar', toggleRadar, false, false ) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...