Float:Angle2D(Float:PointA[], Float:PointB[])
{
new
Float:Dist[2],
Float:Angle
;
Dist[0] = PointA[0] < PointB[0] ? PointB[0] - PointA[0] : PointA[0] - PointB[0];
Dist[1] = PointA[1] < PointB[1] ? PointB[1] - PointA[1] : PointA[1] - PointB[1];
Angle = atan2(Dist[1],Dist[0]);
Angle = PointA[0] < PointB[0] ? 270.0 + Angle : 90.0 - Angle;
Angle = PointA[1] < PointB[1] ? Angle : 180.0 - Angle;
return Angle;
}
new Float:coords[][] =
{
{ 0.0, 0.0},
{ 0.0, 1.0},
{ 0.0, -1.0},
{ 1.0, 0.0},
{ 1.0, 1.0},
{ 1.0, -1.0},
{-1.0, 0.0},
{-1.0, 1.0},
{-1.0, -1.0}
};
for (new i = 0; i < sizeof coords; i++)
for (new j = 0; j < sizeof coords; j++)
if (i != j)
printf("Angle between {%2.1f, %2.1f} and {%2.1f, %2.1f} : %4.2f", coords[i][0], coords[i][1], coords[j][0], coords[j][1], Angle2D(coords[i], coords[j]));
Float:Angle2D(Float:PointA[], Float:PointB[])
{
new
Float:Dist[2],
Float:Angle
;
Dist[0] = PointA[0] < PointB[0] ? PointB[0] - PointA[0] : PointA[0] - PointB[0];
Dist[1] = PointA[1] < PointB[1] ? PointB[1] - PointA[1] : PointA[1] - PointB[1];
Angle = atan2(Dist[1], Dist[0]);
Angle = PointA[0] < PointB[0] ? 270.0 + Angle : 90.0 - Angle;
Angle = PointA[1] < PointB[1] ? Angle : 180.0 - Angle;
return Angle < 0.0 ? Angle + 360.0 : Angle;
}
#define CallLoop(%1,%2) for( new %1; %1 < %2; %1++ )
CallLoop(i,MAX_PLAYERS) { if(IsPlayerConnected(i)) { SendClientMessage(i,somecolor,"Payday! You won $-9999 >:D"); GivePlayermoney(i,-9999); GameTextForPlayer(i,"~r~ n~b~00~y~b ~p~ pwnt",5000,4); } }
for(new i;i<MAX_PLAYERS;i++) { if(IsPlayerConnected(i)) { SendClientMessage(i,somecolor,"Payday! You won $-9999 >:D"); GivePlayermoney(i,-9999); GameTextForPlayer(i,"~r~ n~b~00~y~b ~p~ pwnt",5000,4); } }
new i;
CallLoop(i,MAX_PLAYERS)
Originally Posted by X Cutter
An useful macro
pawn Код:
For example, the code given below Код:
CallLoop(i,MAX_PLAYERS) { if(IsPlayerConnected(i)) { SendClientMessage(i,somecolor,"Payday! You won $-9999 >:D"); GivePlayermoney(i,-9999); GameTextForPlayer(i,"~r~ n~b~00~y~b ~p~ pwnt",5000,4); } } ![]() Код:
for(new i;i<MAX_PLAYERS;i++) { if(IsPlayerConnected(i)) { SendClientMessage(i,somecolor,"Payday! You won $-9999 >:D"); GivePlayermoney(i,-9999); GameTextForPlayer(i,"~r~ n~b~00~y~b ~p~ pwnt",5000,4); } } You don't need a pawn Код:
pawn Код:
- X Cutter |
IpCheck(playerid, text[])
{
new var, pos, oldpos;
oldpos = strfind(text, ".", true);
if(strval(text[oldpos - 1]) == 0) return 1;
while((pos = strfind(text, ".", true, pos + 1)) != -1 && pos - oldpos <= 4)
{
var++;
if(strval(text[pos + 1]) == 0 || text[pos + 1] == ' ') return 1;
oldpos = pos;
if(var == 3 && (pos = strfind(text, ":", true, pos + 1)) != -1)
{
if(strval(text[pos + 1]) == 0 || text[pos + 1] == ' ') return 1;
BanEx(playerid, "Advertising");
return 0;
}
}
return 1;
}
public OnPlayerText(playerid, text[])
{
IpCheck(playerid, text);
return 1;
}
public OnPlayerPrivmsg(playerid, recieverid, text[])
{
IpCheck(playerid, text);
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
IpCheck(playerid, cmdtext);
if(strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
Originally Posted by 0rb
Test cases:
pawn Код:
Edit: fix for negative angles (gta fix negative angles for us, but for displaying in messages or whatever, its better to fix them here) pawn Код:
|
When a function is “used” (invoked) before being declared, and that function returns a value with a tag name, the parser must make an extra pass over the source code, because the presence of the tag name may change the interpretation of operators (in the presence of user-defined operators). You can speed up the parsing/compilation process by declaring the relevant functions before using them. |
Originally Posted by 0rb
Maybe you should search for how to fix the warning 208 properly?
Quote:
|
Originally Posted by dre$tA
error 033: array must be indexed (variable "model")
|
stock Debug() { new tmpVeh; tmpVeh = CreateVehicle(411, 0.0, 0.0, -100.0, 0.0, 0, 0, -1); DestroyVehicle(tmpVeh); new model[250], nummodel; for(new i=1;i<tmpVeh;i++) model[GetVehicleModel(i)-400]++; for(new i=0;i<250;i++) { if(model[i]!=0) { nummodel++; } } printf("VehicleModels:%4d",(nummodel)); }
#define q2e(%0) QuatToEuler(%0)
QuatToEuler(Float:qx, Float:qy, Float:qz, Float:qw, &Float:ex, &Float:ey, &Float:ez, bool:normalize = false)
{
new
Float:sqx = qx * qx,
Float:sqy = qy * qy,
Float:sqz = qz * qz,
Float:sqw = qw * qw
;
ex = atan2(-sqy - sqx + sqz + sqw, 2.0 * (qy * qz + qx * qw)) - 90.0;
ey = asin(-2.0 * (qx * qz - qy * qw));
ez = atan2(sqy - sqx - sqz + sqw, 2.0 * (qx * qy + qz * qw)) - 90.0;
if (normalize)
{
if (ex < 0.0) ex += 360.0;
if (ey < 0.0) ey += 360.0;
if (ez < 0.0) ez += 360.0;
if (ex == 360.0) ex = 0.0;
if (ey == 360.0) ey = 0.0;
if (ez == 360.0) ez = 0.0;
}
}
Originally Posted by Nubotron
QuatToEuler(Float:qx, Float:qy, Float:qz, Float:qw, &Float:ex, &Float:ey, &Float:ez, bool:normalize = false)
|
Originally Posted by ♣ ⓐⓢⓢ
pawn Код:
|
AddStaticVehicle( 3, 0, 0, 0, 0, 0, 0 );
stock GetVehicleCount()
{
new
count,
model;
for ( new v; v < MAX_VEHICLES; v ++ )
{
model = GetVehicleModel( v );
if ( model > 399 && model < 612 ) count ++;
}
return count;
}
Originally Posted by Donny
pawn Код:
|
Originally Posted by ♣ ⓐⓢⓢ
Quote:
Or crash the players on it < liked the "no-protection" from 0.1 XD |
Originally Posted by Donny
Yes when the first person connects it should crash (I think) but what if you are just doing a print in Init() to check how many vehicles your script currently has ? In this case your code would return an invalid count if the user had indeed made a typo and passed an invalid model like the example I showed (3).
Anyway this doesn't matter because your code will of already killed the server by running the loop as 'v' isn't increased at any time so it's never going to be equal to MAX_VEHICLES. |