The example I did is without the player and doesn’t work (using just String eventName, Args) … I don’t know why :/…
Tried also with the player… and doesn’t work also in this case…
Have they fully implemented this in C#? Or I’m doing something wrong?
I tried also to use something like that just to test :
public BasicResourceClient()
{
Tick += OnTick;
EventHandlers["sendMotd"] += new Action<string>(ReceivedMotd);
TriggerEvent("sendMotd", "test");
}
This triggerevent should call the EventHandlers itself right? But also this doesn’t work…
Now could be the EventHandlers in the client side the real problem?
On playerConnecting, the player won’t exist yet, so if you want to send an event to that specific player, you’ll need an event that executes a bit later.
Thx titanium, it’s working , tested with EventHandlers[“chatMessage”] += new Action<int, string, string>(OnPlayerText); .
Thx also to everyone that answered and Syntasu for the tutorial without I could never start scripting :)!
Now I will try to port my single player zombie mod, thx very much again guys.
Exactly the kind of guide I was waiting for! Thank you! I am used to C-Style languages like C++ and C# and really don’t like LUA scripting styles (To me it just looks like spaghetti).
This is a good tutorial, thank you. I followed it and still could not get things working. After consulting with @SheppeR, we found the issue. The main issue, I was using the wrong Target Framework and Target Platform.
Set Build -> Target Platforms -> Any CPU, also use .Net4.5.2
May I suggest adding to your tutorial a check for Target Platform and Target Framework. It should be added to the Wiki as well.
I also tried to implement the playerSpawned event on client side with this line in the constructor:
EventHandlers.Add("playerSpawned", new Action<Player>(OnPlayerSpawned));
and this method:
private void OnPlayerSpawned([FromSource]Player player)
{
Debug.WriteLine("OnPlayerSpawned!!! "+player.Name); //this creates an error :(
Debug.WriteLine("OnPlayerSpawned!!!"); //this works :) you got the line "OnPlayerSpawned!!!" at your client console (F8)
}
So I think there is no parameter of type Player in the event? In the lua docu I got no more help, I don’t understand nothing of it
Where can i find out what parameters are used in the events?
[ 208875] RgscStub::m_13
[ 208875] Exception thrown by a task: System.AggregateException: One or more errors occurred. ---> System.MethodAccessException: Error verifying BasicResourceClient.BasicResourceClient/<OnTick>d__1:MoveNext (): Method System.Array:Empty<object> () is not accessible at 0x0014
[ 208875] at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in <a4e3abdd630b4c98a9d6f31a99197de6>:0
[ 208875] at BasicResourceClient.BasicResourceClient.OnTick () [0x00026] in <ecc227357829482ab7dc92b9bb9a5ade>:0
[ 208875] at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <a4e3abdd630b4c98a9d6f31a99197de6>:0
[ 208875] at System.Threading.Tasks.Task.Execute () [0x00010] in <a4e3abdd630b4c98a9d6f31a99197de6>:0
[ 208875] --- End of inner exception stack trace ---
[ 208875] ---> (Inner Exception #0) System.MethodAccessException: Error verifying BasicResourceClient.BasicResourceClient/<OnTick>d__1:MoveNext (): Method System.Array:Empty<object> () is not accessible at 0x0014
[ 208875] at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in <a4e3abdd630b4c98a9d6f31a99197de6>:0
[ 208875] at BasicResourceClient.BasicResourceClient.OnTick () [0x00026] in <ecc227357829482ab7dc92b9bb9a5ade>:0
[ 208875] at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <a4e3abdd630b4c98a9d6f31a99197de6>:0
[ 208875] at System.Threading.Tasks.Task.Execute () [0x00010] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 <---
[ 208875]
[ 208875] Failed to run a tick for BasicResourceClient: System.MethodAccessException: Error verifying BasicResourceClient.BasicResourceClient/<OnTick>d__1:MoveNext (): Method System.Array:Empty<object> () is not accessible at 0x0014
[ 208875] at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in <a4e3abdd630b4c98a9d6f31a99197de6>:0
[ 208875] at BasicResourceClient.BasicResourceClient.OnTick () [0x00026] in <ecc227357829482ab7dc92b9bb9a5ade>:0
[ 208875] at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <a4e3abdd630b4c98a9d6f31a99197de6>:0
[ 208875] at System.Threading.Tasks.Task.Execute () [0x00010] in <a4e3abdd630b4c98a9d6f31a99197de6>:0
Client script code:
public BasicResourceClient()
{
//In the constructor we add
Tick += OnTick;
}
private async Task OnTick()
{
Debug.WriteLine("One second passed!");
await Delay(1000);
}