/helmet [on] [off]

This is a simple resource to remove your helmet on command, and then put it back on, on command.

I saw a community request this and despite it being a smaller resource I decided to quickly mock it up.
The resource also has the option to remove the auto bike helmets that your player puts on when getting on a motorbike, because the player will put on the regular bike helmet if you do /helmet off when on a bike.

image
image
client.lua (986 Bytes)

I do not reccomend you put this in a standalone resource (as it is very small), it should be added to a single ā€œcommandsā€ resource ideally.

Here is the code itself, for those of you who donā€™t want to download anything.
Client.lua

RemoveBikeHelmet = true --Change this to your liking, I reccomend that you leave this at true.

player = GetPlayerPed(-1)
RegisterCommand("helmet", function(source, args, raw) -- adjust command name here
    if (args[1] == "off")  then
	
	SavedHelmet = GetPedPropIndex(player, 0) -- Get helmet ID of the source player
	SavedHelmetTexture = GetPedPropTextureIndex(player, 0) -- Get helmet texture ID of the source player
	ClearPedProp(player, 0)
	else --if the text after helmet is anything but "off"
	--TODO, use the saved ped helmet, and requip that.
	SetPedPropIndex(player, 0, SavedHelmet, SavedHelmetTexture, true)
	end
	
end, false) -- false, allow everyone to run it

if RemoveBikeHelmet then
Citizen.CreateThread( function()
  while true do
    Citizen.Wait(0)		--Edit this if the resource is using too much resources.   
    local playerVeh = GetVehiclePedIsUsing(player)
    if PlayerVeh ~= 0 then SetPedConfigFlag(player, 35, false) end
  end	
end)
end```
3 Likes

Nice release!

1 Like

It would be a neat feature if you could play an animation when the ped puts the helmet on or takes it off.

Github please.

Great idea! Iā€™ll look into it when I get a minute!

Iā€™ll look into setting up a github, but my projects are all so small. It almost doesnā€™t seem worth it.

1 Like
local helmet = false
RegisterCommand("helmet", function(source, args, raw)
	helmet = not helmet

    if helmet then
				-- Do stuff
    else
				-- Else do other stuff
    end
end, false)

Should avoid you having to use args like on/off, just the command itself to ā€˜toggleā€™ it.

People just wanna view code instead of downloading crap into their PCā€¦ no offense but Iā€™m trying to take caution with downloading random things from the internet.

Editted post to allow the OP to be the one to post his full code block in the main topic.

1 Like

Absolutely understandable! Iā€™ll look into it

Iā€™ll edit the post to include the plain code also.

1 Like

this isnt totally intended just to be used out of the box, itā€™s a very small amount of code, but if every release tended to everyones needs thereā€™d be 500 different versions of each release, I just figured this was the clearest way I could put it.

It would be really easy to change it to a bool toogle instead of the if then else tree, so feel free to, im not stopping you lol.

Oh for sure :slight_smile: was just trying to help you out if you werenā€™t aware of that method.

Yeah, I mean I agree, if anything it would be easier on a keybind toggle, thereā€™s just a lot of possibilities and Iā€™ll leave it up to the players :smiley:

You should also do ear accessories, glasses, and masks. It could replace the esx_accessories menu.

2 Likes

Good idea, I might revamp this sometime to include those

1 Like

How would i go about adding the same thing for masks,glasses,torsos (shirts) and pants?

1 Like

Is anyone else getting bug where they login to the server with the helmet on and the helmet script needs to be restarted in order to remove it? It happens every time.

Yes, no clue why

Iā€™m getting the same error =(

Did u figure out how fix it, please?

@Matthew5 could you help, please?

Thank you!!!