new TimeRespawn;
CMD:respawncall(playerid)
{
if(pAccount[playerid][pAdmin] < ADMIN) return ErrorMsg(playerid, _, false);
TimeRespawn = gettime()+20;
SetTimer("AllVehicleRespawn", 5000, false);
AdminMessage(playerid, "Vous avez dйmarrй le respawn de tous les vйhicules.");
SendMessageToAdmins(RED, "%s a dйmarrй le respawn de tous les vйhicules.", GetName(playerid));
ServeurAnnonce(_, "20 secondes avant le respawn de tous les vйhicules.");
return 1;
}
PUBLIC:AllVehicleRespawn()
{
if(TimeRespawn - gettime() > 13)
{
ServeurAnnonce(_, "15 secondes avant le respawn de tous les vйhicules.");
// 15 seconds before every vehicle's respawn.
SetTimer("AllVehicleRespawn", 5000, false);
return 1;
}
else if(TimeRespawn - gettime() > 9)
{
ServeurAnnonce(_, "10 secondes avant le respawn de tous les vйhicules.");
SetTimer("AllVehicleRespawn", 5000, false);
return 1;
}
else if(TimeRespawn - gettime() > 4)
{
ServeurAnnonce(_, "5 secondes avant le respawn de tous les vйhicules.");
SetTimer("AllVehicleRespawn", 5000, false);
return 1;
}
ServeurAnnonce(_, "Tous les vйhicules ont йtй respawn par un administrateur.");
for(new i; i < GetVehiclePoolSize()+1; i++)
{
SetVehicleToRespawn(i);
}
return 1;
}
for(new i, j=GetVehiclePoolSize(); i <= j; i++)
{
if(GetVehicleDriver(i) == INVALID_PLAYER_ID) SetVehicleToRespawn(i);
}
First optimization is your loop, it's calling GetVehiclePoolSize at every iteration.
And a little (mistake or it's mean't to be like that?), it will respawn also used vehicles which will be annoying to players. PHP Code:
|
PUBLIC:AllVehicleRespawn()
{
if(TimeRespawn - gettime() > 13)
{
ServeurAnnonce(_, "15 secondes avant le respawn de tous les vйhicules.");
SetTimer("AllVehicleRespawn", 5000, false);
return 1;
}
else if(TimeRespawn - gettime() > 9)
{
ServeurAnnonce(_, "10 secondes avant le respawn de tous les vйhicules.");
SetTimer("AllVehicleRespawn", 5000, false);
return 1;
}
else if(TimeRespawn - gettime() > 4)
{
ServeurAnnonce(_, "5 secondes avant le respawn de tous les vйhicules.");
SetTimer("AllVehicleRespawn", 5000, false);
return 1;
}
ServeurAnnonce(_, "Tous les vйhicules ont йtй respawn par un administrateur.");
for(new i, j = GetVehiclePoolSize(); i <= j; i++)
{
if(GetVehicleDriver(i) == INVALID_PLAYER_ID) SetVehicleToRespawn(i);
}
return 1;
}
GetVehicleDriver(vehicleid)
{
foreach(new i : Player)
{
if(GetPlayerVehicleID(i) == vehicleid) return i;
}
return INVALID_PLAYER_ID;
}
// command: /respawncall
SetTimerEx("AllVehicleRespawn", 5000, false, "i", 20);
// callback: AllVehicleRespawn(interval)
if ((interval -= 5))
{
ServeurAnnonce(_, "%i secondes avant le respawn de tous les vйhicules.", interval);
SetTimerEx("AllVehicleRespawn", 5000, false, "i", interval);
}
else
{
// inform players and respawn vehicles..
}
And there are betters ways to check if the vehicle is not occupied because you keep calling player-loops. A method I liked is a vehicle-array and you loop through all players. Set the index (what GetPlayerVehicleID returns) to 1 and then respawn those which were set to 1.
|
RespawnVehicles()
{
new bool: occupied_vehicle[MAX_VEHICLES char], vehicleid;
foreach(new i : Player)
{
if ((vehicleid = GetPlayerVehicleID(i)))
{
occupied_vehicle{vehicleid} = true;
occupied_vehicle{GetVehicleTrailer(vehicleid)} = true;
}
}
foreach(new v : Vehicle)
{
if (!occupied_vehicle{v}) SetVehicleToRespawn(v);
}
}
Sorry, my mistake "..those which were not set to 1".
I actually wrote a function yesterday that is supposed to respawn the vehicles which are not occupied (trailers that are attached to occupied vehicles won't respawn either). Just make sure that you are up-to-date to YSI for the "Vehicle" iterator: pawn Code:
|
Weren't you using YSI 4 before? I'm not sure if changes have been done in y_va include since then but if you post few parts of the lines that give the errors/warnings, I can look into.
I use an edited version of foreach as standalone but this looks okay. |
#include "YSI\y_colours"
Why don't you move everything from YSI-Includes-YSI.tl folder to pawno\include folder so it will be easier to just:
pawn Код:
|
#include "..\YSI_Internal\y_compilerpass"
#if AUTO_INCLUDE_GUARD
#undef _inc_y_colours
#endif
#include "..\YSI_Server\y_colours"
[COLOR NAME] is defined in y_colours (YSI 4.0)
I don't get why you define your own colors, when you already have that included. Just use X11_COLOR for integers, and COLOR for embedded. |
CMD:respawncall(playerid, params[])
{
if(pAccount[playerid][pAdmin] < ADMIN) return ErrorMsg(playerid, _, false);
new time;
if(sscanf(params, "I(20)", time)) return SCM(playerid, LBLUE, "/respawncall [temps avant respawn]");
if(RespawnAllVehicle != -1)
{
ServeurAnnonce(_, "Le respawn des vйhicules a йtй annulй par un administrateur.");
SendMessageToAdmins(ARED, "%s a annulй le respawn des vйhicules", GetName(playerid));
KillTimer(RespawnAllVehicle);
RespawnAllVehicle = -1;
return 1;
}
RespawnAllVehicle = SetTimerEx("AllVehicleRespawn", 5000, false, "i", time);
AdminMessage(playerid, "Vous avez dйmarrй le respawn de tous les vйhicules.");
SendMessageToAdmins(ARED, "%s a dйmarrй le respawn de tous les vйhicules.", GetName(playerid));
ServeurAnnonce(_, "%i secondes avant le respawn de tous les vйhicules.", time);
return 1;
}
PUBLIC:AllVehicleRespawn(interval)
{
if((interval -= 5) > 0)
{
ServeurAnnonce(_, "%i secondes avant le respawn de tous les vйhicules.", interval);
RespawnAllVehicle = SetTimerEx("AllVehicleRespawn", 5000, false, "i", interval);
return 1;
}
KillTimer(RespawnAllVehicle);
RespawnAllVehicle = -1;
ServeurAnnonce(_, "Tous les vйhicules ont йtй respawn par un administrateur.");
RespawnVehicles();
return 1;
}
RespawnVehicles()
{
new bool: occupied_vehicle[MAX_VEHICLES char], vehicleid;
foreach(new i : Player)
{
if ((vehicleid = GetPlayerVehicleID(i)) != 0)
{
occupied_vehicle{vehicleid} = true;
occupied_vehicle{GetVehicleTrailer(vehicleid)} = true;
}
}
foreach(new v : Vehicle)
{
if (!occupied_vehicle{v}) SetVehicleToRespawn(v);
}
}
DecimalBase10toDecimalBase2(Float:number)
{
new
Float:decimal = 1 - (floatround(number, floatround_ceil) - number),
entier = floatround(number - decimal),
binary[20 + EOS],
rest;
for(new i; i != 8; i++)
{
decimal *= 2.00;
if(decimal > 1.00)
{
decimal -= 1.00;
format(binary, sizeof(binary), "%s1", binary);
}
else
format(binary, sizeof(binary), "%s0", binary);
}
format(binary, sizeof(binary), ".%s", binary);
do
{
rest = entier % 2;
entier /= 2;
if(rest > 0)
format(binary, sizeof(binary), "1%s", binary);
else
format(binary, sizeof(binary), "0%s", binary);
}
while(entier > 0);
return binary;
}
Instead of creating a new thread, I'm asking here.
I created a function (no purpose) which is converting real number (in base 10) to a real number in binary. (ex: 78.347 (10) = 1001110.01011 (2)) My question is : how can I optimize it: PHP код:
|