Luckshya

  • Full Member
  • Posts: 108
[Fixed] player.Spec and player.Spectate
« on July 20th, 2017, 11:23 AM »Last edited on August 7th, 2017, 09:51 AM
Well, I was trying to spectate a player.
I first used player.Spec = plr which worked.
then I wanted to stop the player from spectating plr
so, I tried player.Spec = null which crashed the server with an error: std::out_of_range 
then, I tried player.RestoreCamera() which gave no effect.
then, I used player.Spectate(plr) which worked and player was spectating plr and plr left and the server crashed with that same error.

I still didn't get a way to stop someone from spectating.

vito1

  • Guest

EK.IceFlake

  • Hero Member
  • "We are the champions my fellahs" - Sufyan/VK.SuFy
  • Posts: 1,761

vito1

  • Guest

EK.IceFlake

  • Hero Member
  • "We are the champions my fellahs" - Sufyan/VK.SuFy
  • Posts: 1,761

vito1

  • Guest

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,804
[BUG] Re: player.Spec and player.Spectate
« Reply #6, on July 24th, 2017, 04:10 PM »
Entities have something called null entities. Like: SqPlayer.NullInst(); Which you can use to specify an entity which doesn't exist. Which you can use with player.Spectate(...);

This spectating crash has been reported several times an tbh I have no idea wtf is causing it. Could be an event fired when the player is spectated. Which corrupts the stack or something.

I'm not home for another week or so. Therefore I can' t look into it.
[BUG] Re: player.Spec and player.Spectate
« Reply #7, on August 6th, 2017, 02:01 PM »
An attempt to fix this behavior was made here. Let me know if it does anything. And if it doesn't. I honestly have no idea what can cause the crash. Because I'm doing nothing but forward the call to the server function. So I'll assume that the server is the one to cause the crash.
.

Luckshya

  • Full Member
  • Posts: 108
[BUG] Re: player.Spec and player.Spectate
« Reply #8, on August 6th, 2017, 02:55 PM »Last edited on August 6th, 2017, 03:24 PM
The bug is still not yet fixed, it's still crashing the server, here's what I'm using
Code: [Select]
g_Cmd <- SqCmd.Manager();

SqCore.On().PlayerCommand.Connect(this, function(player, command)
{
    g_Cmd.Run(player, command);
});

Spectate <- g_Cmd.Create("spec", "s", ["player"], 1, 1, -1, false, true);
Spectate.Help = "It is a command used to spectate a player.";
Spectate.BindExec(Spectate, function(player, args)
{
local plr = ( (SqStr.AreAllDigit(args.player)) ? SqFind.Player.WithID(args.player.tointeger()) : SqFind.Player.NameContains(false, false, args.player) )
player.Message(plr)
if ( plr == SqPlayer.NullInst() ) return player.Message("[#FF7F50]Error: [#ffffff]Unknown player [#FF7F50]%s[#ffffff].", args.player);
else if ( player.ID == plr.ID ) return player.Message("[#FF7F50]Error: [#ffffff]You cannot spectate yourself.");
else if ( !plr.Spawned ) return player.Message("[#FF7F50]Error: [#FF7F50]%s [#ffffff]is not yet spawned.", plr.Name)
else if ( player.Spectating() != null ) return player.Message("[#FF7F50]Error: [#ffffff]You're already spectating: [#FF7F50]%s[#ffffff].", player.Spec.Name);
player.SpecID = plr.ID;
player.Message("[#ffcc00]Information: [#ffffff]You're now spectating: %s.", plr.Name);
return true;
});

Unspec <- g_Cmd.Create("unspec", "s", [""], 0, 0, -1, false, true);
Unspec.Help = "It is a command used to stop spectating a player.";
Unspec.BindExec(Unspec, function(player, args)
{
if ( player.Spectating() == null ) return player.Message("[#FF7F50]Error: [#ffffff]You're not spectating anyone.");
player.Message("[#ffcc00]Information: [#ffffff]You've stopped spectating: [#FF7F50]%s[#ffffff].", player.Spectating().Name);
player.SpecID = -1; //player.Spectate(SqPlayer.NullInst()), player.SpectateNone();
return true;
});

Commands: /spec <player> and /unspec
Let's see if I'm doing something wrong.

Here's the error log