Spawning objects in a circle - Gap appears - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Spawning objects in a circle - Gap appears (
/showthread.php?tid=640516)
Spawning objects in a circle - Gap appears [RESOLVED] -
Aerotactics - 03.09.2017
Problem: I've built a command to spawn objects in a circle around the player (for testing). However above 50 objects (player count/spawn) a gap appears in the circle. Is my math wrong, or is there an underlying limitation in SAMP?
RESOLUTION: I changed this line and now the circle works perfectly:
PHP код:
new Float:a = float(360)/float(count);
PHP код:
CMD:mtest(playerid, params[])
{
if(pInfo[playerid][pAdmin] < 5) return SCM(playerid, COLOR_GREY, "ERROR: You don't have access to this command, sorry.");
new Float:x, Float:y, Float:z, count, spawn;
if(sscanf(params, "ii", count, spawn))
{
SCM(playerid, COLOR_WHITE, "USE: /mtest [player count] [spawn distance]");
SCM(playerid, COLOR_YELLOW, "WARNING: This command uses open parameters, so be careful.");
return 1;
}
new Float:a = 360/count;
for(new i=0; i<count; i++)
{
GetPlayerPos(playerid, x, y, z);
new Float:a2 = a*(i+1);
x += (spawn * floatsin(-a2, degrees));
y += (spawn * floatcos(-a2, degrees));
CreateDynamicObject(13646, x, y, z-1, 0, 0, (-(a*i)+180));
}
new str[128];
format(str, sizeof(str), "[%s] %s (%i) has created a map test.", GetAdminLevelName(pInfo[playerid][pAdmin]), GetName(playerid), playerid);
CallLocalFunction("AdminMessage", "si", str, COLOR_RED);
return 1;
}
Re: Spawning objects in a circle - Gap appears -
Vince - 03.09.2017
Quote:
Код:
new Float:a = 360/count
|
Doesn't that give a tag mismatch, though? Both values are integers so the output should also be an integer. If you want the output to be a float then at least one of the operands should be a float. 360 divided by 50 as integers gives 7; and 7 * 50 = 350 which explains the gap.
Re: Spawning objects in a circle - Gap appears -
Paulice - 03.09.2017
You don't need to get the player's position in every iterator, and declare "a" outside the loop as well.