View Single Post
Old 19/08/2019, 11:32 PM   #1
Little Clucker
Join Date: Feb 2019
Posts: 6
Reputation: 0
Question How can I optimize this code?

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

PHP Code:
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

In The Calback Shoot

PHP Code:
public Shoot(playerid)
IsPlayerConnected(i) && !IsPlayerNPC(i)) //IF IT IS CONNECTED AND IT IS NOT A BOOT
IsPlayerInRangeOfPoint(i100.0, -1456.6010,1500.7106,6.9688)) // AND IT'S ON THIS RADIO
barcoeventoss == 1//AND THE EVENT IS ACTIVATED
FCNPC_AimAtPlayer(barco1playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco2playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco3playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco4playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco5playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco6playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco7playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco8playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco9playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco10,playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco11,playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco12,playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco13,playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco14,playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco15,playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco16,playeridtrue, -1true0.00.00.5);
FCNPC_AimAtPlayer(barco17,playeridtrue, -1true0.00.00.5);
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

PHP Code:
#include <FCNPC> 

could you help me? thank you
FacuScript is offline   Reply With Quote