29.11.2013, 13:10
Quote:
Can u make a code which returns an random point Count in the zone area??
|
Quote:
pawn Код:
|
@Emmet_ Thanks for the tips
Can u make a code which returns an random point Count in the zone area??
|
pawn Код:
|
stock GetWeaponModel(playerid)
{
new
_ObjectModel = 0;
switch( GetPlayerWeapon( playerid ) )
{
case 1: _ObjectModel = 331;
case 2: _ObjectModel = 333;
case 3: _ObjectModel = 334;
case 4: _ObjectModel = 335;
case 5: _ObjectModel = 336;
case 6: _ObjectModel = 337;
case 7: _ObjectModel = 338;
case 8: _ObjectModel = 339;
case 9: _ObjectModel = 341;
case 10: _ObjectModel = 321;
case 11: _ObjectModel = 322;
case 12: _ObjectModel = 323;
case 13: _ObjectModel = 324;
case 14: _ObjectModel = 325;
case 15: _ObjectModel = 326;
case 16: _ObjectModel = 342;
case 17: _ObjectModel = 343;
case 18: _ObjectModel = 344;
case 22: _ObjectModel = 346;
case 23: _ObjectModel = 347;
case 24: _ObjectModel = 348;
case 25: _ObjectModel = 349;
case 26: _ObjectModel = 350;
case 27: _ObjectModel = 351;
case 28: _ObjectModel = 352;
case 29: _ObjectModel = 353;
case 30: _ObjectModel = 354;
case 31: _ObjectModel = 356;
case 32: _ObjectModel = 372;
case 33: _ObjectModel = 357;
case 34: _ObjectModel = 358;
case 35: _ObjectModel = 359;
case 36: _ObjectModel = 360;
case 37: _ObjectModel = 361;
case 38: _ObjectModel = 362;
case 39: _ObjectModel = 363;
case 40: _ObjectModel = 364;
case 41: _ObjectModel = 365;
case 42: _ObjectModel = 366;
case 43: _ObjectModel = 367;
case 44: _ObjectModel = 368;
case 45: _ObjectModel = 369;
case 46: _ObjectModel = 371;
}
return _ObjectModel;
}
[13:08:37] 348 --> Deagle [13:08:34] 356 --> M4A1 [13:09:16] 358 --> Sniper
stock GetWeaponModel(playerid)
{
static const MyArray[] =
{
0,
331,
333,
334,
// so on...
};
return MyArray[GetPlayerWeapon(playerid)]);
}
stock swap(&{Float,_}:var1, &{Float,_}:var2)
{
#emit LREF.S.pri var1
#emit LREF.S.alt var2
#emit SREF.S.pri var2
#emit SREF.S.alt var1
}
// Many thanks to Y_Less, Nero, RyDeR for teaching me some assembly tips.
// Based on the SYSREQ.C calling method by Zeex - credits to him also.
forward @concat_fix(); @concat_fix()
{
format("", 1, "");
}
stock concat(output[], len, const str[], {Float,_}:...)
{
static
string[512],
start,
end,
args;
args = numargs() * 4;
if (args >= 16)
{
// Load the address of the last static parameter.
#emit ADDR.pri str
#emit STOR.pri start
for (end = start + (args - 12); end > start; end -= 4)
{
// Load the parameter address of this function.
#emit LREF.alt end
// Push it onto the stack.
#emit PUSH.alt
}
// Push the other arguments into "format".
#emit PUSH.S str
#emit PUSH.C 512
#emit PUSH.C string
// Push the number of arguments (in bytes).
#emit PUSH.C args
// Call the function.
#emit SYSREQ.C format
strcat(output, string, len);
// Clear the stack. This is done by loading the previous stack
// level before the function call.
#emit LCTRL 5
#emit SCTRL 4
// Return the function and clean up the local variables.
#emit RETN
}
return strcat(output, str, len);
}
new str[64];
concat(str, sizeof(str), "I like to eat");
concat(str, sizeof(str), " %s and %s.", "bread", "butter");
print(str);
I like to eat bread and butter.
GetSlotWhithID(weaponid){
switch(weaponid){
case 0,1:return 0;
case 2,3,4,5,6,7,8,9:return 1;
case 22,23,24:return 2;
case 25,26,27:return 3;
case 28,29,32:return 4;
case 30,31:return 5;
case 33,34:return 6;
case 35,36,37,38:return 7;
case 16,17,18,39:return 8;
case 41,42,43:return 9;
case 10,11,12,13,14,15:return 10;
case 44,45,46:return 11;
case 40:return 12;
}
return -1;
}
Why is this? |
static stock isFaultyGameText(const string[])
{
new
i,
len;
while ((i = strfind(string, "~", true, (!i) ? (0) : (i + 1))) != -1) {
len++;
}
if (len % 2 != 0)
return 1;
else for (i = 0, len = strlen(string); i != len; i ++)
{
if (string[i] != '~')
continue;
else switch (string[i + 1])
{
case 'k', 'K':
{
if (!string[(i += strfind(string, "~", true, i + 4))])
break;
continue;
}
case 'a'..'j', 'l'..'z', 'A'..'J', 'L'..'Z':
{
if (string[(i += 2)] == '~')
continue;
return 1;
}
default:
{
return 1;
}
}
}
return 0;
}
main()
{
if (isFaultyGameText("I am a ~r~boss")) print("1");
if (isFaultyGameText("Press ~k~~VEHICLE_FIREWEAPON_ALT~ to answer your phone.")) print("2");
if (isFaultyGameText("I like to eat ~~cookies.")) print("3");
if (isFaultyGameText("This is ~r~red~w~ and this is ~y~yellow.")) print("4");
if (isFaultyGameText("Dude, ~r~~where's ~~r~~ my car?")) print("5");
}
3 5
isFaultyGameText("~r~")
stock isValidGameText(szText[]) {
new
iTildes
;
for(new i = 0; szText[i] != EOS; ++i) {
if(szText[i] == '~') {
iTildes++;
}
}
return !(iTildes & 0b1);
}
stock SCM4(playerid, color, form[], {Float, _}: ...) {
#pragma unused form
static
tmp[145]
;
new
t1 = playerid,
t2 = color
;
const
n4 = -4,
n16 = -16,
size = sizeof tmp
;
#emit stack 28
#emit push.c size
#emit push.c tmp
#emit stack n4
#emit sysreq.c format
#emit stack n16
return SendClientMessage(t1, t2, tmp);
}
The stack abuse method is very interesting though. I wouldn't have thought of that, Slice's method is how I would have done it (the "proper" way), but you couldn't do it Nero_3D's way without "playerid" and "color" because there's not enough stack space without destrying the frame header.
|
stock WordWrap(source[], bool:spaces, dest[], size = sizeof(dest), chars = 20)
{
new length = strlen(source);
strcat((dest[0] = '\0', dest), source, size);
if (length <= 0)
return 0;
while (--length != 0) if ((length % chars) == 0)
{
if (!spaces) {
strins(dest, "\r\n", length, size);
}
else for (new i = length; dest[i] != '\0'; i ++) if (dest[i] == ' ' && dest[i + 1] != '\r') {
strins(dest, "\r\n", i + 1, size); break;
}
}
return 1;
}
new dest[128];
WordWrap("I like to eat jelly donuts.", true, dest, sizeof(dest), 10);
print(dest);
WordWrap("I like to eat jelly donuts.", false, dest, sizeof(dest), 10);
print(dest);
I like to eat jelly donuts.
I lik e to eat j elly donut s.
stock INI_WriteData(INI:file, const fmat[], {Float,_}:...)
{
static
i,
ch,
idx,
str[32],
string[YSI_MAX_STRING];
if (((numargs() - 2) / 2) != strlen(fmat))
return printf("** Warning: %d specifiers, but only %d arguments.", strlen(fmat), (numargs() - 2) / 2);
while ((ch = fmat[i++]))
{
if (!('z' >= ch >= 'a'))
continue;
va_getstring(str, (idx = ((i - 1) << 1) + 2));
switch (ch)
{
case 'd', 'i':
INI_WriteInt(file, str, getarg(idx + 1));
case 'f':
INI_WriteFloat(file, str, Float:getarg(idx + 1));
case 'h':
INI_WriteHex(file, str, getarg(idx + 1));
case 's':
INI_WriteString(file, str, (va_getstring(string, idx + 1), string));
default:
printf("** Warning: Invalid specifier '%c'.", ch);
}
}
return 1;
}
new
INI:file = INI_Open("file.ini");
INI_WriteData(file, "sdf",
"String", "My name is Emmet.",
"Integer", 50,
"Float", 73.8
);
INI_Close(file);
Float = 73.800003 Integer = 50 String = My name is Emmet.
#include <a_samp>
#include <strlib> //by Slice, not Westie
main()
{
new
formatStr[184];
formatStr = "~r~ Red\n";
strcat(formatStr, "~g~ Green\n"), strcat(formatStr, "~b~ Blue\n"),
strcat(formatStr, "~w~ White\n"), strcat(formatStr, "~y~ Yellow\n"),
strcat(formatStr, "~p~ Purple\n"), strcat(formatStr, "~bl~ Black\n"),
strcat(formatStr, "~c~ Cyan\n"), strcat(formatStr, "~o~ Orange\n"),
strcat(formatStr, "~pk~ Pink\n"), strcat(formatStr, "~lb~ Light Blue\n"),
strcat(formatStr, "~br~ Brown\n"), UseGameTextColours(formatStr, sizeof(formatStr));
print(formatStr);
}
stock UseGameTextColours( string[], size = sizeof(string) )
{
strreplace(string, "~r~", "{f90303}", false, 0, -1, size); //red
strreplace(string, "~g~", "{03f90a}", false, 0, -1, size); //green
strreplace(string, "~b~", "{030af9}", false, 0, -1, size); //blue
strreplace(string, "~w~", "{ffffff}", false, 0, -1, size); //white
strreplace(string, "~y~", "{f0ff00}", false, 0, -1, size); //yellow
strreplace(string, "~p~", "{8000ff}", false, 0, -1, size); //purple
strreplace(string, "~bl~", "{000000}", false, 0, -1, size); //black
strreplace(string, "~c~", "{00FFFF}", false, 0, -1, size); //cyan
strreplace(string, "~o~", "{FF9900}", false, 0, -1, size); //orange
strreplace(string, "~pk~", "{FF3399}", false, 0, -1, size); //pink
strreplace(string, "~lb~", "{66CCFF}", false, 0, -1, size); //lightblue
strreplace(string, "~br~", "{CC6600}", false, 0, -1, size); //brown
//just follow the format above if you want to add colour, just playing with pawn :D
}
{f90303} Red
{03f90a} Green
{030af9} Blue
{ffffff} White
{f0ff00} Yellow
{8000ff} Purple
{000000} Black
{00FFFF} Cyan
{FF9900} Orange
{FF3399} Pink
{66CCFF} Light Blue
{CC6600} Brown
stock SetPlayerAnimationIndex(playerid, index, Float:fDelta, loop, lockx, locky, freeze, time)
{
static
name[32],
library[32]
;
if (1 <= index <= 1812)
{
GetAnimationName(index, name, sizeof name, library, sizeof library);
ApplyAnimation(playerid, library, name, fDelta, loop, lockx, locky, freeze, time);
}
return 1;
}