Jump to content

One script to rule them all?


robearded

Recommended Posts

Hello, I'm new into RageMP(I only have some days since I'm here). Some years ago I used to develop for a minecraft server and after that I got into Android Dev. The thing i like at Java (and C#) is the OOP structure. Since I got into RageMP I got a feel that the C# way of scripting isn't that based into OOP. If anyone worked with Bukkit, you would know that you can create as many classes inside your project that then you can use for example "ClassName class = new ClassName(parameters); Bukkit.registerEvents(this, class); Bukkit.registerCommand('exampleCommand', class)" which would allow 'class' to process events and the command 'exampleCommand'. The thing is that I didn't got the feel that you can really do that with RageMP so you would need to make your project into lot of scripts instead of having one script with multiple classes (event handlers, command handlers) so you can make your big project into one single plugin(script). That will also make things easier to communicate between classes, because you won't only be able to communicate using strings, ints, arrays, but you would be able to pass custom objects to the other class that is an event handler or command handler. Also on Bukkit you could make plugins that also has API's (you can call functions inside it by referencing to it) so it would be easy to implement a money API from another script as you can just reference the class and access all of it's API why it is still running itself as a script. My question, will the C# API of the RageMP get here in the future? What are the plans of it?

Edited by robearded
Link to comment
Share on other sites

1 hour ago, hyddro said:

Pretty sure everything you said here can be done with Namespaces and Class Abstraction.

 

If I'm not wrong wouldn't that mean that you still need to implement the events in the main class(script) and then just run a function from another class inside the code of that function?

Ex:

SecondClass secondClass;

public MainClass() {
	secondClass = new SecondClass(...params);
}

[Command("example")]
public void CMD_Example(Client client)
{
	secondClass.CMD_Example(client);
}

[ServerEvent(Event.EventOne)]
public void Event_EventOne(...params)
{
	secondClass.EventOne(...params);
}

[ServerEvent(Event.EventX)]
public void Event_EventX(...params)
{
	secondClass.EventX(...params);
} // and so on

That It's still more 'clunkier' than

SecondClass secondClass;

public MainClass() {
	secondClass = new SecondClass(...params);
	NAPI.ScriptManager.registerCommand("example", secondClass); //example of how this can be implemented
	NAPI.ScriptManager.registerEvents(secondClass); //this allows the second class to process events
}

Then second class would look something like that:

public class SecondClass : Script // It would still need to extend Script so it can 'overwrite'(not sure if the right word) command processing, event processing etc.
{
	public SecondClass(...params){
		// Do your variable initialization here etc.
	}
	
	[Command("example")]
	public void CMD_Example(Client client)
	{
		//  Bridge see this as valid command because the main script registered it to this class
	}

	[ServerEvent(Event.AnyEvent)]
	public void Event_AnyEvent(...params)
	{
		// Event will be processed because the class got events registered
	}
}

 

It would allow easier between scripts-communication, as you can pass classes instances of the other scripts when creating the class, basically you can pass any custom object that you created, instead of having to rely on getData, hasData and putData so you don't have to serialize and deserialize your custom objects into arrays, strings etc. each time you want to pass something to another script.

 

Update:

I managed to do that (I don't know how i haven't think of that before) by creating an InstanceManager class (also a Script) and have the instances of all the scripts saved there, when starting a script I would just pass the instance to the instancemanager, where other scripts can find the instance of the other scripts. It works just fine by compiling all of it into a single .dll file. The thing I'm wondering now, I don't think that would work on Client-Side C#, because it only accepts .cs files from what I know and you can't put already compiled scripts.

 

Update 2: Just tested it, the above method works for client-side too.

Edited by robearded
Link to comment
Share on other sites

RAGEmp doesn't support accessing .dll scripts at the client-side at the moment due to the need of Implementation of a Security Layer.

As for what you asked about previously; What you wrote in the "What it would look like" would actually work and an open source example of it is the WiredPlayers-RP gamemode but it does use deserialization .

  • Like 1
Link to comment
Share on other sites

8 hours ago, hyddro said:

RAGEmp doesn't support accessing .dll scripts at the client-side at the moment due to the need of Implementation of a Security Layer.

As for what you asked about previously; What you wrote in the "What it would look like" would actually work and an open source example of it is the WiredPlayers-RP gamemode but it does use deserialization .

The idea on the last post update I got by looking at the WiredPlayers source code, they are using static functions inside the scripts to do that (doing that you wont be able to access non-static functions tho) but if you have another class managing the instances of the scripts it works just fine by calling the instance manager and getting the variable that references to another script.

I also tested this and it works fine for client side too (I guess it works because maybe ragemp compiles client scripts into a single dll?) or maybe it's because on C# you can access classes from other dll's if using on the same proccess(I guess?). So I think this topic can be clossed as something like I requested can somehow be done.

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