player spectate killer
#1

I got this and I dont get it why isnt it working.

Basically if you get killed you should spectate the player that killed you (10 sec), but it wont work.


Код:
//Top of the script.
new Died[MAX_PLAYERS], KilledBy[MAX_PLAYERS];
forward EndDeathCam(playerid);

//OnPlayerConnect
Died[playerid] = -1;
KilledBy[playerid] = -1;

//OnPlayerDisconnect
Died[playerid] = 0;
KilledBy[playerid] = 0;

public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;
    pInfo[playerid][Deaths]++;
    
    Died[playerid] = 1;
    if(Died[playerid] == 1)
    {
        Died[playerid] = 0;
        if(KilledBy[playerid] != INVALID_PLAYER_ID)
        TogglePlayerSpectating(playerid, 1);
        PlayerSpectatePlayer(playerid, killerid);
        SendClientMessage(playerid, WHITE, "You have been killed, you are now spectating your killer.");
        SetTimerEx("EndDeathCam", 10000, 1, "i", playerid); // 10 seconds
    }
    else
    {
        TogglePlayerSpectating(playerid, 0);
    }
    return 1;
}

public EndDeathCam(playerid)
{
    TogglePlayerSpectating(playerid, 0);
    Died[playerid] = 0;
}
Reply
#2

pawn Код:
Died[playerid] = 1;
if(Died[playerid] == 1)
{
//(...)
}
else
{
//(...)
}
Question: does the else ever gets called?

pawn Код:
if(KilledBy[playerid] != INVALID_PLAYER_ID)
You have to use brackets to specify how many lines are affected by the condition.

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;
    pInfo[playerid][Deaths]++;
   
    Died[playerid] = 1;
    KilledBy[playerid] = killerid;
    TogglePlayerSpectating(playerid, 1);
    PlayerSpectatePlayer(playerid, killerid);
    SendClientMessage(playerid, WHITE, "You have been killed, you are now spectating your killer.");
    SetTimerEx("EndDeathCam", 10000, 1, "i", playerid); // 10 seconds
    return 1;
}
Reply
#3

pawn Код:
#define FILTERSCRIPT
#include <a_samp>

forward spectateend(playerid);

public OnPlayerDeath(playerid,killerid,reason)
{
    if ( killerid != INVALID_PLAYER_ID )
    {
        new szGameTextStr[128], killerName[24];
       
        GetPlayerName(killerid,killerName,24);
        TogglePlayerSpectating( playerid, 1 );
        if (IsPlayerInAnyVehicle(killerid))
        {
        PlayerSpectateVehicle( playerid, GetPlayerVehicleID( killerid ) );
        }
        else
        {
        PlayerSpectatePlayer( playerid, killerid );
        }
        format( szGameTextStr, 128, "~w~~n~killCamera~n~~>~Killer: %s ( ID: %i )~<~", killerName, killerid );
        GameTextForPlayer( playerid, szGameTextStr, 10000, 5 );
        SetTimerEx( "spectateend", true, 10000, "i", playerid );
    }
    return 1;
}

public spectateend(playerid)
return TogglePlayerSpectating(playerid,0), SpawnPlayer(playerid);
// end.
Now, edit it like you want for your register system..
Reply
#4

Oh thanks guys, I'll test it.
Reply
#5

I tested it and the issue is that it spectates the player but constantly bugs the camera and you crash. It's like teleporting the camera like crazy.


It just teleports the camera like crazy. FOr example

Teleports Camera to KillerID
Teleports Camera to PlayerID
Teleports Camera to KillerID
Teleports Camera to PlayerID

every sec


This is my OnPlayerSpawn
Код:
public OnPlayerSpawn(playerid)
{
	
	TextDrawHideForPlayer(playerid, Textdraw0);
	TextDrawHideForPlayer(playerid, Textdraw1);
	
	new Random = random(sizeof(RandomSpawns));
    SetPlayerPos(playerid, RandomSpawns[Random][0], RandomSpawns[Random][1], RandomSpawns[Random][2]);
    SetPlayerFacingAngle(playerid, RandomSpawns[Random][3]);
    
	return 1;
}
I use this
Код:
#define FILTERSCRIPT
#include <a_samp>

forward spectateend(playerid);

public OnPlayerDeath(playerid,killerid,reason)
{
    if ( killerid != INVALID_PLAYER_ID )
    {
        new szGameTextStr[128], killerName[24];
        
        GetPlayerName(killerid,killerName,24);
        TogglePlayerSpectating( playerid, 1 );
        if (IsPlayerInAnyVehicle(killerid))
        {
        PlayerSpectateVehicle( playerid, GetPlayerVehicleID( killerid ) );
        }
        else
        {
        PlayerSpectatePlayer( playerid, killerid );
        }
        format( szGameTextStr, 128, "~w~~n~killCamera~n~~>~Killer: %s ( ID: %i )~<~", killerName, killerid );
        GameTextForPlayer( playerid, szGameTextStr, 10000, 5 );
        SetTimerEx( "spectateend", true, 10000, "i", playerid );
    }
    return 1;
}

public spectateend(playerid)
return TogglePlayerSpectating(playerid,0), SpawnPlayer(playerid);
// end.
Reply
#6

It's work fine for me?
Reply
#7

Hmmm...

It doesnt work for me normaly. It just switches the camera as crazy and at the end you crash :/

Can it be related to something else maybe?
Here is my full code
http://pastebin.com/1Z79zv7q
Reply
#8

Try this? just edited some code. give it a try if it works.

also im not sure if this caused the problem
as when the timer get called it repeats every 10 seconds. so i change the true --> false on code below. give it a try!
pawn Код:
SetTimerEx( "spectateend", true, 10000, "i", playerid );//means it repeats every 10 seconds
pawn Код:
public OnPlayerDeath(playerid,killerid,reason)
{
    if(killerid != INVALID_PLAYER_ID)
    {
        new szGameTextStr[128];
        new kvehicle =  GetPlayerVehicleID(killerid);
        new killerName[24]; GetPlayerName(killerid, killerName, sizeof killerName);
        //
        if(IsPlayerInAnyVehicle(killerid)) // = player is in vehicle
            return PlayerSpectateVehicle( playerid, kvehicle);
       
        if(!IsPlayerInAnyVehicle(killerid)) // = player is not in vehicle
            return PlayerSpectatePlayer( playerid, killerid );

        format( szGameTextStr, sizeof szGameTextStr, "~w~~n~killCamera~n~~>~Killer: %s ( ID: %i )~<~", killerName, killerid );
        GameTextForPlayer( playerid, szGameTextStr, 10000, 5);
        //
        TogglePlayerSpectating(playerid, 1);
        SetTimerEx( "spectateend", false, 10000, "i", playerid );
    }
    return 1;
}

forward spectateend(playerid);
public spectateend(playerid)
{
    TogglePlayerSpectating(playerid, 0)
    SpawnPlayer(playerid);
    return 1;
}
Reply
#9

Actually I tried with changing the timer but didnt help at all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)