19.08.2019, 23:32
Let nothing forgive my level of English.
Hi, I have a problem, the problem is that my CPU collapses completely, the CPU where I host my server, after I implement a code ..
I summarize briefly, add 17 NCP, create a couple of variables to activate an event, when the event is activated those players who are close to the position X, Y, Z get them the positions, then the 17 NCPs point and shoot with the updated position of the player, every 1 second ..
When I go alone to the place, the server is washed but it does not collapse, but when 2 or 3 players go in the same place, it is like the code, takes the positions of those 2 or 3 players and applies it to the 17 NCP , if we take accounts would be 17 x 3 = 51 queries per second ..
My server has 1GB RAM, I know very little, but I am also sure that the code can be optimized so that this does not happen.
I show you briefly
In The Calback Shoot
My question is the following, how can I optimize that code? For example, that instead of obtaining the positions of all the players within the radius, it takes only one at random, of all those inside, and that the CPU usage is reduced, how can I optimize this so that the VPS don't collapse me
Include that I am using
could you help me? thank you
Hi, I have a problem, the problem is that my CPU collapses completely, the CPU where I host my server, after I implement a code ..
I summarize briefly, add 17 NCP, create a couple of variables to activate an event, when the event is activated those players who are close to the position X, Y, Z get them the positions, then the 17 NCPs point and shoot with the updated position of the player, every 1 second ..
When I go alone to the place, the server is washed but it does not collapse, but when 2 or 3 players go in the same place, it is like the code, takes the positions of those 2 or 3 players and applies it to the 17 NCP , if we take accounts would be 17 x 3 = 51 queries per second ..
My server has 1GB RAM, I know very little, but I am also sure that the code can be optimized so that this does not happen.
I show you briefly
PHP Code:
if(eventobarco == 0) // TIME FOR START OF EVENT, LOCATED WITHIN CALLBACK
{
Update3DTextLabelText(barcoevento,COLOR_WHITE,"{00CC00}Estado: ACTIVO\n{FFFFFF}Faltan 10 MIN para finalizar");
barcoeventoss = 1;
tiemporestante = 10;
SetTimer("tiempodeevento",60000,false); //TIMER COMMAND FOR THE UPDATE OF TIME
SetTimer("Shoot",1000,false); //HERE IS THE IMPORTANT, CALL THE CALLBACK SHOOT IN 1 SECOND
}
return 1;
PHP Code:
public Shoot(playerid)
{
new Float:X,Float:Y,Float:Z;
for(new i = 0; i < MAX_PLAYERS; i++) //ALL PLAYERS CONNECTED
{
if(IsPlayerConnected(i) && !IsPlayerNPC(i)) //IF IT IS CONNECTED AND IT IS NOT A BOOT
{
if(IsPlayerInRangeOfPoint(i, 100.0, -1456.6010,1500.7106,6.9688)) // AND IT'S ON THIS RADIO
{
if(barcoeventoss == 1) //AND THE EVENT IS ACTIVATED
{
GetPlayerPos(i,X,Y,Z); // OBTAINS THE POSITIONS OF ALL WHO ARE WITHIN THE RADIO
//APPLY THIS AT 17 NCP
FCNPC_AimAtPlayer(barco1, playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco2, playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco3, playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco4, playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco5, playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco6, playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco7, playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco8, playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco9, playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco10,playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco11,playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco12,playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco13,playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco14,playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco15,playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco16,playerid, true, -1, true, 0.0, 0.0, 0.5);
FCNPC_AimAtPlayer(barco17,playerid, true, -1, true, 0.0, 0.0, 0.5);
}
SetTimer("Shoot",1500,false); // SEND A TIMER OF 1 SECOND AND THE FUNCTION IS REPEATED
Include that I am using
PHP Code:
#include <FCNPC>