Spec saving off
#1

Im here for another problem, im trying to save the current admin position while doing /spec, and setting him to the saved position with /specoff, but doesn't work. I get respawned as normal..

pawn Код:
CMD:spec(playerid, params[])
{
    if(pInfo[playerid][Logged] == 0) return SCM(playerid,0x0080C0FF,"Please login before using this command.");
    if(pInfo[playerid][Admin] >= 1)
    {
        new targetid;
        if(sscanf(params,"u", targetid)) return SendClientMessage(playerid, -1, "{F70505}Usage: {FFFFFF}/spec [playerid]");
        {
            if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, red, "SERVER: Player not connected");
            new Float:xpoz,Float:ypoz,Float:zpoz;
            GetPlayerPos(playerid,xpoz,ypoz,zpoz);
            SetPVarFloat(playerid,"XPos",xpoz); SetPVarFloat(playerid,"YPos",ypoz); SetPVarFloat(playerid,"ZPos",zpoz);
            new string[150];
            new sstring[250];
            new pname[24];
            GetPlayerName(targetid,pname,24);
            new Float:gihp, Float:giar;
            GetPlayerHealth(targetid, gihp);
            GetPlayerArmour(targetid, giar);
            TogglePlayerSpectating(playerid, 1);
            if(IsPlayerInAnyVehicle(targetid))
            {
                new vehicleid = GetPlayerVehicleID(targetid);
                PlayerSpectateVehicle(playerid, vehicleid);
            }
            else
            {
                PlayerSpectatePlayer(playerid, targetid);
                SetPlayerInterior(playerid,GetPlayerInterior(targetid));
            }
            format(string, sizeof(string), "** You are now spectating %s (%d) - Type /specoff when you're done.", pname, targetid, GetPlayerPing(targetid));
            format(sstring, sizeof(sstring), "** Ping: %d - Money: %i - Health: %0.1f - Armour: %0.1f", GetPlayerPing(targetid),GetPlayerMoney(targetid),gihp,giar);
            SendClientMessage(playerid, 0x0080C0FF, string);
            SendClientMessage(playerid, 0x0080C0FF, sstring);
        }
    }
    else SendClientMessage(playerid, red, "You do not have access to this command!");
    return 1;
}

CMD:specoff(playerid, params[])
{
    if(pInfo[playerid][Logged] == 0) return SCM(playerid,0x0080C0FF,"Please login before using this command.");
    if(pInfo[playerid][Admin] >= 1)
    {
        SetPlayerPosEx(playerid, GetPVarFloat(playerid,"XPos"), GetPVarFloat(playerid,"YPos"), GetPVarFloat(playerid,"ZPos"));
        TogglePlayerSpectating(playerid, 0);
        SendClientMessage(playerid, red, "INFO: You have cancelled spectating.");
        SetPlayerInterior(playerid, 0);
    }
    else SendClientMessage(playerid, red, "You do not have access to this command!");
    return 1;
}
Reply
#2

pawn Код:
// specoff command, remove SetPlayerPosEx here
// OnPlayerSpawn gets called if spectating is turned off (source: wiki)
TogglePlayerSpectating(playerid, 0);
pawn Код:
//OnPlayerSpawn
if(GetPVarType(playerid, "XPos")) { // check if the variable exists
    SetPlayerPosEx(playerid, GetPVarFloat(playerid,"XPos"), GetPVarFloat(playerid,"YPos"), GetPVarFloat(playerid,"ZPos"));
    DeletePVar(playerid, "XPos");
    return true;
}
Reply
#3

It works but i got another problem, when setting old player pos after using /specoff, the rest of code of OnPlayerSpawn doesn't get called. I bet the problem is in "return true;" that stops code from executing. Should i remove it?
Reply
#4

Should have gone to specsavers.

Yes - return will stop the code below it from being executed.
Reply
#5

Nothing, doesn't work. I tried removing "return true;" and editing the code in this way:

pawn Код:
if(GetPVarType(playerid, "SXPos")) return SetPlayerPosEx(playerid, GetPVarFloat(playerid,"SXPos"), GetPVarFloat(playerid,"SYPos"), GetPVarFloat(playerid,"SZPos")), DeletePVar(playerid, "SXPos");
But i get spawned as normal, plus other OnPlayerSpawn code doesn't execute.
Reply
#6

It need to look like that

