Jump to content

Command Handler


InVision

Recommended Posts

NoAimerWeaponIDs = { [28] = true, [32] = true, [29] = true, [22] = true, [23] = true, [24] = true, } 
  
function disableAimer( prevSlot, newSlot ) 
    if NoAimerWeaponIDs[getPedWeapon(getLocalPlayer(), newSlot)] then 
        showPlayerHudComponent("crosshair", false) 
    else 
        showPlayerHudComponent("crosshair", true) 
    end 
end 
addEventHandler("onClientPlayerWeaponSwitch", getRootElement(), disableAimer) 
addCommandHandler ( "togtarget", disableAimer ) 

I'm trying to make a script that will allow you to disable and enable your crosshair, but the command handler is not working :o what am I doing wrong?

Link to comment
You are writing the new slot along with the command, right? also, the "newSlot" result will be always a string, convert it to a number.

Could you give me an example?

And I want the command to make permanent changes on the event whether there's a transition to a new, or previous slot.

Link to comment
What exactly are you trying to achieve?

I'm trying to make it so a player can enable/disable their crosshair

NoAimerWeaponIDs = { [28] = true, [32] = true, [29] = true, [22] = true, [23] = true, [24] = true, } 
  
function disableAimer( prevSlot, newSlot ) 
    if NoAimerWeaponIDs[getPedWeapon(getLocalPlayer(), newSlot)] then 
        showPlayerHudComponent("crosshair", false) 
    end 
end 
addEventHandler("onClientPlayerWeaponSwitch", getRootElement(), disableAimer) 
  
function enableAimer( prevSlot, newSlot ) 
    if NoAimerWeaponIDs[getPedWeapon(getLocalPlayer(), newSlot)] then 
        showPlayerHudComponent("crosshair", true) 
    end 
end 
addEventHandler("onClientPlayerWeaponSwitch", getRootElement(), enableAimer) 
addCommandHandler ( "togtarget", disableAimer ) 

I changed the code to this, when I have my Deagle out, I execute /togtarget, and the crosshair will dissapear, I'll then do /togtarget in an attempt to enable the crosshair, but it does nothing at that time, I'll then switch to another weapon, and back to my deagle, and the crosshair will be enabled.

But I just want to disable / enable the crosshair without having to transition through weapons

"I know it has something to do with the EventHandler, and possibly the New Slot / Previous Slot when it tries to collect the whether you have a weapon with the No Aimer Weapon IDs

Edited by Guest
Link to comment
You want to let the player choose which weapons will have crosshair?
NoAimerWeaponIDs = { [28] = true, [32] = true, [29] = true, [22] = true, [23] = true, [24] = true, } 

No, I have listed the weapon ID's above in which they can disable... I want them to be able to enable / disable their crosshair without having to switch weapons after executing the command to get the function to work.

Link to comment
NoAimerWeaponIDs = { [28] = true, [32] = true, [29] = true, [22] = true, [23] = true, [24] = true, } 
  
function crosshair ( ) 
    if NoAimerWeaponIDs [ getPedWeapon ( localPlayer ) ] then 
        showPlayerHudComponent ( "crosshair", false ) 
    else 
        showPlayerHudComponent ( "crosshair", true ) 
    end 
end 
addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), crosshair ) 
addCommandHandler ( "togtarget", crosshair ) 

Link to comment
NoAimerWeaponIDs = { [28] = true, [32] = true, [29] = true, [22] = true, [23] = true, [24] = true, } 
  
function crosshair ( ) 
    if NoAimerWeaponIDs [ getPedWeapon ( localPlayer ) ] then 
        showPlayerHudComponent ( "crosshair", false ) 
    else 
        showPlayerHudComponent ( "crosshair", true ) 
    end 
end 
addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), crosshair ) 
addCommandHandler ( "togtarget", crosshair ) 

Your code didn't work :/

But I changed my code some, and got it to work, although I would like to disable / enable it with just one command...

NoAimerWeaponIDs = { [28] = true, [32] = true, [29] = true, [22] = true, [23] = true, [24] = true, } 
  
function disableAimer( prevSlot, newSlot ) 
    if NoAimerWeaponIDs[getPedWeapon(getLocalPlayer(), newSlot)] then 
        showPlayerHudComponent("crosshair", true) 
    end 
end 
addEventHandler("onClientPlayerJoin", getRootElement(), disableAimer) 
addCommandHandler ( "targeton", disableAimer ) 
  
function enableAimer( prevSlot, newSlot ) 
    if NoAimerWeaponIDs[getPedWeapon(getLocalPlayer(), newSlot)] then 
        showPlayerHudComponent("crosshair", false) 
    end 
end 
addEventHandler("onClientPlayerJoin", getRootElement(), enableAimer) 
addCommandHandler ( "targetoff", enableAimer ) 

Link to comment
I don't understand now, you want to disable the crosshair for the weapons in that table or enable it?

I want people to be able to disable the crosshair and enable it all under ONE command. Right now I've only managed to be able to do that under TWO SEPARATE commands.

ED: I am new to scripting, so my style / format may be different than other peoples, so please excuse me.

Think of it as a clapping light, you clap the light turns on, you clap again the light turns off

clap = command

light = crosshair

Edited by Guest
Link to comment
NoAimerWeaponIDs = { [28] = true, [32] = true, [29] = true, [22] = true, [23] = true, [24] = true, } 
  
function crosshair ( ) 
    if NoAimerWeaponIDs [ getPedWeapon ( localPlayer ) ] then 
        showPlayerHudComponent ( "crosshair", not isPlayerHudComponentVisible ( "crosshair" ) ) 
    end 
end 
addCommandHandler ( "togtarget", crosshair ) 

Link to comment
NoAimerWeaponIDs = { [28] = true, [32] = true, [29] = true, [22] = true, [23] = true, [24] = true, } 
  
function crosshair ( ) 
    if NoAimerWeaponIDs [ getPedWeapon ( localPlayer ) ] then 
        showPlayerHudComponent ( "crosshair", not isPlayerHudComponentVisible ( "crosshair" ) ) 
    end 
end 
addCommandHandler ( "togtarget", crosshair ) 

Worked perfectly, thank you so much, you saved me a lot of headaches!

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...