SA-MP Forums Archive
Spec System Help[Rep+] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Spec System Help[Rep+] (/showthread.php?tid=563711)



Spec System Help[Rep+] - HydraHumza - 16.02.2015

Hello Friends can anyone tell me why this function is not safing last pos working


PHP Code:
CMD:spec(playerid,params[]) {
    if(
PlayerInfo[playerid][Helper] == || PlayerInfo[playerid][Level] >= || IsPlayerAdmin(playerid)) {
        if(
isnull(params) || !IsNumeric(params)) return SendClientMessage(playeridred"USAGE: /spec [playerid]");
        new 
specplayerid strval(params);
        if(
IsPlayerConnected(specplayerid) && specplayerid != INVALID_PLAYER_ID) {
        new 
Float:x,Float:y,Float:z;
            if(
specplayerid == playerid) return SendClientMessage(playeridred"ERROR: You cannot spectate yourself");
            if(
GetPlayerState(specplayerid) == PLAYER_STATE_SPECTATING && PlayerInfo[specplayerid][SpecID] != INVALID_PLAYER_ID) return SendClientMessage(playeridred"Spectate: Player spectating someone else");
            if(
GetPlayerState(specplayerid) != && GetPlayerState(specplayerid) != && GetPlayerState(specplayerid) != 3) return SendClientMessage(playeridred"Spectate: Player not spawned");
            if( (
PlayerInfo[specplayerid][Level] != ServerInfo[MaxAdminLevel]) || (PlayerInfo[specplayerid][Level] == ServerInfo[MaxAdminLevel] && PlayerInfo[playerid][Level] == ServerInfo[MaxAdminLevel]) )    {
            if(
PlayerInfo[specplayerid][Level] == ServerInfo[MaxAdminLevel] && PlayerInfo[playerid][Level] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,red,"ERROR: You cannot use this command on this admin");
                 
GetPlayerPos(playerid,x,y,z);
                 
SetPVarFloat(playerid,"xpos",x); 
                   
SetPVarFloat(playerid,"ypos",y);
                   
SetPVarFloat(playerid,"zpos",z);
                 
StartSpectate(playeridspecplayerid);
                 
Spectating[playerid] = 1;
                 for(new 
i=0i<MAX_PLAYERSi++)
                 {
                 if(
Reporter[i] == 1)
                 {
                 
SCM(i,green,"[SERVER] {FFB400}Thanks for Report.An admin is checking your report.");
                 
Reporter[i] = 0;
                 }
                 }
                 new 
str[100];
                 
format(strsizeof(str),"Admin %s has use SPEC on ID %d ."PlayerName2(playerid),specplayerid);
                 
MessageToAdmins(blue,str);
                return 
SendClientMessage(playerid,blue,"Now Spectating");
            } else return 
SendClientMessage(playerid,red,"ERROR: You cannot spectate the highest level admin");
        } else return 
SendClientMessage(playerid,red,"ERROR: Player is not connected");
    } else return 
SendClientMessage(playerid,red,"ERROR: You need to be at least Help Operator to use this command");

PHP Code:
CMD:specoff(playerid,params[]) {
    
#pragma unused params
    
if(PlayerInfo[playerid][Helper] == || PlayerInfo[playerid][Level] >= || IsPlayerAdmin(playerid)) {
        if(
PlayerInfo[playerid][SpecType] != ADMIN_SPEC_TYPE_NONE) {
            
StopSpectate(playerid);
               
SetPlayerPos(playeridGetPVarFloat(playerid,"xpos"), GetPVarFloat(playerid,"ypos"), GetPVarFloat(playerid,"zpos"));
            return 
SendClientMessage(playerid,blue,"No Longer Spectating");
        } else return 
SendClientMessage(playerid,red,"ERROR: You are not spectating");
    } else return 
SendClientMessage(playerid,red,"ERROR: You need to be at least Help Operator to use this command");

Thanks for advance!


Re: Spec System Help[Rep+] - Golimad - 16.02.2015

Use this instead of vars :
Code:
new
	Float:LastPosX[MAX_PLAYERS],
	Float:LastPosY[MAX_PLAYERS],
	Float:LastPosZ[MAX_PLAYERS];
in top of gamemode.

Get position with :
Code:
GetPlayerPos(playerid, LastPosX[playerid], LastPosY[playerid], LastPosZ[playerid]);
Set position with:
Code:
SetPlayerPos(playerid, LastPosX[playerid], LastPosY[playerid], LastPosZ[playerid]);
So :
PHP Code:
new
    
Float:LastPosX[MAX_PLAYERS],
    
Float:LastPosY[MAX_PLAYERS],
    
Float:LastPosZ[MAX_PLAYERS];
CMD:spec(playerid,params[]) { 
    if(
PlayerInfo[playerid][Helper] == || PlayerInfo[playerid][Level] >= || IsPlayerAdmin(playerid)) { 
        if(
isnull(params) || !IsNumeric(params)) return SendClientMessage(playeridred"USAGE: /spec [playerid]"); 
        new 
specplayerid strval(params); 
        if(
IsPlayerConnected(specplayerid) && specplayerid != INVALID_PLAYER_ID) { 
            if(
specplayerid == playerid) return SendClientMessage(playeridred"ERROR: You cannot spectate yourself"); 
            if(
GetPlayerState(specplayerid) == PLAYER_STATE_SPECTATING && PlayerInfo[specplayerid][SpecID] != INVALID_PLAYER_ID) return SendClientMessage(playeridred"Spectate: Player spectating someone else"); 
            if(
GetPlayerState(specplayerid) != && GetPlayerState(specplayerid) != && GetPlayerState(specplayerid) != 3) return SendClientMessage(playeridred"Spectate: Player not spawned"); 
            if( (
PlayerInfo[specplayerid][Level] != ServerInfo[MaxAdminLevel]) || (PlayerInfo[specplayerid][Level] == ServerInfo[MaxAdminLevel] && PlayerInfo[playerid][Level] == ServerInfo[MaxAdminLevel]) )    { 
            if(
PlayerInfo[specplayerid][Level] == ServerInfo[MaxAdminLevel] && PlayerInfo[playerid][Level] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,red,"ERROR: You cannot use this command on this admin"); 
                 
GetPlayerPos(playeridLastPosX[playerid], LastPosY[playerid], LastPosZ[playerid]);
                 
StartSpectate(playeridspecplayerid); 
                 
Spectating[playerid] = 1
                 for(new 
i=0i<MAX_PLAYERSi++) 
                 { 
                 if(
Reporter[i] == 1
                 { 
                 
SCM(i,green,"[SERVER] {FFB400}Thanks for Report.An admin is checking your report."); 
                 
Reporter[i] = 0
                 } 
                 } 
                 new 
str[100]; 
                 
format(strsizeof(str),"Admin %s has use SPEC on ID %d ."PlayerName2(playerid),specplayerid); 
                 
MessageToAdmins(blue,str); 
                return 
SendClientMessage(playerid,blue,"Now Spectating"); 
            } else return 
SendClientMessage(playerid,red,"ERROR: You cannot spectate the highest level admin"); 
        } else return 
SendClientMessage(playerid,red,"ERROR: Player is not connected"); 
    } else return 
SendClientMessage(playerid,red,"ERROR: You need to be at least Help Operator to use this command"); 
}  
CMD:specoff(playerid,params[]) { 
    
#pragma unused params 
    
if(PlayerInfo[playerid][Helper] == || PlayerInfo[playerid][Level] >= || IsPlayerAdmin(playerid)) { 
        if(
PlayerInfo[playerid][SpecType] != ADMIN_SPEC_TYPE_NONE) { 
            
StopSpectate(playerid); 
             
SetPlayerPos(playeridLastPosX[playerid], LastPosY[playerid], LastPosZ[playerid]);
             
SetPlayerInterior(playerid0);
            return 
SendClientMessage(playerid,blue,"No Longer Spectating"); 
        } else return 
SendClientMessage(playerid,red,"ERROR: You are not spectating"); 
    } else return 
SendClientMessage(playerid,red,"ERROR: You need to be at least Help Operator to use this command"); 

if you get any error, please reply.


Re: Spec System Help[Rep+] - HydraHumza - 17.02.2015

Quote:
Originally Posted by Golimad
View Post
Use this instead of vars :
Code:
new
	Float:LastPosX[MAX_PLAYERS],
	Float:LastPosY[MAX_PLAYERS],
	Float:LastPosZ[MAX_PLAYERS];
in top of gamemode.

Get position with :
Code:
GetPlayerPos(playerid, LastPosX[playerid], LastPosY[playerid], LastPosZ[playerid]);
Set position with:
Code:
SetPlayerPos(playerid, LastPosX[playerid], LastPosY[playerid], LastPosZ[playerid]);
So :
PHP Code:
new
    
Float:LastPosX[MAX_PLAYERS],
    
Float:LastPosY[MAX_PLAYERS],
    
Float:LastPosZ[MAX_PLAYERS];
CMD:spec(playerid,params[]) { 
    if(
PlayerInfo[playerid][Helper] == || PlayerInfo[playerid][Level] >= || IsPlayerAdmin(playerid)) { 
        if(
isnull(params) || !IsNumeric(params)) return SendClientMessage(playeridred"USAGE: /spec [playerid]"); 
        new 
specplayerid strval(params); 
        if(
IsPlayerConnected(specplayerid) && specplayerid != INVALID_PLAYER_ID) { 
            if(
specplayerid == playerid) return SendClientMessage(playeridred"ERROR: You cannot spectate yourself"); 
            if(
GetPlayerState(specplayerid) == PLAYER_STATE_SPECTATING && PlayerInfo[specplayerid][SpecID] != INVALID_PLAYER_ID) return SendClientMessage(playeridred"Spectate: Player spectating someone else"); 
            if(
GetPlayerState(specplayerid) != && GetPlayerState(specplayerid) != && GetPlayerState(specplayerid) != 3) return SendClientMessage(playeridred"Spectate: Player not spawned"); 
            if( (
PlayerInfo[specplayerid][Level] != ServerInfo[MaxAdminLevel]) || (PlayerInfo[specplayerid][Level] == ServerInfo[MaxAdminLevel] && PlayerInfo[playerid][Level] == ServerInfo[MaxAdminLevel]) )    { 
            if(
PlayerInfo[specplayerid][Level] == ServerInfo[MaxAdminLevel] && PlayerInfo[playerid][Level] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,red,"ERROR: You cannot use this command on this admin"); 
                 
GetPlayerPos(playeridLastPosX[playerid], LastPosY[playerid], LastPosZ[playerid]);
                 
StartSpectate(playeridspecplayerid); 
                 
Spectating[playerid] = 1
                 for(new 
i=0i<MAX_PLAYERSi++) 
                 { 
                 if(
Reporter[i] == 1
                 { 
                 
SCM(i,green,"[SERVER] {FFB400}Thanks for Report.An admin is checking your report."); 
                 
Reporter[i] = 0
                 } 
                 } 
                 new 
str[100]; 
                 
format(strsizeof(str),"Admin %s has use SPEC on ID %d ."PlayerName2(playerid),specplayerid); 
                 
MessageToAdmins(blue,str); 
                return 
SendClientMessage(playerid,blue,"Now Spectating"); 
            } else return 
SendClientMessage(playerid,red,"ERROR: You cannot spectate the highest level admin"); 
        } else return 
SendClientMessage(playerid,red,"ERROR: Player is not connected"); 
    } else return 
SendClientMessage(playerid,red,"ERROR: You need to be at least Help Operator to use this command"); 
}  
CMD:specoff(playerid,params[]) { 
    
#pragma unused params 
    
if(PlayerInfo[playerid][Helper] == || PlayerInfo[playerid][Level] >= || IsPlayerAdmin(playerid)) { 
        if(
PlayerInfo[playerid][SpecType] != ADMIN_SPEC_TYPE_NONE) { 
            
StopSpectate(playerid); 
             
SetPlayerPos(playeridLastPosX[playerid], LastPosY[playerid], LastPosZ[playerid]);
             
SetPlayerInterior(playerid0);
            return 
SendClientMessage(playerid,blue,"No Longer Spectating"); 
        } else return 
SendClientMessage(playerid,red,"ERROR: You are not spectating"); 
    } else return 
SendClientMessage(playerid,red,"ERROR: You need to be at least Help Operator to use this command"); 

if you get any error, please reply.
Fix Rep+