pawn Код:
if(GetPVarType(playerid, "XPos")) {
    SetPlayerPosEx(playerid, GetPVarFloat(playerid,"XPos"), GetPVarFloat(playerid,"YPos"), GetPVarFloat(playerid,"ZPos"));
    DeletePVar(playerid, "XPos");
} else {
    // Your normal spawn code
}
// rest of your code (not spawn related)
Reply
#7

Same problem. As normal, when respawn, the server will give weapons and some messages, this doesn't happen. Here is whole OnPlayerSpawn:

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(GetPVarType(playerid, "SXPos"))
    {
    SetPlayerPosEx(playerid, GetPVarFloat(playerid,"SXPos"), GetPVarFloat(playerid,"SYPos"), GetPVarFloat(playerid,"SZPos"));
    DeletePVar(playerid, "XPos");
    }
    else
    {
    SetRank3DText(playerid);
    PlayerPlaySound(playerid,1063,0.0,0.0,0.0);
    SetPlayerHealth(playerid, 97);
    pSpawned[playerid] = 1;
    pAlive[playerid] = 1;
    IsTakingOverTurf[playerid] = 0;
    pSkProtected[playerid] = 1;
    SetPlayerHealth(playerid, FLOAT_INFINITY);
    ASkTimer[playerid] = SetTimerEx("AntiSpawnkill",10000,0,"i",playerid);
    SetTimerEx("PlayerUnfrozen", 3000, false, "i", playerid);
    TogglePlayerControllable(playerid, 0);
    SCM(playerid,red,"* You are freezed for 3 seconds and in godmode for 10.");
   
    GangZoneShowForPlayer(playerid, UsaGangzone, COLOR_BLUE);
    GangZoneShowForPlayer(playerid, GermanyZone, COLOR_RED);
    GangZoneShowForPlayer(playerid, RussianZone, COLOR_ORANGE);
    GangZoneShowForPlayer(playerid, JapanZone, COLOR_LIGHTGREEN);
    GangZoneShowForPlayer(playerid, MercenaryZone, COLOR_INDIGO);
   
    TextDrawShowForPlayer(playerid, KillsTxd[playerid]);
    TextDrawShowForPlayer(playerid, DeathsTxd[playerid]);
    TextDrawShowForPlayer(playerid, RankTxd[playerid]);
    TextDrawShowForPlayer(playerid, KSTxd[playerid]);
    TextDrawShowForPlayer(playerid, CookiesTxd[playerid]);
    TextDrawShowForPlayer(playerid, ClassTxd[playerid]);
   
    if(pInfo[playerid][Admin] >= 1)
    {
    TextDrawShowForPlayer(playerid, ShopTxd[playerid]);
    TextDrawShowForPlayer(playerid, ReportedTxd[playerid]);
    TextDrawShowForPlayer(playerid, RegTxd[playerid]);
    TextDrawShowForPlayer(playerid, PausedTxd[playerid]);
    TextDrawShowForPlayer(playerid, PmTxd[playerid]);
    TextDrawShowForPlayer(playerid, AdminEchoTxd[playerid]);
    }

    TextDrawShowForPlayer(playerid, Star[0]);
    TextDrawShowForPlayer(playerid, Star[1]);
    TextDrawShowForPlayer(playerid, Star[2]);
    TextDrawShowForPlayer(playerid, CmdsTxd);

    RankArmour(playerid);
    CheckForLevelUpdate(playerid);
   
    if(gTeam[playerid] == TEAM_USA)
    {
        SetRandomUSAPos(playerid);
        TextDrawHideForPlayer(playerid,MercTxd);
        TextDrawShowForPlayer(playerid,UsaTxd);
        TextDrawHideForPlayer(playerid,GermanyTxd);
        TextDrawHideForPlayer(playerid,RussianTxd);
        TextDrawHideForPlayer(playerid,JapanTxd);
        UsaWeps(playerid);
        WindowForPlayer(playerid, "You have ~y~spawned ~w~as ~r~Usa Team.");
    }

    if(gTeam[playerid] == TEAM_GERMANY)
    {
        SetRandomGERPos(playerid);
        TextDrawHideForPlayer(playerid,MercTxd);
        TextDrawShowForPlayer(playerid, GermanyTxd);
        TextDrawHideForPlayer(playerid,UsaTxd);
        TextDrawHideForPlayer(playerid,RussianTxd);
        TextDrawHideForPlayer(playerid,JapanTxd);
        GermanyWeps(playerid);
        WindowForPlayer(playerid, "You have ~y~spawned ~w~as ~r~Germany Team.");
    }

    if(gTeam[playerid] == TEAM_RUSSIA)
    {
        SetRandomRUSPos(playerid);
        TextDrawHideForPlayer(playerid,MercTxd);
        TextDrawShowForPlayer(playerid, RussianTxd);
        TextDrawHideForPlayer(playerid,GermanyTxd);
        TextDrawHideForPlayer(playerid,JapanTxd);
        TextDrawHideForPlayer(playerid,UsaTxd);
        RussianWeps(playerid);
        WindowForPlayer(playerid, "You have ~y~spawned ~w~as ~r~Russia Team.");
    }

    if(gTeam[playerid] == TEAM_JAPAN)
    {
        SetRandomJAPPos(playerid);
        TextDrawHideForPlayer(playerid,MercTxd);
        TextDrawShowForPlayer(playerid, JapanTxd);
        TextDrawHideForPlayer(playerid,GermanyTxd);
        TextDrawHideForPlayer(playerid,RussianTxd);
        TextDrawHideForPlayer(playerid,UsaTxd);
        JapanWeps(playerid);
        WindowForPlayer(playerid, "You have ~y~spawned ~w~as ~r~Japan Team.");
    }
   
    if(gTeam[playerid] == TEAM_MERCENARY)
    {
        SetRandomMERCENARYPos(playerid);
        TextDrawShowForPlayer(playerid, MercTxd);
        TextDrawHideForPlayer(playerid,UsaTxd);
        TextDrawHideForPlayer(playerid,GermanyTxd);
        TextDrawHideForPlayer(playerid,RussianTxd);
        TextDrawHideForPlayer(playerid,JapanTxd);
        MercenaryWeps(playerid);
        WindowForPlayer(playerid, "You have ~y~spawned ~w~as ~r~Mercenary Team.");
    }

    if(pInfo[playerid][Jailed] == 1 && pInfo[playerid][Logged] == 1)
    {
    SetTimerEx("JailRes", 3000, false, "i", playerid);
    }

    SetPlayerInterior(playerid,0);
    SetPlayerVirtualWorld(playerid,0);

    ClearAnimations(playerid);

    SetPlayerToTeamColour(playerid);
    SettingPlayerTeam();
    }
    return 1;
}
Reply
#8

