Jump to content

[C#] how to create custom event in one script and cal it from another.


Recommended Posts

Download some resources from ragemp forum and experiment.


Here is an example from one of my gamemodes

// Client side
class LoginRegister : Events.Script
        public LoginRegister()
            // this event you call from CEF to get login data using mp.trigger('client:login.player', email, password);
            Events.Add("client:login.player", LoginPlayerEvent); 
        private void LoginPlayerEvent(object[] args)
            string inputedEmail = (string)args[0],
				   inputedPassword = (string)args[1];

            Events.CallRemote("server:login.player", inputedEmail, inputedPassword);

// Server side
public void LoginPlayerEvent(Player player, string email, string password)
	// Check if email and password match
	if(Database.LoginAccount(email, password))
		// Load all the player data
		var character = Database.LoadAccountFromEmail(email);
		LoadCharacterData(player, character);
		// Warn the player that his email/password is incorrect
		player.TriggerEvent("javascript:warning", "Wrong username/password.");


Edited by Kopra
Link to comment
Share on other sites

Thank you Kopra for your time and reply.

But mine proble is that i want event that i call from another serverside script.

If i register RemoteEvent then (i think) i cant call it from another server side script.

I tryed to use GTANetworkApi.NAPI.LocalEvent.Register but get no luck with that... propably my skill in C# to low.

            System.Reflection.MethodInfo zMethod = this.GetType().GetMethod("ClassMethod");
            GTANetworkAPI.NAPI.LocalEvent.Register(zMethod, "ClassMethodEvent", this);


I get System.NullRefenceException on TriggerEvent.

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