Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DIALOG_ARRAY (1)
- #define DIALOG_EDIT (2)
- new Array[10];
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if(!strcmp(cmdtext, "/editarray"))
- {
- new string[1024];
- for(new i = 0; i < sizeof(Array); i++) format(string, sizeof(string), "%sArray[%d] = %d\n", string, i, Array[i]);
- ShowPlayerDialog(playerid, DIALOG_ARRAY, DIALOG_STYLE_LIST, "Edit the array as you wish:", string, "Edit", "Cancel");
- return 1;
- }
- if(!strcmp(cmdtext, "/sortarray"))
- {
- quickSort(Array, 0, sizeof(Array) - 1);
- return 1;
- }
- return 0;
- }
- //
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case DIALOG_ARRAY:
- {
- if(response)
- {
- new string[10];
- format(string, sizeof(string), "Array[%d] edition:", listitem);
- SetPVarInt(playerid, "cell", listitem);
- ShowPlayerDialog(playerid, DIALOG_EDIT, DIALOG_STYLE_INPUT, string, "Type in a number.", "Okay", "Cancel");
- }
- else SendClientMessage(playerid, -1, "You have decided to abort the array edition.");
- }
- case DIALOG_EDIT:
- {
- if(response)
- {
- Array[GetPVarInt(playerid, "cell")] = strval(inputtext);
- SendClientMessage(playerid, -1, "You have edited a number in the array, this is the refreshed one.");
- new string[1024];
- for(new i = 0; i < sizeof(Array); i++) format(string, sizeof(string), "%sArray[%d] = %d\n", string, i, Array[i]);
- ShowPlayerDialog(playerid, DIALOG_ARRAY, DIALOG_STYLE_LIST, "Edit the array as you wish:", string, "Edit", "Cancel");
- }
- else
- {
- DeletePVar(playerid, "cell");
- SendClientMessage(playerid, -1, "You have aborted the array edition.");
- }
- }
- }
- return 0;
- }
- //
- stock quickSort(array[], left, right)
- {
- new
- tempLeft = left,
- tempRight = right,
- pivot = array[(left + right) / 2],
- tempVar
- ;
- while(tempLeft <= tempRight)
- {
- while(array[tempLeft] < pivot) tempLeft++;
- while(array[tempRight] > pivot) tempRight--;
- if(tempLeft <= tempRight)
- {
- tempVar = array[tempLeft], array[tempLeft] = array[tempRight], array[tempRight] = tempVar;
- tempLeft++, tempRight--;
- }
- }
- if(left < tempRight) quickSort(array, left, tempRight);
- if(tempLeft < right) quickSort(array, tempLeft, right);
- }
- //
Advertisement
Add Comment
Please, Sign In to add comment