View Single Post
Old 20/08/2019, 12:44 AM   #2
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,193
Reputation: 420
Default Re: [HELP] How can I optimize this code?

pawn Code:
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);

This can be shortened down by creating one variable with an array,

for example, instead of doing barco1,2,3,3 etc
you can do this:

pawn Code:
new barco[17];

Then do
pawn Code:
for(new i; i < 17; i++)
{
    FCNPC_AimAtPlayer(barco[i], playerid, true, -1, true, 0.0, 0.0, 0.5);
}

it's exactly the same thing basically. Then use later on your script barco[0] and barco[1] etc instead of creating 17 variables
__________________
Quote:
Originally Posted by Andy
My anti cheat is still relevant *puts shades on* https://github.com/RogueDrifter/Anti_cheat_pack

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link

RogueDrifter is offline   Reply With Quote