24.08.2016, 12:02
(
Последний раз редактировалось Tass007; 28.08.2016 в 09:34.
)
REMOVED
CMD:afk(playerid,params[])// /afk command { new string[128];// Store the intial action if(IsAFK[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "Error: You are already AFK."); else // And why using else while the "return" already breaks the code? { format(string,sizeof(string),"*%s has gone AFK",GetName(playerid));//Formats the /do cmd output IsAFK[playerid] = 1; SendClientMessageToAll(COLOR_WHITE,string);//Display the output to all clients } return 1; }
CMD:back(playerid,params[])// /back command { new string[128];// Store the intial action if(IsAFK[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "Error: You aren't AFK."); format(string,sizeof(string),"*%s is back",GetName(playerid));//Formats the /do cmd output IsAFK[playerid] = 0; SendClientMessageToAll(COLOR_WHITE,string);//Display the output to all clients return 1; }
forward AFKCheck(); public AFKCheck() // And another huge mistake, you are not checking if the players are online are not,imagine what if there are 10 players playing on a 1000 slots server { new Float:Pos[3] /* Arrays are slower than variables,it should be "new Float:x, Float:y, Float:z"*/, string[128]; // creating an array variable of 3 values whose datatype is Float. for(new i = 0; i < MAX_PLAYERS; i++) // Looping through the players. { if(IsAFK[i] == 1) return 1; //Checks to see if the player is already AFK GetPlayerPos(i,Pos[0],Pos[1],Pos[2]); // Gets the player position and saves into their variables. if(IsPlayerInRangeOfPoint(i,2,Pos[0],Pos[1],Pos[2])) // If player is around the position (if player is at the same place) { AFK[i]++; // Increment the AFK variable (for every second if player is at same location, increase the AFK variable by 1) } if(AFK[i] == SetAFKTime) // Checking to see how long the player has been in the same place, if the varible (AFK) matches (SetAFKTime) it sets the player AFK. { format(string,sizeof(string),"*%s has gone AFK",GetName(i));//Formats the /do cmd output SendClientMessageToAll(COLOR_WHITE,string); IsAFK[i] = 1; } } return 1; }