12.04.2015, 05:56
Again, it is still way more efficient to use y_iterate. I'll give an example (some snips of my old proximity mine script) in a sec (done).
Features:
- Sly use of y_iterate for object handling.
- Efficient foreach (aka y_iterate) loops, the loop will not even go on if the mines do not exist.
- Command with time to run away, used to activate the mines.
- Mines are green when inactive, but turn red when they are active.
- Explosions (because you said you like explosions ofc).
@Gammix, I'm not against your method at all, just pointing out the better efficiency of this method.
Код:
#include <a_samp> #include <sscanf> #include <YSI\y_commands> // Or ZCMD. This system is compatible with both (as is all other scripts using ZCMD). #include <YSI\y_iterate> #define MAX_PROX 5 //Change to your liking. new Iterator:Proximeter[MAX_PLAYERS]<MAX_OBJECTS>, bool:Active[MAX_OBJECTS]; CMD:prox(playerid, params[]) { if(Iter_Count(Proximeter[playerid]) == MAX_PROX) return SendClientMessage(playerid, -1, "You can't have more than 5 Proximity Mines planted."); new time; if(sscanf(params, "i", time)) return SendClientMessage(playerid, COLOR_ERROR, "[Command] Error: /Prox <time before activation>"); else if(5 > time > 30) return SendClientMessage(playerid, COLOR_ERROR, "[Command] Error: The timer can only be set between 5 and 30 seconds."); else { GetPlayerPos(playerid, nx, ny, z); new id = CreateObject(19602, nx, ny, nz, rx, ry, rz); Iter_Add(Proximeter[playerid], id); Active[id] = false; SetTimerEx("AddProx", time*1000, false, "i", id); return SendClientMessage(playerid, -1, sprintf("You now have %i Proximity Mine(s) planted.", Iter_Count(Proximeter[playerid]))); } } forward AddProx(proxid); public AddProx(proxid) { SetObjectMaterial(proxid, 0, -1, "none", "none", 0xFFFF0000); //Turns it red when active, nice touch! Active[proxid] = true; //Activates the proximeter. return 1; } public OnGameModeInit() { Iter_Init(Proximeter); return 1; } public OnPlayerUpdate(playerid) { foreach(new p : Player) //if(GetPlayerTeam(p) != GetPlayerTeam(playerid))// Remove this comment if you want to check the teams. foreach(new m : Proximeter[p]) if(Active[m]) { new Float:P[3]; GetObjectPos(m, P[0], P[1], P[2]); if(IsPlayerInRangeOfPoint(playerid, 10.0, P[0], P[1], P[2])) { Iter_Remove(Proximeter[p], m); DestroyObject(m); CreateExplosion(P[0], P[1], P[2], 6, 10.0); } } return 1; }
- Sly use of y_iterate for object handling.
- Efficient foreach (aka y_iterate) loops, the loop will not even go on if the mines do not exist.
- Command with time to run away, used to activate the mines.
- Mines are green when inactive, but turn red when they are active.
- Explosions (because you said you like explosions ofc).
@Gammix, I'm not against your method at all, just pointing out the better efficiency of this method.