pawn Код:
public OnPlayerSpawn(playerid)
{
    SetRank3DText(playerid);
    PlayerPlaySound(playerid,1063,0.0,0.0,0.0);
    SetPlayerHealth(playerid, 97);
    pSpawned[playerid] = 1;
    pAlive[playerid] = 1;
    IsTakingOverTurf[playerid] = 0;
    pSkProtected[playerid] = 1;
    SetPlayerHealth(playerid, FLOAT_INFINITY);
    ASkTimer[playerid] = SetTimerEx("AntiSpawnkill",10000,0,"i",playerid);
    SetTimerEx("PlayerUnfrozen", 3000, false, "i", playerid);
    TogglePlayerControllable(playerid, 0);
    SCM(playerid,red,"* You are freezed for 3 seconds and in godmode for 10.");
   
    GangZoneShowForPlayer(playerid, UsaGangzone, COLOR_BLUE);
    GangZoneShowForPlayer(playerid, GermanyZone, COLOR_RED);
    GangZoneShowForPlayer(playerid, RussianZone, COLOR_ORANGE);
    GangZoneShowForPlayer(playerid, JapanZone, COLOR_LIGHTGREEN);
    GangZoneShowForPlayer(playerid, MercenaryZone, COLOR_INDIGO);
   
    TextDrawShowForPlayer(playerid, KillsTxd[playerid]);
    TextDrawShowForPlayer(playerid, DeathsTxd[playerid]);
    TextDrawShowForPlayer(playerid, RankTxd[playerid]);
    TextDrawShowForPlayer(playerid, KSTxd[playerid]);
    TextDrawShowForPlayer(playerid, CookiesTxd[playerid]);
    TextDrawShowForPlayer(playerid, ClassTxd[playerid]);
   
    if(pInfo[playerid][Admin] >= 1)
    {
        TextDrawShowForPlayer(playerid, ShopTxd[playerid]);
        TextDrawShowForPlayer(playerid, ReportedTxd[playerid]);
        TextDrawShowForPlayer(playerid, RegTxd[playerid]);
        TextDrawShowForPlayer(playerid, PausedTxd[playerid]);
        TextDrawShowForPlayer(playerid, PmTxd[playerid]);
        TextDrawShowForPlayer(playerid, AdminEchoTxd[playerid]);
    }
    TextDrawShowForPlayer(playerid, Star[0]);
    TextDrawShowForPlayer(playerid, Star[1]);
    TextDrawShowForPlayer(playerid, Star[2]);
    TextDrawShowForPlayer(playerid, CmdsTxd);

    RankArmour(playerid);
    CheckForLevelUpdate(playerid);

    if(pInfo[playerid][Jailed] == 1 && pInfo[playerid][Logged] == 1)
    {
        SetTimerEx("JailRes", 3000, false, "i", playerid);
    }
    SetPlayerInterior(playerid,0);
    SetPlayerVirtualWorld(playerid,0);

    ClearAnimations(playerid);

    if(GetPVarType(playerid, "SXPos"))
    {
        SetPlayerPosEx(playerid, GetPVarFloat(playerid,"SXPos"), GetPVarFloat(playerid,"SYPos"), GetPVarFloat(playerid,"SZPos"));
        DeletePVar(playerid, "XPos");
    } else {
        switch(gTeam[playerid])
        {
            case TEAM_USA:
            {
                SetRandomUSAPos(playerid);
                TextDrawHideForPlayer(playerid,MercTxd);
                TextDrawShowForPlayer(playerid,UsaTxd);
                TextDrawHideForPlayer(playerid,GermanyTxd);
                TextDrawHideForPlayer(playerid,RussianTxd);
                TextDrawHideForPlayer(playerid,JapanTxd);
                UsaWeps(playerid);
                WindowForPlayer(playerid, "You have ~y~spawned ~w~as ~r~Usa Team.");
            }
            case TEAM_GERMANY:
            {
                SetRandomGERPos(playerid);
                TextDrawHideForPlayer(playerid,MercTxd);
                TextDrawShowForPlayer(playerid, GermanyTxd);
                TextDrawHideForPlayer(playerid,UsaTxd);
                TextDrawHideForPlayer(playerid,RussianTxd);
                TextDrawHideForPlayer(playerid,JapanTxd);
                GermanyWeps(playerid);
                WindowForPlayer(playerid, "You have ~y~spawned ~w~as ~r~Germany Team.");
            }
            case TEAM_RUSSIA:
            {
                SetRandomRUSPos(playerid);
                TextDrawHideForPlayer(playerid,MercTxd);
                TextDrawShowForPlayer(playerid, RussianTxd);
                TextDrawHideForPlayer(playerid,GermanyTxd);
                TextDrawHideForPlayer(playerid,JapanTxd);
                TextDrawHideForPlayer(playerid,UsaTxd);
                RussianWeps(playerid);
                WindowForPlayer(playerid, "You have ~y~spawned ~w~as ~r~Russia Team.");
            }
            case TEAM_JAPAN:
            {
                SetRandomJAPPos(playerid);
                TextDrawHideForPlayer(playerid,MercTxd);
                TextDrawShowForPlayer(playerid, JapanTxd);
                TextDrawHideForPlayer(playerid,GermanyTxd);
                TextDrawHideForPlayer(playerid,RussianTxd);
                TextDrawHideForPlayer(playerid,UsaTxd);
                JapanWeps(playerid);
                WindowForPlayer(playerid, "You have ~y~spawned ~w~as ~r~Japan Team.");
            }
            case TEAM_MERCENARY:
            {
                SetRandomMERCENARYPos(playerid);
                TextDrawShowForPlayer(playerid, MercTxd);
                TextDrawHideForPlayer(playerid,UsaTxd);
                TextDrawHideForPlayer(playerid,GermanyTxd);
                TextDrawHideForPlayer(playerid,RussianTxd);
                TextDrawHideForPlayer(playerid,JapanTxd);
                MercenaryWeps(playerid);
                WindowForPlayer(playerid, "You have ~y~spawned ~w~as ~r~Mercenary Team.");
            }
        }
    }
    SetPlayerToTeamColour(playerid);
    SettingPlayerTeam();
    return true;
}
Reply
#9

Lol same. Now is worst, even if i normally spawn i don't get the weapons and other stuff.
Reply
#10

Try again, I moved SetPlayerToTeamColour(playerid) and SettingPlayerTeam() down again
The function SettingPlayerTeam is probably badly named and doesnt set the team of the player...

Although if you wrote you code you should know what the problem is because you know what the function does
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)