by krokots » Thu Dec 07, 2017 4:28 am
OK Just to be sure if I'm making this correctly (the easiest example possible) :
This is the custom event handler :
Code: Select all
Class GEventHandlers : EventHandler
{
override void NetworkProcess(ConsoleEvent e)
{
int playerNumber = e.Player;
let plr = players[playerNumber].mo;
if(plr)
{
if (e.Name == "TestNetEvent")
{
Console.Printf(e.Name.." called by player : "..playerNumber);
Console.Printf(plr.GetClassName());
Console.Printf("Before : "..plr.Health);
//plr.health++; //health is not updating properly
plr.A_SetInventory("Shotgun", 1);
Console.Printf("After : "..plr.Health);
}
else
{
Console.Printf("Invalid event");
}
}
}
}
And this is menu :
Code: Select all
Class TMenu : ListMenu
{
Actor plr;
override void Init(Menu parent, ListMenuDescriptor desc)
{
//plr = players[consoleplayer].mo;
GEventHandlers.SendNetworkEvent("TestNetEvent",1,0,0);
Super.Init(parent, desc);
}
}
It works for player getting an item, but not for health. When I change health, console output from event shows it has changed, but in the HUD it is not changing (eg. I have 100 health and open the menu, the Console.printf("After : "..plr.health) prints 101 but HUD says 100).
OK Just to be sure if I'm making this correctly (the easiest example possible) :
This is the custom event handler :
[code]
Class GEventHandlers : EventHandler
{
override void NetworkProcess(ConsoleEvent e)
{
int playerNumber = e.Player;
let plr = players[playerNumber].mo;
if(plr)
{
if (e.Name == "TestNetEvent")
{
Console.Printf(e.Name.." called by player : "..playerNumber);
Console.Printf(plr.GetClassName());
Console.Printf("Before : "..plr.Health);
//plr.health++; //health is not updating properly
plr.A_SetInventory("Shotgun", 1);
Console.Printf("After : "..plr.Health);
}
else
{
Console.Printf("Invalid event");
}
}
}
}[/code]
And this is menu :
[code]Class TMenu : ListMenu
{
Actor plr;
override void Init(Menu parent, ListMenuDescriptor desc)
{
//plr = players[consoleplayer].mo;
GEventHandlers.SendNetworkEvent("TestNetEvent",1,0,0);
Super.Init(parent, desc);
}
}[/code]
It works for player getting an item, but not for health. When I change health, console output from event shows it has changed, but in the HUD it is not changing (eg. I have 100 health and open the menu, the Console.printf("After : "..plr.health) prints 101 but HUD says 100).