05.02.2019, 22:39
Can you tell me is my code well optimized?
Код:
#include <a_samp> #include <streamer> #include <sscanf2> #include <ColAndreas> #include <zcmd> #include <YSI_Coding\y_timers> new Timer:timer1; new Grass[MAX_PLAYERS][3]; new Kosilice[5]; new br=0; new scfmString[250]; #define SCM SendClientMessage #define SCFM(%1,%2,%3) format(scfmString,sizeof(scfmString),%3), SCM(%1,%2,scfmString) public OnFilterScriptInit() { CA_Init(); for(new i=0;i<sizeof(Kosilice);i++) { Kosilice[i] = CreateVehicle(572, 99.2503+(i*4), 77.9267-(i*2), 2.1, 164.1081, 0, 0, -1); new Text3D:label = Create3DTextLabel("Kosač", 0x00FF00FF, 0, 0, 0, 40, 0, 0); Attach3DTextLabelToVehicle(label, Kosilice[i], 0.0, 0.0, 1.0); } return 1; } public OnFilterScriptExit() { for(new i=0; i<MAX_OBJECTS; i++) { DestroyObject(i); DestroyVehicle(i); } return 1; } CMD:as(playerid, params[], help) { for(new i=0; i<sizeof(Grass[]); i++) { new Float:randx = RandomFloat(109.2241-92.6121)+92.6121; new Float:randy = RandomFloat(-71.6366-(-57.7923))+57.7923; new Float:z; CA_FindZ_For2DCoord(randx, randy, z); Grass[playerid][i] = CreatePlayerObject(playerid, 802, randx, randy, z+0.2, 0, 0, 0); } timer1 = repeat kosacTimer(playerid); return 1; } timer kosacTimer[250](playerid) { new Float:x,Float:y,Float:z; if(br >= sizeof(Grass[])) { new rand = 0; SendClientMessage(playerid, -1,"No grass"); rand = random(50)+26; GivePlayerMoney(playerid, rand); SCFM(playerid, 0, "Dobili ste %i $", rand ); br=0; stop timer1; } else { for(new i=0; i<sizeof(Grass[]); i++) { GetPlayerObjectPos(playerid, Grass[playerid][i], x, y, z); if(IsPlayerInRangeOfPoint(playerid, 1.2, x, y, z) && Grass[playerid][i] != 0 && KosacVozilo(playerid)) { DestroyPlayerObject(playerid, Grass[playerid][i]); Grass[playerid][i] = 0; br++; } } } return 1; } KosacVozilo(playerid)//provjerava da li je igrac u vozilu kosača trave { for(new i=0;i<=sizeof(Kosilice);i++) { if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) if(GetPlayerVehicleID(playerid) == Kosilice[i]) return 1; } return 0; }