News A server update was released on July 20. Server patch notes and downloads are here. Additionally, a client update was released on the same day. Client patch notes are here.
[Fixed] player.Spec and player.Spectate

Luckshya

  • Jr. Member
  • Posts: 73
[Fixed] player.Spec and player.Spectate
«  »Last edited
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

  • Jr. Member
  • Posts: 81

EK.IceFlake

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

vito1

  • Jr. Member
  • Posts: 81

EK.IceFlake

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

vito1

  • Jr. Member
  • Posts: 81

.

  • Moderator
  • Posts: 1,766
[BUG] Re: player.Spec and player.Spectate
« Reply #6,  »
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,  »
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

  • Jr. Member
  • Posts: 73
[BUG] Re: player.Spec and player.Spectate
« Reply #8,  »Last edited
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