Jump to content

Issues with client-side scripting.


Rozi

Recommended Posts

Hello, so I just started scripting RageMP and I am using the bridge and C#. I wish to know how to properly use client-side scripting as there isn't much documentation about it. How would I properly go around and check when a player places a waypoint and relay the coordinates in the chat? Or for example when someone does a command, a notification will appear?

Link to comment
Share on other sites

For clientside you need to use this event https://wiki.rage.mp/index.php?title=PlayerCreateWaypoint

And to place it in chat you simply use https://wiki.rage.mp/index.php?title=Chat.push

Example:

mp.events.add("playerCreateWaypoint", (player, position) => {
    mp.gui.chat.push("You have placed a waypoint at " + position.x + ',' + position.y + ',' + position.z);
});

For serverside commands in C# check this

https://wiki.gtanet.work/index.php?title=Getting_Started_with_Commands

 

Edited by FailerZ
Link to comment
Share on other sites

Just now, FailerZ said:

For clientside you need to use this event https://wiki.rage.mp/index.php?title=PlayerCreateWaypoint

And to place it in chat you simply use https://wiki.rage.mp/index.php?title=Chat.push

Example:


mp.events.add("playerCreateWaypoint", (player, position) => {
    mp.gui.chat.push("You have placed a waypoint at " + position.x + ',' + position.y + ',' + position.z);
});

 

Thank you but I'm asking like how to do the client side stuff, I have no idea where to put the js files, how to call it in my C# code, etc.

Link to comment
Share on other sites

10 minutes ago, Rozi said:

Thank you but I'm asking like how to do the client side stuff, I have no idea where to put the js files, how to call it in my C# code, etc.

You need to open the client_packages inside the server-files then here open or create a file call it 'index.js' inside this file insert

the scripts that you are going to use for example:

require('./SomeScript.js');

Now create the SomeScript.js and it is now going to run clientside scripts inside.

To send events from clientside to serverside use https://wiki.rage.mp/index.php?title=Events::callRemote and then inside your C# resource use https://wiki.gtanet.work/index.php?title=Getting_Started_with_Remote_Events

to receive the function and the passed arguments,

The other way around you do from your C# resource (Client).TriggerEvent() then you catch it inside your javascript file that you've just created by using the mp.events.add like you would when using any clientside event.

Edited by FailerZ
  • Like 2
Link to comment
Share on other sites

10 hours ago, FailerZ said:

You need to open the client_packages inside the server-files then here open or create a file call it 'index.js' inside this file insert

the scripts that you are going to use for example:


require('./SomeScript.js');

Now create the SomeScript.js and it is now going to run clientside scripts inside.

 To send events from clientside to serverside use https://wiki.rage.mp/index.php?title=Events::callRemote and then inside your C# resource use https://wiki.gtanet.work/index.php?title=Getting_Started_with_Remote_Events

to receive the function and the passed arguments,

The other way around you do from your C# resource (Client).TriggerEvent() then you catch it inside your javascript file that you've just created by using the mp.events.add like you would when using any clientside event.

And what exactly would I go and write in the .js file? 

 

I tried:

 

mp.events.add("playerCreateWaypoint", (player, position) => {
 mp.events.callRemote("Waypoint", position);
});

But it didn't work

Link to comment
Share on other sites

//JS Clientside
mp.events.add("playerCreateWaypoint", (player, position) => {
 mp.events.callRemote("Waypoint", player, position);
});
//C# Serverside
[RemoteEvent("Waypoint")]
public void OnPlayerPlaceWaypoint(Client player, Vector3 position)
{
	player.SendChatMessage($"The player {player.Name} has placed waypoint on {position.X},{position.Y},{position.Z}");
}

That's how you send the waypoint that a player placed from client to server

Link to comment
Share on other sites

4 minutes ago, FailerZ said:

//JS Clientside
mp.events.add("playerCreateWaypoint", (player, position) => {
 mp.events.callRemote("Waypoint", player, position);
});

//C# Serverside
[RemoteEvent("Waypoint")]
public void OnPlayerPlaceWaypoint(Client player, Vector3 position)
{
	player.SendChatMessage($"The player {player.Name} has placed waypoint on {position.X},{position.Y},{position.Z}");
}

That's how you send the waypoint that a player placed from client to server

Doing exactly that and it doesn't work

Link to comment
Share on other sites

20 hours ago, Rozi said:

Hello, so I just started scripting RageMP and I am using the bridge and C#. I wish to know how to properly use client-side scripting as there isn't much documentation about it. How would I properly go around and check when a player places a waypoint and relay the coordinates in the chat? Or for example when someone does a command, a notification will appear?

Do you have the C# bridge installed?

Link to comment
Share on other sites

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