03.12.2013, 04:22
Your preferred scripting methods
Sup?
So anyways, it's that time of year again where I start developing my own gamemode (last year was a bust). Now I need opinions and I want you guys to tell me your preferred methods for scripting PAWN.
This is very similar to the coding style research thread from a while back, but this one is more advanced because I'm seeking more ways to do stuff.
1) Numerated lists
2) Player arrays
3) Functions
4) Commands
5) Single statement functions
6) Conditions
7) Loops
8) Variable grouping
9) Multiple conditions
10) Data organization
11) Formatting strings
12) Copying a string
13) Clearing or deleting a string
14) Prefixing
Thanks!
Sup?
So anyways, it's that time of year again where I start developing my own gamemode (last year was a bust). Now I need opinions and I want you guys to tell me your preferred methods for scripting PAWN.
This is very similar to the coding style research thread from a while back, but this one is more advanced because I'm seeking more ways to do stuff.
1) Numerated lists
Code:
a) #define DIALOG_PIZZA 1356 #define DIALOG_CARS 1483 #define DIALOG_GUNS 1753 #define DIALOG_STORE 1533 b) enum { DIALOG_PIZZA = 1356, DIALOG_CARS = 1483, DIALOG_GUNS = 1753, DIALOG_STORE = 1533 };
Code:
a) new Money[MAX_PLAYERS]; new Score[MAX_PLAYERS]; new JailTime[MAX_PLAYERS]; new LoggedIn[MAX_PLAYERS]; b) enum ePlayerInfo { Money, Score, JailTime, LoggedIn } new PlayerInfo[MAX_PLAYERS][ePlayerInfo];
Code:
a) stock GiveMoney(playerid, amount) { Money[playerid] += amount; return 1; } b) GiveMoney(playerid, amount) { Money[playerid] += amount; } c) forward GiveMoney(playerid, amount); public GiveMoney(playerid, amount) { Money[playerid] += amount; }
Code:
a) public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/help", true)) { SendClientMessage(playerid, -1, "My help command."); return 1; } return 0; } b) CMD:help(playerid, params[]) { SendClientMessage(playerid, -1, "My help command."); return 1; } c) public OnPlayerCommandText(playerid, cmdtext[]) { dcmd(help, playerid, 4); return 0; } dcmd_help(playerid, params[]) { #pragma unused params SendClientMessage(playerid, -1, "My help command."); return 1; }
Code:
a) stock IsPlayerLogged(playerid) { return LoggedIn[playerid]; } b) stock IsPlayerLogged(playerid) return LoggedIn[playerid]; c) #define IsPlayerLogged(%0) (LoggedIn[(%0)])
Code:
a) if (a) { b = a + 1; } else { b = a + 2; } b) if (a) b = a + 1; else b = a + 2; c) b = (a) ? (a + 1) : (a + 2);
Code:
a) for (new i = 0; i < MAX_ITEMS; i ++) { // ... } b) new i; while (i < MAX_ITEMS) { // ... i++; }
Code:
a) new a, b, c; b) new a, b, c; c) new a; new b; new c;
Code:
a) if (something == 1) { ... } else if (something == 2) { ... } else if (something == 3) { ... } b) switch (something) { case 1: { ... } case 2: { ... } case 3: { ... } } c) if (something == 1) ... else if (something == 2) ... else if (something == 3) ...
Code:
a) stock Spawn(playerid) { if (gTeam[playerid] == 1) { SetPlayerPos(playerid, 0.0, 1.0, 2.0); } else if (gTeam[playerid] == 2) { SetPlayerPos(playerid, 5.0, 10.0, 15.0); } else if (gTeam[playerid] == 3) { SetPlayerPos(playerid, 25.0, 10.0, 155.0); } } b) static const Float:g_SpawnArray[3][4] = { {0.0, 1.0, 2.0}, {5.0, 10.0, 15.0}, {25.0, 10.0, 155.0} }; stock Spawn(playerid) { SetPlayerPos(playerid, g_SpawnArray[gTeam[playerid] - 1][0], g_SpawnArray[gTeam[playerid] - 1][1], g_SpawnArray[gTeam[playerid] - 1][2]); }
Code:
a) new string[128]; format(string, sizeof(string), "Emmet is"); format(string, sizeof(string), "%s a boss.", string); b) new string[128]; strcat(string, "Emmet is"); strcat(string, " a boss");
Code:
a) new str[128]; format(str, sizeof(str), "%s", string); b) new str[128]; strcat(str, string, sizeof(str)); c) new str[128]; memcpy(str, string, 0, 512, sizeof(str));
Code:
a) string[0] = '\0'; b) strdel(string, 0, strlen(string)); c) for (new i = 0, length = strlen(string); i < length; i ++) { string[i] = 0; }
Code:
a) new score, string[128]; b) new iScore, szString[128];