Spectate Update Strings not Updating
#1

Ok guys, I need a bit of help here, i'm not understanding why the textdraw strings are not updating. Basically the textdraw shown to the player should show the player who he is spectating's health and armour. It works fine, but the problem is that it is not updating. The SpectateUpdatePlayer callback is not being called- only once. Maybe i've made a simple mistake.

Thanks.


Somewhere:

pawn Код:
new SpectateUpdateTimer[MAX_SERVER_PLAYERS];
pawn Код:
zcmd(spec, playerid, params[])
{
    new specid;
    if (!sscanf(params, "u", specid))
    {
        if(!IsPlayerConnected(specid)) return SendClientMessage(playerid, AAD_COLOR_GREY, "* That player is not connected.");
      //if(specid == playerid) return SendClientMessage(playerid, red, "ERROR: You cannot spectate yourself");
        if(GetPlayerState(specid) == PLAYER_STATE_SPECTATING && gSpectateID[specid] != INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "Spectate: Player spectating someone else");
        if(Player[playerid][pPlaying] == true && Player[playerid][pTeam] != T_REF) return SendClientMessage(playerid, AAD_COLOR_GREY, "* You can only spectate if you are not in a round.");
        if(GetPlayerState(specid) != 1 && GetPlayerState(specid) != 2 && GetPlayerState(specid) != 3) return SendClientMessage(playerid, AAD_COLOR_GREY, "* Player not spawned");
        if(Player[specid][pTeam] != Player[playerid][pTeam] && Player[playerid][pTeam] != T_REF) return SendClientMessage(playerid, AAD_COLOR_GREY, "* You can only spectate your own team.");
        StartSpectate(playerid, specid);
    }
    else SendClientMessage(playerid, AAD_COLOR_GREY, "USAGE: /spec [playerid/PartofName]");
    return 1;
}
pawn Код:
stock StartSpectate(playerid,specid)
{
    for(new x=0; x<MAX_SERVER_PLAYERS; x++)
    {
        if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && gSpectateID[x] == playerid)
        {
            AdvanceSpectate(x);
        }
    }
    if(IsPlayerInAnyVehicle(specid))
    {
        TogglePlayerSpectating(playerid, 1);
        SetPlayerInterior(playerid,GetPlayerInterior(specid));
        PlayerSpectateVehicle(playerid, GetPlayerVehicleID(specid));
        gSpectateID[playerid] = specid;
        gSpectateType[playerid] = SPECTATE_TYPE_VEHICLE;
    }
    else
    {
      SetPlayerInterior(playerid,GetPlayerInterior(specid));
        TogglePlayerSpectating(playerid, 1);
        PlayerSpectatePlayer(playerid, specid);
        gSpectateID[playerid] = specid;
        gSpectateType[playerid] = SPECTATE_TYPE_PLAYER;
    }
    gSpectating[playerid] = true;
    SendClientMessage(playerid,AAD_COLOR_LIMEGREEN,">> START spectated called");
    //SpectateUpdateTimer[playerid] = SetTimerEx("SpectateUpdatePlayer", 2000, false, "i", playerid);
    SpectateUpdatePlayer(playerid);
    return 1;
}
pawn Код:
SpectateUpdatePlayer(playerid)
{
  //FunctionLog("SpectateUpdatePlayer");
    new SM_PNstring [128];
    new specname[MAX_PLAYER_NAME];
    GetPlayerName(gSpectateID[playerid],specname,sizeof(specname));
    format(SM_PNstring,128,"Spectating: ~p~%s",specname);
    TextDrawSetString(SM_PN, SM_PNstring);
    TextDrawShowForPlayer(playerid, SM_PN);

    new SM_HAstring [256];
    new Float:armour, Float:Health;
    GetPlayerHealth(gSpectateID[playerid],Health);
    GetPlayerArmour(gSpectateID[playerid], armour);
    format(SM_HAstring,sizeof(SM_HAstring),"~r~Health: %.0f ~b~Armour: %.0f",Health, armour);
    TextDrawSetString(SM_HA, SM_HAstring);
    TextDrawShowForPlayer(playerid, SM_HA);

    TextDrawShowForPlayer(playerid, SM_Team);
    TextDrawHideForPlayer(playerid, CurrentTeamsTD);

    new SM_IDstring [128];
    format(SM_IDstring,sizeof(SM_IDstring),"Spectate ID: %d",gSpectateID[playerid]);
    TextDrawSetString(SM_ID, SM_IDstring);
    TextDrawShowForPlayer(playerid, SM_ID);

    TextDrawShowForPlayer(playerid, SM_BBar);
    spectating[playerid] = 1;
    SendClientMessage(playerid,AAD_COLOR_LIMEGREEN,">> SpectateUpdatePlayer Called");
    SpectateUpdateTimer[playerid] = SetTimerEx("SpectateUpdatePlayer", 2000, false, "i", playerid);
    SendClientMessage(playerid,AAD_COLOR_LIMEGREEN,">> Timer Set to Update");
}
Reply
#2

I'm not sure, but maybe return 1; under StartSpectate stops the process?
Reply
#3

Quote:
Originally Posted by SpiderPork
I'm not sure, but maybe return 1; under StartSpectate stops the process?
Just tested that, but that makes no difference. Still need help. I know i've made a simple mistake somewhere. Any help is appreciated.
Reply
#4

I see you're using "SpectateUpdatePlayer" as a timer. Timers must be public and forwarded.
Reply
#5

Quote:
Originally Posted by Don Correlli
I see you're using "SpectateUpdatePlayer" as a timer. Timers must be public and forwarded.
Thank you Don Corelli it works! I could come and kiss u. I feel a bit stupid for forgetting that - I knew i had made a simple mistake.

Future Note to anyone: the strings don't update if you are spectating yourself, your health/armour doesn't actually change even if you set ur own health.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)