Spec problem
#8

pawn Код:
CMD:spec(playerid, params[])
{
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(!PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
    if(!strcmp(params, "off", true))
    {
        if(Spec[playerid] == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREY, "You aren't spectating anybody.");
        new string[65];
        TogglePlayerSpectating(playerid, 0);
        SetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
        SetPlayerArmour(playerid, PlayerInfo[playerid][pArmor]);
        SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pVW]);
        SetPlayerInterior(playerid, PlayerInfo[playerid][pInt]);
        SetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
        SendClientMessage(playerid, COLOR_WHITE, " You have stopped spectating players.");
        TextDrawHideForPlayer(playerid, Health1);
        TextDrawHideForPlayer(playerid, Money);
        TextDrawHideForPlayer(playerid, Name);
        TextDrawHideForPlayer(playerid, Armour);
        if(PlayerInfo[Spec[playerid]][pAdmin] >= PlayerInfo[playerid][pAdmin])
        {
            format(string, sizeof(string), "SpecWarn: %s has stopped spectating you.", RPN(playerid));
            SendClientMessage(Spec[playerid], COLOR_DARKRED, string);
        }
        Spec[playerid] = INVALID_PLAYER_ID;
        return 1;
    }
    new playerb;
    if(sscanf(params, "u", playerb)) return SendClientMessage(playerid, COLOR_WHITE, "[Usage]: /spec [playerid]");
    if(playerid == playerb) return SendClientMessage(playerid, COLOR_GREY, "You can't spectate yourself.");
    if(!IsPlayerLoggedIn(playerb) || !IsPlayerConnected(playerb) || playerb == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREY, "Invalid player id.");
    if(Spec[playerb] != INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREY, "Player is spectating someone.");
    if(!PlayerInfo[playerb][pTutorial]) SendClientMessage(playerid, COLOR_WHITE, " That player is viewing the tutorial, don't assume he's using hacks yet.");
    PlayerInfo[playerid][pModel] = GetPlayerSkin(playerid);
    new string[65];
    if(Spec[playerid] == INVALID_PLAYER_ID)
    {
        PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(playerid);
        PlayerInfo[playerid][pInt] = GetPlayerInterior(playerid);
        GetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
    }
    Spec[playerid] = playerb;
    TogglePlayerSpectating(playerid, 1);
    SetPlayerInterior(playerid, GetPlayerInterior(playerb));
    SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(playerb));
    format(string, sizeof(string), " Currently spectating %s", RPN(playerb));
    SendClientMessage(playerid, COLOR_WHITE, string);
    TextDrawShowForPlayer(playerid, Health1);
    TextDrawShowForPlayer(playerid, Money);
    TextDrawShowForPlayer(playerid, Name);
    TextDrawShowForPlayer(playerid, Armour);
    if(IsPlayerInAnyVehicle(playerb)) PlayerSpectateVehicle(playerid, GetPlayerVehicleID(playerb));
    else PlayerSpectatePlayer(playerid, playerb);
    if(PlayerInfo[playerb][pAdmin] >= PlayerInfo[playerid][pAdmin])
    {
        format(string, sizeof(string), "SpecWarn: %s is currently spectating you.", RPN(playerid));
        SendClientMessage(playerb, COLOR_DARKRED, string);
    }
    return 1;
}
Also, you are using global textdraws for something that should be kept 'per-player'. So if you have two admins spectating at the same time, you can expect some weird things to happen to the textdraws. What you need to do is create a player textdraw (CreatePlayerTextDraw) which will be created when a player uses spec, and deleted when a player does 'spec off'.

Then you should update the textdraws using either OnPlayerUpdate or the appropriate callbacks depending on the textdraw types. (Eg. updating the money textdraw when you give/take server money rather than doing checks under OnPlayerUpdate)

Unfortunately I don't have your entire code to do this for you, but I can help you through PM further if you'd like. (To prevent you from posting your entire code in this thread)

EDIT: Also, I combined the 'Spec[playerid]' and 'Specid[playerid]' variables into one. This technically doesn't need two variables, because if Specid[playerid] is an invalid player id, that simply means that they are not spectating someone.
Reply


Messages In This Thread
Spec problem - by lulo356 - 17.08.2014, 21:08
Re: Spec problem - by SnG.Scot_MisCuDI - 17.08.2014, 21:11
Re: Spec problem - by lulo356 - 17.08.2014, 21:16
Re: Spec problem - by lulo356 - 17.08.2014, 21:56
Re: Spec problem - by iSkate - 17.08.2014, 22:06
Re: Spec problem - by lulo356 - 17.08.2014, 22:25
Re: Spec problem - by iSkate - 17.08.2014, 22:43
Re: Spec problem - by Threshold - 17.08.2014, 23:02
Re: Spec problem - by lulo356 - 17.08.2014, 23:03

Forum Jump:


Users browsing this thread: 6 Guest(s)