This will return in what range a file size is in.. supports Bytes, KB, MB, and GB...
Код:
GetFileSizeInBytes(file[]) { if(!fexist(file)) return 0; new t; new kb,mb,fl; new File:raw; raw = fopen(file); fl = flength(raw); mb = 1073741824/fl; kb = 1024/fl; if(fl > 1024 && fl < 1048576) { return 1; // 1 = file is in KB } if(fl >= 1048576) { return 2; // 2 = file is in MB } if(fl >= 1073741824) { return 3; // 3 = file is in GB } return 4; } ![]() |
#define cformat(%0,%1,%2); format(%0,sizeof %0,%1,%2); //used for formats with one parameter
#define cGetPlayerName(%0,%1); GetPlayerName(%0,%1,MAX_PLAYER_NAME);
Example of standart use:
new Name[MAX_PLAYER_NAME], string[121];
GetPlayerName(playerid,Name,MAX_PLAYER_NAME);
format(string,sizeof (string),"%s was comited suicide",Name);
printf("%s",string);
Example of use without standart parameters :
new Name[MAX_PLAYER_NAME], string[121];
cGetPlayerName(playerid,Name);
cformat(string,"%s was comited suicide",Name);
printf("%s",string);
//You can make this for any functions, it is only a example.
pawn Код:
|
y += (10.4632134 * floatcos(-fa,degrees)); |
new VALUE = 5;
#define returnValue(%0) %0 * VALUE
stock SetNewValue(value) return VALUE = value;
//example
SetNewValue(8);
printf("%i", returnValue(6)); // back 48 (because 8 * 6 = 48)
AddLineBreaks(input[], chars=80)
{
new output[512];
format(output, sizeof(output), "%s", input);
for(new i, j, o = strlen(output); i < o; i++, j++)
{
if(j >= chars && output[i] == ' ')
{
output[i] = '\n';
j = 0;
}
}
return output;
}
stock IsPlayerOutOfArea(playerid, Float:MinX, Float:MinY, Float:MaxX, Float:MaxY)
{
new
Float:X,
Float:Y,
Float:Z
;
GetPlayerPos(playerid, X, Y, Z);
if(X >= MaxX && Y >= MaxY && X <= MinX && Y <= MinY) return 1;
return 0;
}
IsPlayerOutOfArea pawn Код:
|
* AddLineBreaks(input[], chars=80)
This function is meant to be used by DIALOG_STYLE_MSGBOX dialogs, when it is desired to show a large string, and this string to be split into several lines. It adds the line breaks just if it finds a ' ' (space) character. - Parameters: -- input[]: The string to be split. -- chars[]: How many minimum characters should show per line (default: 80). - Returns: -- The formatted string. pawn Code:
|
stock
AddLineBreaks(input[], chars = 80)
{
new
Count = 1,
i = chars,
output[512];
format(output, sizeof(output), "%s", input);
while(output[i])
{
// if(i % chars) { printf("Loop: %d", i); } else { printf(" Start chars Index: %d", i); } // DEBUG
if(output[i] == ' ')
{
output[i] = '\n';
i = chars * (++Count);
} else i--;
}
return output;
}
public
OnFilterScriptInit()
{
printf("%s", AddLineBreaks("This function is meant to be used by DIALOG_STYLE_MSGBOX dialogs, when it is desired to show a large string, and this string to be split into several lines. It adds the line breaks just if it finds a ' ' (space) character. - Parameters: -- input[]: The string to be split. -- chars[]: How many minimum characters should show per line (default: 80). - Returns: -- The formatted string"));
printf("%s", AddLineBreaks("This function is meant to be used by DIALOG_STYLE_MSGBOX dialogs, when it is desired to show a large string, and this string to be split into several lines. It adds the line breaks just if it finds a ' ' (space) character. - Parameters: -- input[]: The string to be split. -- chars[]: How many minimum characters should show per line (default: 80). - Returns: -- The formatted string", 20));
return 1;
}
[11:21:18] Start chars Index 80 [11:21:18] Loop: 79 [11:21:19] Loop: 78 [11:21:19] Loop: 77 [11:21:19] Loop: 76 [11:21:19] Start chars Index 160 [11:21:19] Loop: 159 [11:21:19] Start chars Index 240 [11:21:19] Loop: 239 [11:21:19] Start chars Index 320 [11:21:19] Loop: 319 [11:21:19] This function is meant to be used by DIALOG_STYLE_MSGBOX dialogs, when it is desired to show a large string, and this string to be split into several lines. It adds the line breaks just if it finds a ' ' (space) character. - Parameters: -- input[]: The string to be split. -- chars[]: How many minimum characters should show per line (default: 80). - Returns: -- The formatted string [11:21:19] Start chars Index 20 [11:21:19] Loop: 19 [11:21:19] Loop: 18 [11:21:19] Loop: 17 [11:21:19] Loop: 16 [11:21:19] Start chars Index 40 [11:21:19] Loop: 39 [11:21:19] Loop: 38 [11:21:19] Loop: 37 [11:21:19] Loop: 36 [11:21:19] Start chars Index 60 [11:21:19] Loop: 59 [11:21:19] Loop: 58 [11:21:19] Loop: 57 [11:21:19] Loop: 56 [11:21:19] Start chars Index 80 [11:21:19] Loop: 79 [11:21:19] Loop: 78 [11:21:19] Loop: 77 [11:21:19] Loop: 76 [11:21:19] Start chars Index 100 [11:21:19] Start chars Index 120 [11:21:19] Loop: 119 [11:21:19] Loop: 118 [11:21:19] Loop: 117 [11:21:19] Start chars Index 140 [11:21:19] Loop: 139 [11:21:19] Loop: 138 [11:21:19] Loop: 137 [11:21:19] Loop: 136 [11:21:19] Start chars Index 160 [11:21:19] Loop: 159 [11:21:19] Start chars Index 180 [11:21:19] Start chars Index 200 [11:21:19] Loop: 199 [11:21:19] Start chars Index 220 [11:21:19] Loop: 219 [11:21:19] Loop: 218 [11:21:19] Loop: 217 [11:21:19] Loop: 216 [11:21:19] Loop: 215 [11:21:19] Loop: 214 [11:21:19] Loop: 213 [11:21:19] Loop: 212 [11:21:19] Loop: 211 [11:21:19] Start chars Index 240 [11:21:19] Loop: 239 [11:21:19] Start chars Index 260 [11:21:19] Loop: 259 [11:21:19] Start chars Index 280 [11:21:19] Loop: 279 [11:21:19] Loop: 278 [11:21:19] Loop: 277 [11:21:19] Loop: 276 [11:21:19] Loop: 275 [11:21:19] Start chars Index 300 [11:21:19] Loop: 299 [11:21:19] Loop: 298 [11:21:19] Loop: 297 [11:21:19] Loop: 296 [11:21:19] Loop: 295 [11:21:19] Loop: 294 [11:21:19] Loop: 293 [11:21:19] Start chars Index 320 [11:21:19] Loop: 319 [11:21:19] Start chars Index 340 [11:21:19] Loop: 339 [11:21:19] Loop: 338 [11:21:19] Loop: 337 [11:21:19] Loop: 336 [11:21:19] Loop: 335 [11:21:19] Loop: 334 [11:21:19] Loop: 333 [11:21:19] Start chars Index 360 [11:21:19] Loop: 359 [11:21:19] Start chars Index 380 [11:21:19] Loop: 379 [11:21:19] Loop: 378 [11:21:19] Loop: 377 [11:21:19] Loop: 376 [11:21:19] This function is meant to be used by DIALOG_STYLE_MSGBOX dialogs, when it is desired to show a large string, and this string to be split into several lines. It adds the line breaks just if it finds a ' ' (space) character. - Parameters: -- input[]: The string to be split. -- chars[]: How many minimum characters should show per line (default: 80). - Returns: -- The formatted string
stock SendERROR(playerid, error)
{
if(error == 1) return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
if(error == 2) return SendClientMessage(playerid,red,"ERROR: Player is not connected");
if(error == 3) return SendClientMessage(playerid,red,"ERROR: Player is not connected or is yourself or is highest level admin");
if(error == 4) return SendClientMessage(playerid,red,"ERROR: You need to be Level 4 to use this Command");
if(error == 5) return SendClientMessage(playerid,red,"ERROR: You need to be Level 3 to use this Command");
if(error == 6) return SendClientMessage(playerid,red,"ERROR: You need to be Level 2 to use this Command");
if(error == 7) return SendClientMessage(playerid,red,"ERROR: You need to be Level 1 to use this Command");
if(error == 8) return SendClientMessage(playerid,red,"ERROR: You need to be Level 5 to use this Command");
if(error == 9) return SendClientMessage(playerid,red,"ERROR: You need to be Level 6 to use this Command");
if(error == 10) return SendClientMessage(playerid,red,"ERROR: You need to be Level 7 to use this Command");
if(error == 11) return SendClientMessage(playerid,red,"ERROR: You need to be Level 8 to use this Command");
if(error == 12) return SendClientMessage(playerid,red,"ERROR: You are not in a vehicle");
return 1;
}
stock DestroyVehicle2(vehicleid)
{
OnVehicleDeath(vehicleid, INVALID_PLAYER_ID);
return DestroyVehicle(vehicleid);
}
Makes it a lot clearer which error you're sending - yours were in an almost random order, especially the levels, which went 4, 3, 2, 1, 5, 6, 7, 8... Now you can do:
pawn Код:
pawn Код:
|
stock SaveStringToFile(content[], filename[]) { new File:usfl = fopen(filename, io_append); fwrite(usfl, content); fclose(usfl); }
} else //A login code above this, don't need it here ;) So this 'else' means: WRONG PASSWORD { new year,month,day,hours,minutes,seconds; getdate(year,month,day);gettime(hours,minutes,seconds); Kick(playerid); format(string, sizeof(string), "%s [%d-%d-%d %d:%d:%d], Kicked by: ADMIN BOT\r\n", PlayerName[playerid], day, month, year, hours, minutes, seconds); SaveStringToFile(string, "LOGS/KickLog.log"); }
LineCount(filepath[])
{
new idx = 0;
if(fexist(filepath))
{
new File:Handler, string[1028];
Handler = fopen(filepath, io_read);
while(fread(Handler, string)){idx++;}
fclose(Handler);
}
return idx;
}
printf("There are currently %d players banned.",LineCount("List.ban"));
#define MAX_INI_ENTRY_TEXT 80 stock DB_Escape(text[]) { new ret[MAX_INI_ENTRY_TEXT * 2], ch, i, j; while ((ch = text[i++]) && j < sizeof (ret)) { if (ch == '\'') { if (j < sizeof (ret) - 2) { ret[j++] = '\''; ret[j++] = '\''; } } else if (j < sizeof (ret)) { ret[j++] = ch; } else { j++; } } ret[sizeof (ret) - 1] = '\0'; return ret; }
Nice function, but why don't you escape them instead of adding whitespace?
This is an escape function made by ******: Код:
#define MAX_INI_ENTRY_TEXT 80 stock DB_Escape(text[]) { new ret[MAX_INI_ENTRY_TEXT * 2], ch, i, j; while ((ch = text[i++]) && j < sizeof (ret)) { if (ch == '\'') { if (j < sizeof (ret) - 2) { ret[j++] = '\''; ret[j++] = '\''; } } else if (j < sizeof (ret)) { ret[j++] = ch; } else { j++; } } ret[sizeof (ret) - 1] = '\0'; return ret; } |