help with /spec command
#1

My /spec is bugged and idk why i tried everything,

When the players on foot its ok but if there in a vehicle it bugs and specs id 0 regardless the id u put :S

pawn Код:
CMD:spec(playerid, params[])
{
    if(pInfo[playerid][Level] < 2) return SendClientMessage(playerid,RED,">> You Must Be Level 2+ To Use This Command!");
    new specid;
    new specvehicleid = GetPlayerVehicleID(specid);
    if(sscanf(params, "U", specid)) return SendClientMessage(playerid,RED, "USAGE: /spec [id]");
    {
        if (specid == INVALID_PLAYER_ID) return SendClientMessage(playerid,RED, ">> Player Not Found!");
        if(IsPlayerInAnyVehicle(specid))//If there in a vehicle do...
        {
            TogglePlayerSpectating(playerid, 1);
            PlayerSpectateVehicle(playerid, specvehicleid);
            SendClientMessage(playerid,YELLOW,">> Spec On!, Use /specoff To Disable Spec!");
        }
        else //if on foot do...
        {
            TogglePlayerSpectating(playerid, 1);
            PlayerSpectatePlayer(playerid, specid);
            SendClientMessage(playerid,YELLOW,">> Spec On!, Use /specoff To Disable Spec!");
        }
    }
    return true;
}
Any help :S

Also will it auto pick up if they enter a vehicle then auto spec vehicle?
Reply
#2

pawn Код:
CMD:spec(playerid, params[])
{
    if(pInfo[playerid][Level] < 2) return SendClientMessage(playerid,RED,">> You Must Be Level 2+ To Use This Command!");
    new specid;
    if(sscanf(params, "U", specid)) return SendClientMessage(playerid,RED, "USAGE: /spec [id]");
    {
        if (specid == INVALID_PLAYER_ID) return SendClientMessage(playerid,RED, ">> Player Not Found!");
        if(IsPlayerInAnyVehicle(specid))//If there in a vehicle do...
        {
            TogglePlayerSpectating(playerid, 1);
            PlayerSpectateVehicle(playerid, GetPlayerVehicleID(specid));
            SendClientMessage(playerid,YELLOW,">> Spec On!, Use /specoff To Disable Spec!");
        }
        else //if on foot do...
        {
            TogglePlayerSpectating(playerid, 1);
            PlayerSpectatePlayer(playerid, specid);
            SendClientMessage(playerid,YELLOW,">> Spec On!, Use /specoff To Disable Spec!");
        }
    }
    return true;
}
The problem was that you assigned the vehicle ID before you actually got a user ID from sscanf. You also created a variable you really didn't need as you can simply use the GetPlayerVehicleID function instead of creating a new variable to store the vehicle ID in which I removed and replaced with usage of the function.
Reply
#3

Ahh i see, Thankyou sir, Much appreciated.
Reply
#4

I had this problem too, solved now!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)