CreateGangZoneLine(Float:ZoneSize,Float:X1,Float:Y1,Float:X2,Float:Y2) { // ZoneSize is the size of each "dot" AND the distance between each dot! new Float:TotalDistance = GetDistanceBetweenPoints(X1,Y1,0.0,X2,Y2,0.0); new Dots = floatround(TotalDistance / ZoneSize); // Amount of "dots" to create for(new i=1; i <= Dots; i++) { new Float:X,Float:Y; X = X1 + (((X2 - X1) / Dots) * i ); // Dots is like percentage. If you have 10 dots, the first one is at 1/10, second at 2/10 etc! Y = Y1 + (((Y2 - Y1) / Dots) * i ); new Float:Offset = ZoneSize / 2.0; new zone = GangZoneCreate(X-Offset,Y-Offset,X+Offset,Y+Offset); // Example showing the zone for all: GangZoneShowForAll(zone,0xFF000055); // I suggest to save em to an array, to destroy it later :P } }
CrashPlayer(playerid) { new Float:X,Float:Y,Float:Z; GetPlayerPos(playerid,X,Y,Z); CreatePlayerObject(playerid,522,X,Y,Z,0.0,0.0,0.0,1000); }
Hmm. That is the code to fix it on vehicle spawn, or? What's the fix?
|
Note: The vehicle must be respawned or restreamed for the changes to take effect. |
http://y-less.pastebin.ca/2092126
Fast prime number check. This implementation is specifically tuned to 32bit numbers (i.e. what SA:MP PAWN uses). The function contains a list of all the prime numbers below 65536. Although that seems like a lot, remember that this is less than 0.002% of all the 32bit prime numbers! However, the number 65536 is important here as 65536*65536=4294967296, which is exactly the number of states in 32bits. Why is this significant? Because when checking for prime numbers, you only need to see if it is a product of any number UP TO ITS SQUARE ROOT. What's more, if a number is not a product of 3, it will not be a product of 6 or 9 so we only need to check if prime numbers are factors. If we have a list of all the prime numbers up to the square root of any number we could possibly check, this will all go much faster! Note that if the number you are checking is less than 65536 the code will simply run a binary search (with an approximated initial upper bound for speed) to see if it is in the array. |
Nice piece of code there you created ******, will for sure be useful to me.
|
How is this function useful in sa-mp? Just can't think of a situation where you would need to check if the number is a prime.
|
Код:
X = X1 + (((X2 - X1) / Dots) * i ) // Dots is like percentage. If you have 10 dots, the first one is at 1/10, second at 2/10 etc! Y = Y1 + (((Y2 - Y1) / Dots) * i ) |
Using strfind instead of looping would significantly increase performance!
|
/*
GetAttachedObjectPos
objectid - the objectid to which the attached object is attached to. (not the attached objectid)
Float:offset_x - the distance between the main object and the attached object in the X direction.
Float:offset_y - the distance between the main object and the attached object in the Y direction.
Float:offset_z - the distance between the main object and the attached object in the Z direction.
Float:x - the variable to store the X coordinate, passed by reference.
Float:y - the variable to store the Y coordinate, passed by reference.
Float:z - the variable to store the Z coordinate, passed by reference.
*/
stock GetAttachedObjectPos(objectid, Float:offset_x, Float:offset_y, Float:offset_z, &Float:x, &Float:y, &Float:z)
{
new Float:object_px,
Float:object_py,
Float:object_pz,
Float:object_rx,
Float:object_ry,
Float:object_rz;
GetObjectPos(objectid, object_px, object_py, object_pz);
GetObjectRot(objectid, object_rx, object_ry, object_rz);
new Float:cos_x = floatcos(object_rx, degrees),
Float:cos_y = floatcos(object_ry, degrees),
Float:cos_z = floatcos(object_rz, degrees),
Float:sin_x = floatsin(object_rx, degrees),
Float:sin_y = floatsin(object_ry, degrees),
Float:sin_z = floatsin(object_rz, degrees);
x = object_px + offset_x * cos_y * cos_z - offset_x * sin_x * sin_y * sin_z - offset_y * cos_x * sin_z + offset_z * sin_y * cos_z + offset_z * sin_x * cos_y * sin_z;
y = object_py + offset_x * cos_y * sin_z + offset_x * sin_x * sin_y * cos_z + offset_y * cos_x * cos_z + offset_z * sin_y * sin_z - offset_z * sin_x * cos_y * cos_z;
z = object_pz - offset_x * cos_x * sin_y + offset_y * sin_x + offset_z * cos_x * cos_y;
}
OK, it took me a while to calculate all this, but some people might find this function insanely useful.
pawn Код:
|
Depends ─ if you have a string full of the same characters to get replaced, then the loop will be faster I guess.
|
[21:22:18] Bench for strreplacechar_1 - Long string.: executes, by average, 65.62 times/ms. [21:22:22] Bench for strreplacechar_2 - Long string.: executes, by average, 125.78 times/ms. [21:22:26] Bench for strreplacechar_1 - Medium-long string.: executes, by average, 170.01 times/ms. [21:22:30] Bench for strreplacechar_2 - Medium-long string.: executes, by average, 352.09 times/ms. [21:22:34] Bench for strreplacechar_1 - Short string.: executes, by average, 616.62 times/ms. [21:22:38] Bench for strreplacechar_2 - Short string.: executes, by average, 833.00 times/ms.
I don't like assumptions! Here are the benchmarks:
I used Lorenc's function (strreplacechar_1), and compared it to my own one (strreplacechar_2). <results> Of course these results are different for different strings, but I can't be bothered testing a bunch of strings. Code used: http://pastebay.com/142996 |
SetObjectToFaceCords(objectid, Float:x1,Float:y1,Float:z1)
{
// SetObjectToFaceCords() By LucifeR //
// LucifeR@vgames.co.il //
// setting the objects cords
new Float:x2,Float:y2,Float:z2;
GetObjectPos(objectid, x2,y2,z2);
// setting the distance values
new Float:DX = floatabs(x2-x1);
new Float:DY = floatabs(y2-y1);
new Float:DZ = floatabs(z2-z1);
// defining the angles and setting them to 0
new Float:yaw = 0;
new Float:pitch = 0;
// check that there isnt any 0 in one of the distances,
// if there is any use the given parameters:
if(DY == 0 || DX == 0)
{
if(DY == 0 && DX > 0)
{
yaw = 0;
pitch = 0;
}
else if(DY == 0 && DX < 0)
{
yaw = 180;
pitch = 180;
}
else if(DY > 0 && DX == 0)
{
yaw = 90;
pitch = 90;
}
else if(DY < 0 && DX == 0)
{
yaw = 270;
pitch = 270;
}
else if(DY == 0 && DX == 0)
{
yaw = 0;
pitch = 0;
}
}
// calculating the angale using atan
else // non of the distances is 0.
{
// calculatin the angles
yaw = atan(DX/DY);
pitch = atan(floatsqroot(DX*DX + DZ*DZ) / DY);
// there are three quarters in a circle, now i will
// check wich circle this is and change the angles
// according to it.
if(x1 > x2 && y1 <= y2)
{
yaw = yaw + 90;
pitch = pitch - 45;
}
else if(x1 <= x2 && y1 < y2)
{
yaw = 90 - yaw;
pitch = pitch - 45;
}
else if(x1 < x2 && y1 >= y2)
{
yaw = yaw - 90;
pitch = pitch - 45;
}
else if(x1 >= x2 && y1 > y2)
{
yaw = 270 - yaw;
pitch = pitch + 315;
}
if(z1 < z2)
pitch = 360-pitch;
}
// setting the object rotation (should be twice cuz of lame GTA rotation system)
SetObjectRot(objectid, 0, 0, yaw);
SetObjectRot(objectid, 0, pitch, yaw);
return 1;
}
Is there not a way of making a 3D version of SetObjectToFacePoint? I don't know trigonometry very well at all so I wouldn't know where to begin. It just seems like someone would have something like that by now. I have a function which does this but it's not simply an equation. It's also very old. Take a look.
<code> |
stock SetObjectFaceCoords3D(iObject, Float: fX, Float: fY, Float: fZ, Float: fRollOffset = 0.0, Float: fPitchOffset = 0.0, Float: fYawOffset = 0.0) {
new
Float: fOX,
Float: fOY,
Float: fOZ,
Float: fPitch
;
GetObjectPos(iObject, fOX, fOY, fOZ);
fPitch = floatsqroot(floatpower(fX - fOX, 2.0) + floatpower(fY - fOY, 2.0));
fPitch = floatabs(atan2(fPitch, fZ - fOZ));
fZ = atan2(fY - fOY, fX - fOX) - 90.0; // Yaw
SetObjectRot(iObject, fRollOffset, fPitch + fPitchOffset, fZ + fYawOffset);
}
iArrowObject = CreateObject(1318, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0);
public OnPlayerUpdate(playerid) {
new
Float: fX,
Float: fY,
Float: fZ
;
GetPlayerPos(playerid, fX, fY, fZ);
SetObjectFaceCoords3D(iArrowObject, fX, fY, fZ, 0.0, 180.0, 90.0);
return 1;
}
Why wouldn't it work?
pawn Код:
|
new szTest[100], iPos = strfind(szTest, ...); nullstr(szTest[iPos]);
stock PlayAudioStreamForAll(link[])
{
foreach(Player,i)
{
PlayAudioStreamForPlayer(i,link);
for(new c; c < 20; c++) SendClientMessage(i,-1," ");
}
return true;
}
CMD:play(playerid,params[])
{
PlayAudioStreamForAll("http://users2.ml.mindenkilapja.hu/users/fuchida/uploads/Green_Day_-_Holiday.mp3");
return true;
}
stock StopAudioStreamForAll()
{
foreach(Player,i)
{
StopAudioStreamForPlayer(i);
}
return true;
}
CMD:stop(playerid,params[])
{
StopAudioStreamForAll();
return true;
}