| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- #include <YSI_Coding\y_hooks>
- #define MAX_INTERIORS 40
- #define MAX_INTERIOR_NAME 57
- static IntName[MAX_INTERIORS][MAX_INTERIOR_NAME];
- static IntInterior[MAX_INTERIORS];
- static Float:IntPosX[MAX_INTERIORS];
- static Float:IntPosY[MAX_INTERIORS];
- static Float:IntPosZ[MAX_INTERIORS];
- static Float:IntPosA[MAX_INTERIORS];
- new Iterator:Interior<MAX_INTERIORS>;
- hook OnMySQLConnected()
- {
- inline const OnInteriorFound()
- {
- for(new i; i < cache_num_rows(); i++)
- {
- if(Iter_Free(Interior) == INVALID_ITERATOR_SLOT)
- {
- printf("The maximum amount of interiors has been reached. (%d)", Iter_Count(Interior));
- break;
- }
- new interiorid = INVALID_ITERATOR_SLOT;
- cache_get_value_name_int(i, "id", interiorid);
- cache_get_value_name(i, "name", IntName[interiorid]);
- cache_get_value_name_int(i, "interior", IntInterior[interiorid]);
- cache_get_value_name_float(i, "pos_x", IntPosX[interiorid]);
- cache_get_value_name_float(i, "pos_y", IntPosY[interiorid]);
- cache_get_value_name_float(i, "pos_z", IntPosZ[interiorid]);
- cache_get_value_name_float(i, "pos_a", IntPosA[interiorid]);
- Iter_Add(Interior, interiorid);
- }
- }
- MySQL_TQueryInline(MySQL_GetHandle(), using inline OnInteriorFound, "SELECT * FROM interiors");
- }
- ShowAvailableInteriors(playerid)
- {
- new count;
- new listitemEx[MAX_INTERIORS];
- new string[1024];
- strcat(string, "These are the available interiors:\n");
- foreach(new i : Interior)
- {
- listitemEx[count] = i;
- count++;
- strcat(string, va_return("%d. %s\n", i, IntName[i]));
- }
- inline _response(response, listitem, string:inputtext[])
- {
- #pragma unused inputtext
- if(!response) return 0;
- ShowInteriorMenu(playerid, listitemEx[listitem]);
- }
- Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_TABLIST_HEADERS, "Available interiors", string, "Next", "Close");
- return 1;
- }
- ShowInteriorMenu(playerid, interiorid)
- {
- inline _response(responseEx, listitemEx, string:inputtextEx[])
- {
- #pragma unused inputtextEx
- if(!responseEx) return ShowAvailableInteriors(playerid);
- switch(listitemEx)
- {
- case 0: // Edit the name
- {
- inline NameInput(response, listitem, string:inputtext[])
- {
- #pragma unused listitem
- if(!response) return ShowInteriorMenu(playerid, interiorid);
- if(isnull(inputtext) || IsNumeric(inputtext))
- {
- SendErrorMessage(playerid, "You specified an invalid name.");
- return ShowInteriorMenu(playerid, interiorid);
- }
- if(strlen(inputtext) > MAX_INTERIOR_NAME - 1)
- {
- SendErrorMessageF(playerid, "Invalid name length, it must be below %d characters.", MAX_INTERIOR_NAME - 1);
- return ShowInteriorMenu(playerid, interiorid);
- }
- format(IntName[interiorid], MAX_INTERIOR_NAME, inputtext);
- new query[128];
- mysql_format(MySQL_GetHandle(), query, sizeof(query), "UPDATE interiors SET name = '%e' WHERE id = %d", inputtext, interiorid);
- mysql_tquery(MySQL_GetHandle(), query);
- SendAdminWarningF(playerid, "You've set Interior ID %d name to %s.", interiorid, inputtext);
- }
- Dialog_ShowCallback(playerid, using inline NameInput, DIALOG_STYLE_INPUT, "Set the name", "{b3b3b3}Type the new name", "Ok", "Back");
- }
- case 1: // Teleport to interior
- {
- SetPlayerPos(playerid, IntPosX[interiorid], IntPosY[interiorid], IntPosZ[interiorid]);
- SetPlayerFacingAngle(playerid, IntPosA[interiorid]);
- SetPlayerInterior(playerid, IntInterior[interiorid]);
- SetCameraBehindPlayer(playerid);
- }
- case 2: // Delete the interior
- {
- inline DoubleCheck(pid, dialogid, response, listitem, string:inputtext[])
- {
- #pragma unused pid, dialogid, listitem, inputtext
- if(!response) return ShowInteriorMenu(playerid, interiorid);
- new query[78];
- mysql_format(MySQL_GetHandle(), query, sizeof(query), "DELETE FROM interiors WHERE id = %d", interiorid);
- mysql_tquery(MySQL_GetHandle(), query);
- Iter_Remove(Interior, interiorid);
- SendAdminWarningF(playerid, "You have deleted an interior. (ID %d)", interiorid);
- }
- Dialog_ShowCallback(playerid, using inline DoubleCheck, DIALOG_STYLE_MSGBOX, va_return("Deleting Interior ID %d", interiorid), "{b3b3b3}Are you sure?", "Yes", "No");
- }
- }
- }
- new string[182];
- strcat(string, "Please choose an option\n");
- strcat(string, va_return("Set the name {b3b3b3}(currently %s){eeeeee}\n", IntName[interiorid]));
- strcat(string, "Teleport to this interior\n");
- strcat(string, "{ff6666}Delete this interior");
- Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_TABLIST_HEADERS, va_return("Interior ID %d", interiorid), string, "Next", "Back");
- return 1;
- }
- CMD:createinterior(playerid, params[])
- {
- if(Iter_Free(Interior) == INVALID_ITERATOR_SLOT) return SendErrorMessage(playerid, "The maximum amount of interiors has been reached.");
- if(isnull(params))
- return SendSyntaxMessage(playerid, "/createinterior (name)");
- if(strlen(params) > MAX_INTERIOR_NAME - 1)
- return SendErrorMessageF(playerid, "Invalid name length, it must be below %d characters.", MAX_INTERIOR_NAME - 1);
- new Float:x, Float:y, Float:z, Float:a;
- GetPlayerPos(playerid, x, y, z);
- GetPlayerFacingAngle(playerid, a);
- new interiorid = Iter_Free(Interior);
- new int = GetPlayerInterior(playerid);
- IntInterior[interiorid] = int;
- IntPosX[interiorid] = x;
- IntPosY[interiorid] = y;
- IntPosZ[interiorid] = z;
- IntPosA[interiorid] = a;
- format(IntName[interiorid], MAX_INTERIOR_NAME, params);
- new query[236];
- mysql_format(MySQL_GetHandle(), query, sizeof(query), "INSERT INTO interiors (id, name, interior, pos_x, pos_y, pos_z, pos_a) VALUES (%d, '%e', %d, %f, %f, %f, %f)", interiorid, params, int, x, y, z, a);
- mysql_tquery(MySQL_GetHandle(), query);
- Iter_Add(Interior, interiorid);
- SendAdminWarningF(playerid, "You have created an interior. ID: %d, Name: %s", interiorid, params);
- return 1;
- }
- CMD:interiors(playerid, params[])
- {
- ShowAvailableInteriors(playerid);
- return 1;
- }
- stock Interior_GetName(interiorid)
- {
- return IntName[interiorid];
- }
- stock Interior_GetInterior(interiorid)
- {
- return IntInterior[interiorid];
- }
- stock Interior_GetPosition(interiorid, &Float:x, &Float:y, &Float:z, &Float:a = 0.0)
- {
- x = IntPosX[interiorid];
- y = IntPosY[interiorid];
- z = IntPosZ[interiorid];
- a = IntPosA[interiorid];
- }
- stock bool:IsValidInterior(interiorid)
- {
- if(Iter_Contains(Interior, interiorid))
- {
- return true;
- }
- return false;
- }
|