MyNameIsJeff

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

Recommended Posts

Posted (edited)
Quote

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: 

require(./YOURFOLDERNAME)


Copy & paste this code:

Spoiler

 

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

		// VARIABLES
		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;

		// CHECK IF THE PLAYER IS INSIDE A VEHICLE
		if (!localPlayer.vehicle && commandName != ['flwup', 'flwdown', 'frwup', 'frwdown', 'blwup', 'blwdown', 'brwup', 'brwdown', 'wdown', 'wup'])
		{ return null; }

		// COMMANDS FOR WINDOWS
		if (commandName == 'flwup')			// Front Left Window
		{localVehicle.rollUpWindow(0);}
		if (commandName === 'flwdown')	
		{localVehicle.rollDownWindow(0);}
		if (commandName === 'frwup')		// Front Right Window
		{localVehicle.rollUpWindow(1);}
		if (commandName === 'frwdown')		
		{localVehicle.rollDownWindow(1);}
		if (commandName === 'blwup')		// Back Left Window
		{localVehicle.rollUpWindow(2);}
		if (commandName === 'blwdown')
		{localVehicle.rollDownWindow(2);}
		if (commandName === 'brwup')		// Back Right Window
		{localVehicle.rollUpWindow(3);}
		if (commandName === 'brwdown')		
		{localVehicle.rollDownWindow(3);}
		if (commandName === 'wdown')		
		{localVehicle.rollDownWindows();}		// Lowers All The Windows
		if (commandName === 'wup')			
		{mp.events.call("rollUpWindows")};
	
	});

	// EVENT FUNCTION FOR ROLLING UP ALL WINDOWS
	mp.events.add("rollUpWindows", (vehicle) => {
		var vehicle = mp.players.local.vehicle;
		vehicle.rollUpWindow(0);
		vehicle.rollUpWindow(1);
		vehicle.rollUpWindow(2);
		vehicle.rollUpWindow(3);
	});

 

 

 

 

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.

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