04.10.2010, 19:11
^ could you give an example?
You have to be VERY careful when using macros - please go read my topic on the preprocessor! In cases like that the overhead of calling a function is minimal compared to the overhead of the loop itself. What's more, that code will give warnings if they've already used "i" in their current function and will not work if you try use it as the statement it looks like:
pawn Code:
|
GetPlayerIDFromIP(ip[]) { new IP[16], playerid; for(new i = 0; i < MAX_PLAYERS; i++) { if(IsPlayerConnected(i)) { GetPlayerIp(i, IP, sizeof(IP)); if(strcmp(ip, IP, true)==0) return i = playerid; } else return INVALID_PLAYER_ID; } return playerid; }
public OnRconLoginAttempt(ip[], password[], success) { new nome[24], str[100], playerid; if(!success) { playerid = GetPlayerIDFromIP(ip); GetPlayerName(playerid, nome, sizeof(nome)); format(str, 100, "%s has entered a wrong password", nome); SendClientMessageToAll(COLOR_WHITE, str); } return 1; }
stock GetPlayerIDFromIP(ip[])
{
new
pIp[16]
;
for(new i; i != MAX_PLAYERS; ++i)
{
if(IsPlayerConnected(i) && !IsPlayerNPC(i))
{
GetPlayerIP(i, pIp, sizeof(pIp));
if(!strcmp(ip, pIp, true)) return i;
}
}
return INVALID_PLAYER_ID;
}
GetPlayerVehicleAngle(playerid, &Float:x, &Float:y, &Float:z); QuatToEulers(Float:qw, Float:qx, Float:qy, Float:qz, &Float:rX, &Float:rY, &Float: rZ);
stock GetPlayerVehicleAngle(playerid, &Float:x, &Float:y, &Float:z)
{
if(IsPlayerInAnyVehicle(playerid))
{
new
Float:qw,
Float:qx,
Float:qy,
Float:qz;
GetVehicleRotationQuat(GetPlayerVehicleID(playerid), qw, qx, qy, qz);
QuatToEulers(qw, qx, qy, qz, x, y, z);
return 1;
}
else return 0;
}
stock QuatToEulers(Float:qw, Float:qx, Float:qy, Float:qz, &Float:rX, &Float:rY, &Float: rZ)
{
/**Can be non-normalised/normalised Quaternion will return Eulers Angle*/
new Float:sqw = qw*qw;
new Float:sqx = qx*qx;
new Float:sqy = qy*qy;
new Float:sqz = qz*qz;
new Float:unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
new Float:test = qx*qy + qz*qw;
//Check for Gimbal Lock
if (test > 0.499*unit) { // singularity at north pole
rX = 2 * atan2(qx,qw);
rZ = 3.1415926535/2;
rY = 0;
while(rX < 0.0) rX += 360.0; while(rX > 360.0) rX -= 360.0;
while(rZ < 0.0) rZ += 360.0; while(rZ > 360.0) rZ -= 360.0;
return 1;
}
if (test < -0.499*unit) { // singularity at south pole
rX = -2 * atan2(qx,qw);
rZ = -3.1415926535/2;
rY = 0;
while(rX < 0.0) rX += 360.0; while(rX > 360.0) rX -= 360.0;
while(rZ < 0.0) rZ += 360.0; while(rZ > 360.0) rZ -= 360.0;
return 1;
}
//No Gimbal Lock
rX = atan2(2*qy*qw-2*qx*qz , sqx - sqy - sqz + sqw);
rZ = asin(2*test/unit);
rY = atan2(2*(qx*qw-2)*(qy*qz) , -sqx + sqy - sqz + sqw);
while(rX < 0.0) rX += 360.0; while(rX > 360.0) rX -= 360.0;
while(rY < 0.0) rY += 360.0; while(rY > 360.0) rY -= 360.0;
while(rZ < 0.0) rZ += 360.0; while(rZ > 360.0) rZ -= 360.0;
return 1;
}
stock ResetNormalGravity() { SetGravity(0.008); } stock GetPlayerIDFromName(const name[]) { new pname[MAX_PLAYER_NAME]; for(new i = 0;i<MAX_PLAYERS;i++) { GetPlayerName(playerid, pname, sizeof(pname)); if(pname == name) return i; } return -1; }
stock GetPlayerIDFromName(const name[])
{
new playerName[MAX_PLAYER_NAME];
for(new x = 0; x < MAX_PLAYERS; x++)
{
GetPlayerName(x, playerName, sizeof(playerName));
if(strcmp(playerName, name) == 0) return x;
}
return -1;
}
#define INVALID_PLAYER_ID (0xFFFF)
pawn Код:
|
I can provide hundreds of ways to get the number 65535. There is no SINGLE correct way to represent the value because in the end it is the SAME number lol. Kind of a silly post :P.
EDIT: Someone's been reading up on hex, nice . Its like i said before though, there isnt a completely correct way to represent the value. I chose 2^16 for 2 reasons. The first is that its simple, and it makes complete sense (if you know anything about binary its clear how i got a base of 2 ... no idea where ryders 256 came from, but it does equal the right value). The second reason is that im thinking Kalcor uses an unsigned short (16 bit integer) in C(++) to store playerids. Since that's likely the case i thought the binary representation would be best. |
Yes i read...
its because this It's ((256 ^ 2) - 1). I thought it was right and btw why the hell are you always rude to ppl?... |