[Snippet] Raise/Lower Windows With Commands (Client) [V 1.1]

Recommended Posts

Posted (edited)

EDIT - JULY 9, 2019:  I managed to handle the error when not in a vehicle! Next up is creating the key-binds. :)  I've also updated the code to make it easier to read.

I haven't found this on the forums yet so I thought I'd share my code that is a work in progress. I'm fairly new to JavaScript and I'm still adapting, but hopefully some of you can make something out of this. Like I said, it is a work in progress, so if you'd like to contribute to it, please do so and I will happily add it to the main source code and give you credit for contribution.

Right now, all commands work, however, there is an error when the player is not in a vehicle. I haven't been able to figure it out yet (I know it's probably stupidly easy).
Other than that, I am working on implementing keybinds once I manage to get all the functions to work in a toggle function. Also, it is only Client Side, so this is not synced!

I've also created a custom function which rolls all the windows up since RAGEMP doesn't have one in their documentation.

To implement this all you have to do is:

1) Create a new folder in: client_resources (name it whatever you'd like)
2) Create a new JS file called: index.js (in folder you created within client_resources - call it whatever you'd like)
3) Include the snippet in your main index.js in the root of client_resources: 


Copy & paste this code:



const blockedClasses = [13, 14, 15, 16, 21];	// Blocks Aeroplanes, Boats, etc."playerCommand", (command) => {

		const localPlayer = mp.players.local;
		const localVehicle = mp.players.local.vehicle;
   	 	const args = command.split(/[ ]+/);
		const commandName = args[0];
		var vehicle = localPlayer.localVehicle;
		var player = player;

		if (!localPlayer.vehicle && commandName != ['flwup', 'flwdown', 'frwup', 'frwdown', 'blwup', 'blwdown', 'brwup', 'brwdown', 'wdown', 'wup'])
		{ return null; }

		if (commandName == 'flwup')			// Front Left Window
		if (commandName === 'flwdown')	
		if (commandName === 'frwup')		// Front Right Window
		if (commandName === 'frwdown')		
		if (commandName === 'blwup')		// Back Left Window
		if (commandName === 'blwdown')
		if (commandName === 'brwup')		// Back Right Window
		if (commandName === 'brwdown')		
		if (commandName === 'wdown')		
		{localVehicle.rollDownWindows();}		// Lowers All The Windows
		if (commandName === 'wup')			

	// EVENT FUNCTION FOR ROLLING UP ALL WINDOWS"rollUpWindows", (vehicle) => {
		var vehicle = mp.players.local.vehicle;





And that's it!
All commands are interchangeable just by directly changing the "commandName".

Hope this helps out some of you! (PS - It's my first script ever for RAGEMP, so please don't be too harsh. :P )

Edited by MyNameIsJeff

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.