Hello, I have a problem on my C# code. One serverside method with TriggerClientEvent is working corretly but anothers works only one for a payer.
Here is my code.
// Server side
public class GunSystemServer : BaseScript
{
public GunSystemServer()
{
EventHandlers.Add("chatMessage", new Action<int, string, string>(HelpGun));
EventHandlers.Add("chatMessage", new Action<int, string, string>(GiveAllGuns));
}
// server-client works well
private void HelpGun(int playerid, string playername, string message)
{
if ( message == "/helpgun" )
{
PlayerList pl = new PlayerList();
Player player = pl[playerid];
TriggerClientEvent(player, "HelpGun", helpmessage);
}
}
// server side works, client side works only once
private void GiveAllGuns(int playerid, string playername, string message)
{
if ( message == "/giveallguns" || message == "/gag" )
{
API.CancelEvent(); // tried with and without that
PlayerList pl = new PlayerList();
Player player = pl[playerid];
TriggerClientEvent(player, "GiveAllGuns");
}
}
}
// client side
public class GunSystemClient : BaseScript
{
public GunSystemClient()
{
EventHandlers.Add("HelpGun", new Action<string>(HelpGun));
EventHandlers.Add("GiveAllGuns", new Action(GiveAllGuns));
}
// works well
private void HelpGun(string helpmessage) {
TriggerEvent("chatMessage", "HELP", new[] { 0, 0, 200 }, helpmessage);
}
// works only once at connection time of a player
private void GiveAllGuns()
{
// only for ingame debugging
TriggerEvent("chatMessage", "DB", new [] { 200, 0, 0 }, "GiveAllGuns Client was triggerd");
Ped ped = new Ped(Game.PlayerPed.Handle);
var weaponList = Enum.GetValues(typeof(WeaponHash));
foreach (var item in weaponList)
{
Function.Call(Hash.GIVE_WEAPON_TO_PED, ped, Convert.ToInt32(item), 1000, false);
}
}
}
HelpGun() works always, GiveAllGuns() works only once for a player at connection session.
If he reconnect he can used it once again.
Have I forget something? Thank you for helping