06.10.2011, 09:09
Useful Functions
08.10.2011, 09:30
Here's a tiny function in case someone is interested in exploring yellow markers all over San Andreas!!
Yellow markers will randomly appear, disappear and reappear in random places. Screenies:
pawn Код:
CMD:showmeyellowmarkers(playerid, params[])
{
YellowMarkersForPlayer(playerid, 0);
return 1;
}
forward YellowMarkersForPlayer(playerid, pos);
public YellowMarkersForPlayer(playerid, pos)
{
switch(pos)
{
case 0, 2, 4:
{
SetPlayerPos(playerid, 2449.17, 689.83, 10.97);
}
case 1, 3:
{
SetPlayerPos(playerid, 2543.15, 1025.16, 10.32);
}
case 5:
{
SendClientMessage(playerid, 0xAA3333AA, "Go and explore!");
}
}
if(pos < 5)
{
SetTimerEx("YellowMarkersForPlayer", 1500, 0, "dd", playerid, ++pos);
}
}
08.10.2011, 14:41
(
Последний раз редактировалось RyDeR`; 08.10.2011 в 21:33.
)
intLen
Returns the length of an integer:
Examples:
intCat
Returns a value of two concatenated integers:
or in recursive way (most probably slower):
Examples:
Returns the length of an integer:
pawn Код:
stock intLen(iNum)
return floatround(floatlog(floatabs(iNum) + 1), floatround_ceil);
pawn Код:
printf("%d", intLen(235)); // Prints 3
printf("%d", intLen(123456)); // Prints 6
Returns a value of two concatenated integers:
pawn Код:
stock intCat(iNum1, iNum2)
return iNum1 * floatround(floatpower(10.0, intLen(iNum2))) + iNum2;
pawn Код:
stock intCat(iNum1, iNum2)
{
if(iNum2)
iNum1 = intCat(iNum1 * 10, iNum2 / 10);
return iNum1 - (iNum2 / 10) + iNum2;
}
pawn Код:
printf("%d", intCat(3, 1456)); // Prints 31456
printf("%d", intCat(54654, 9984)); // Prints 546549984
08.10.2011, 17:26
Quote:
Here's a tiny function in case someone is interested in exploring yellow markers all over San Andreas!!
pawn Код:
|
08.10.2011, 17:54
(
Последний раз редактировалось RyDeR`; 08.10.2011 в 21:23.
Причина: Deleted code.
)
08.10.2011, 20:41
(
Последний раз редактировалось RyDeR`; 08.10.2011 в 21:25.
)
08.10.2011, 21:20
Quote:
Here's a tiny function in case someone is interested in exploring yellow markers all over San Andreas!!
pawn Код:
|
08.10.2011, 22:42
Using y_va from YSI. This function returns the formatted string!
Example:
Another thing I just made is strcatf, it appends a formatted string to a string, without using a buffer in-between!
pawn Код:
stock sprintf(szFormat[], va_args<>) {
static
s_szBuffer[512]
;
va_format(s_szBuffer, sizeof (s_szBuffer), szFormat, va_start<1>);
return s_szBuffer;
}
pawn Код:
SendRconCommand(sprintf("weather %d", weather));
pawn Код:
stock strcatf(szDest[], szFormat[], iMaxLength = sizeof(szDest), va_args<>) {
new
iLength = strlen(szDest)
;
va_format(szDest[iLength], iMaxLength - iLength, szFormat, va_start<3>);
}
08.10.2011, 22:44
@Slice so it'll change the wather ID as you wish?
08.10.2011, 22:48
Well, yea. The weather thing was just an example, though.
09.10.2011, 03:17
NEW FUNCTION
OLD FUNCTION
Example 1
Untested this little example though should work!
Example 1
Untested this little example though should work!
If I did something wrong, tell me
PS.
We're on
pawn Код:
stock Float: Pythagoras2(Float: val1, Float: val2, bool: shortside = false)
return shortside == true ? (floatsqroot(floatsub(floatmul(val1, val1), floatmul(val2, val2)))) : (floatsqroot(floatadd(floatmul(val1, val1), floatmul(val2, val2))));
pawn Код:
stock Pythagoras(Float: val1, Float: val2, bool: shortside = false)
{
new
Float: cal
;
if(shortside) cal = ((val1 * val1) - (val2 * val2));
else cal = ((val1 * val1) + (val2 * val2));
cal = floatsqroot(cal);
return cal;
}
Example 1
pawn Код:
new Float: X = Pythagoras(90, 20, false);
printf("The hypotenuse of this is %f", X);
Example 1
pawn Код:
new Float: X = Pythagoras(56, 20, true);
printf("The height of this is %f", X);
If I did something wrong, tell me
PS.
We're on
pawn Код:
new page[256];
09.10.2011, 08:41
Quote:
09.10.2011, 11:02
Quote:
NEW FUNCTION
pawn Код:
pawn Код:
Example 1 pawn Код:
Example 1 pawn Код:
If I did something wrong, tell me PS. We're on pawn Код:
|
Pytahoras says:
if we put in some numbers:
a = 6
b = 3
------
c=?
c=15 cm
now your formula:
cal = ((val1 * val1) - (val2 * val2));
val1 = 6
val2 = 3
--------
cal=?
cal=((val1 * val1) - (val2 * val2))
cal=27 cm
we get difreent result, something is wrong :S
09.10.2011, 11:22
09.10.2011, 13:43
i did not see that lorenc put floatsqroot(cal); sorry i fajl :S
09.10.2011, 14:41
intIns
Inserts an integer to another integer and returns the final value:
Examples:
NOTE: You also need intLen which I posted here.
Inserts an integer to another integer and returns the final value:
pawn Код:
stock intIns(iNum1, iNum2, iPos)
{
static
iLength[2]
;
iLength[0] = intLen(iNum1);
iLength[1] = intLen(iNum2);
if((0 <= (iLength[0] + iLength[1]) <= 9) && (0 <= (iLength[0] -= iPos) <= 9))
{
iLength[0] = floatround(floatpower(10.0, iLength[0]));
iLength[1] = floatround(floatpower(10.0, iLength[1]));
return ((((iNum1 / iLength[0]) * iLength[1]) + iNum2) * iLength[0]) + (iNum1 % iLength[0]);
}
return 0;
}
pawn Код:
printf("%d", intIns(1245, 3, 2)); // Prints 12345
printf("%d", intIns(666666, 999, 3)); // Prints 666999666
13.10.2011, 10:17
@Lorenc_:
I meant something more like this:
I meant something more like this:
pawn Код:
stock SetObjectFacePoint(iObjectID, Float: fX, Float: fY, Float: fOffset = 0.0)
{
new
Float: fOX,
Float: fOY,
Float: fRZ
;
if(GetObjectPos(iObjectID, fOX, fOY, fRZ))
{
fRZ = atan2(fY - fOY, fX - fOX) - 90.0;
GetObjectRot(iObjectID, fX, fY, fOX);
SetObjectRot(iObjectID, fX, fY, fRZ + fOffset);
}
}
13.10.2011, 12:09
here is a little function for MySQL
It just make easier than doing mysql_real_escape_string etc. also you will need GetName function !
pawn Код:
stock mysql_get_name(playerid)
{
new mysqlname[MAX_PLAYER_NAME];
mysql_real_escape_string(GetName(playerid), mysqlname);
return mysqlname;
}
pawn Код:
stock GetName(playerid)
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
return pName;
}
13.10.2011, 12:15
Quote:
here is a little function for MySQL
pawn Код:
pawn Код:
|
On the other hand, if you're using BlueG's MySQL plugin, mysql_format can be used.
13.10.2011, 15:52
« Next Oldest | Next Newest »
Users browsing this thread: 30 Guest(s)