New Custom Event onPlayerUnderAttack

Started by Sonmez, Jan 13, 2021, 11:36 AM

Previous topic - Next topic

Sonmez

Syntax
function onPlayerUnderAttack(player,plr)

Example
function onPlayerUnderAttack(player,plr)
{
  Message(player.Name+" is attacking "+plr.Name);
}

Source Code

CLIENT SIDE
function Player::PlayerShoot(player, weapon, hitEntity, hitPosition)
{
  if (player == World.FindLocalPlayer()){
  if (hitEntity.Type == 0){
      local shooter = player;
      local plr = hitEntity.ID;
      local message = Stream();
      message.WriteInt(12332115);  // use unique integer
      message.WriteString(plr.tostring());
      Server.SendData(message);}
}}


SERVER SIDE

function onPlayerUnderAttack(player,plr)
{
  Message(player.Name+" is attacking "+plr.Name);
}
function onClientScriptData( player )
{
    local int = Stream.ReadInt(),
    string = Stream.ReadString();
    if (int == 12332115)
    {
      local plr = FindPlayer(string.tointeger());
      if (plr){onPlayerUnderAttack(player,plr)}
    }
}
if (!perfect) createAgain();

Sebastian

Unfortunately,  Player::PlayerShoot is not called for shotguns...