edit.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. ShowPropertyEditingDialog(playerid, propertyid)
  2. {
  3. SetPVarInt(playerid, "EditingProperty", propertyid);
  4. new string[512];
  5. strcat(string, "Please choose an option\n");
  6. strcat(string, "Set the exterior position at your current position\n");
  7. strcat(string, "Set the interior position at your current position\n");
  8. strcat(string, "Set the property interior ID\n");
  9. strcat(string, va_return("Set the owner ID{b3b3b3}(currently %d){eeeeee}\n", Property_GetOwnerSQLID(propertyid)));
  10. strcat(string, va_return("Set the type {b3b3b3}(currently %d - %s){eeeeee}\n", Property_GetType(propertyid), Property_GetTypeName(Property_GetType(propertyid))));
  11. strcat(string, va_return("Set the description {b3b3b3}(currently %s){eeeeee}\n", Property_GetDescription(propertyid)));
  12. strcat(string, va_return("Set the address {b3b3b3}(currently %s){eeeeee}\n", Property_GetAddress(propertyid)));
  13. strcat(string, va_return("Set the price {b3b3b3}(currently $%s)", MoneyFormat(Property_GetPrice(propertyid))));
  14. Dialog_ShowCallback(playerid, using public OnPlayerEditProperty<iiiis>, DIALOG_STYLE_TABLIST_HEADERS, va_return("Editing Property ID %d", propertyid), string, "Next", "Back");
  15. return 1;
  16. }
  17. forward OnPlayerEditProperty(playerid, dialogidEx, responseEx, listitemEx, string:inputtextEx[]);
  18. public OnPlayerEditProperty(playerid, dialogidEx, responseEx, listitemEx, string:inputtextEx[])
  19. {
  20. if(!responseEx)
  21. {
  22. return 0;
  23. }
  24. new propertyid = GetPVarInt(playerid, "EditingProperty");
  25. switch(listitemEx)
  26. {
  27. case 0: // set the exterior position
  28. {
  29. inline _response(response, listitem, string:inputtext[])
  30. {
  31. #pragma unused listitem, inputtext
  32. if(!response) return ShowPropertyEditingDialog(playerid, propertyid);
  33. if(!IsValidProperty(propertyid)) return SendErrorMessage(playerid, "You specified an invalid property ID.");
  34. new Float:x, Float:y, Float:z, Float:a;
  35. new int = GetPlayerInterior(playerid);
  36. new vw = GetPlayerVirtualWorld(playerid);
  37. GetPlayerPos(playerid, x, y, z);
  38. GetPlayerFacingAngle(playerid, a);
  39. foreach(new i : Player) if(GetCurrentProperty(i) == propertyid)
  40. {
  41. if(i != playerid) SendAdminWarningF(i, "%s has changed the exterior position for this property.", ReturnPlayerRPName(playerid));
  42. }
  43. Property_SetExtPos(propertyid, vw, int, x, y, z, a);
  44. SendAdminWarningF(playerid, "You've set the exterior position for this property. (ID %D)", propertyid);
  45. }
  46. Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_MSGBOX, "Set the exterior position at your current position", "{b3b3b3}Are you sure?", "Yes", "No");
  47. }
  48. case 1: // set the interior position
  49. {
  50. inline _response(response, listitem, string:inputtext[])
  51. {
  52. #pragma unused listitem, inputtext
  53. if(!response) return ShowPropertyEditingDialog(playerid, propertyid);
  54. if(!IsValidProperty(propertyid)) return SendErrorMessage(playerid, "You specified an invalid property ID.");
  55. new Float:x, Float:y, Float:z, Float:a;
  56. new int = GetPlayerInterior(playerid);
  57. GetPlayerPos(playerid, x, y, z);
  58. GetPlayerFacingAngle(playerid, a);
  59. foreach(new i : Player) if(GetCurrentProperty(i) == propertyid)
  60. {
  61. if(i != playerid) SendAdminWarningF(i, "%s has changed the interior position for this property.", ReturnPlayerRPName(playerid));
  62. SetPlayerPos(i, x, y, z);
  63. SetPlayerFacingAngle(i, a);
  64. SetPlayerInterior(i, int);
  65. SetCameraBehindPlayer(i);
  66. }
  67. Property_SetIntPos(propertyid, int, x, y, z, a);
  68. SendAdminWarningF(playerid, "You've set the interior position for this property. (ID %d)", propertyid);
  69. }
  70. Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_MSGBOX, "Set the interior position at your current position", "{b3b3b3}Are you sure?", "Yes", "No");
  71. }
  72. case 2: // Set the property interior ID
  73. {
  74. inline _response(response, listitem, string:inputtext[])
  75. {
  76. #pragma unused listitem
  77. if(!response) return ShowPropertyEditingDialog(playerid, propertyid);
  78. if(!IsValidProperty(propertyid)) return SendErrorMessage(playerid, "You specified an invalid property ID.");
  79. new interiorid;
  80. if(sscanf(inputtext, "i", interiorid) || !IsValidInterior(interiorid))
  81. {
  82. SendErrorMessage(playerid, "You specified an invalid interior ID.");
  83. return OnPlayerEditProperty(playerid, dialogidEx, responseEx, 2, inputtextEx);
  84. }
  85. new Float:x, Float:y, Float:z, Float:a;
  86. new int = Interior_GetInterior(interiorid);
  87. Interior_GetPosition(interiorid, x, y, z, a);
  88. foreach(new i : Player) if(GetCurrentProperty(i) == propertyid)
  89. {
  90. if(i != playerid) SendAdminWarningF(i, "%s has changed the interior for this property.", ReturnPlayerRPName(playerid));
  91. SetPlayerPos(i, x, y, z);
  92. SetPlayerFacingAngle(i, a);
  93. SetPlayerInterior(i, int);
  94. SetCameraBehindPlayer(i);
  95. }
  96. Property_SetIntPos(propertyid, int, x, y, z, a);
  97. OnPlayerEditProperty(playerid, dialogidEx, responseEx, 2, inputtextEx);
  98. SendAdminWarningF(playerid, "You've set Property ID %d interior to %d.", propertyid, interiorid);
  99. }
  100. Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_INPUT, "Set the property interior ID", "{b3b3b3}Type the new property interior ID", "Ok", "Back");
  101. }
  102. case 3: // Set the owner (to be updated)
  103. {
  104. inline _response(response, listitem, string:inputtext[])
  105. {
  106. #pragma unused listitem, inputtext
  107. if(!response) return ShowPropertyEditingDialog(playerid, propertyid);
  108. if(!IsValidProperty(propertyid)) return SendErrorMessage(playerid, "You specified an invalid property ID.");
  109. OnPlayerEditProperty(playerid, dialogidEx, responseEx, 3, inputtextEx);
  110. }
  111. Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_INPUT, "Set the property owner", "{b3b3b3}Type the new owner name (or ID if they're online)", "Ok", "Back");
  112. }
  113. case 4: // Set the type
  114. {
  115. inline _response(response, listitem, string:inputtext[])
  116. {
  117. #pragma unused listitem
  118. if(!response) return ShowPropertyEditingDialog(playerid, propertyid);
  119. if(!IsValidProperty(propertyid)) return SendErrorMessage(playerid, "You specified an invalid property ID.");
  120. new type;
  121. if(sscanf(inputtext, "i", type) || (!IsHouseTypeValid(type) && !IsBusinessTypeValid(type) && !IsEntranceTypeValid(type)))
  122. {
  123. SendErrorMessage(playerid, "That property type is not defined yet.");
  124. return OnPlayerEditProperty(playerid, dialogidEx, responseEx, 4, inputtextEx);
  125. }
  126. Property_SetType(propertyid, type);
  127. SendAdminWarningF(playerid, "You've set Property ID %d type to %d - %s.", propertyid, type, Property_GetTypeName(type));
  128. }
  129. Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_INPUT, "Set the property type", "{b3b3b3}Type the new property type", "Ok", "Back");
  130. }
  131. case 5: // Set the description
  132. {
  133. inline _response(response, listitem, string:inputtext[])
  134. {
  135. #pragma unused listitem
  136. if(!response) return ShowPropertyEditingDialog(playerid, propertyid);
  137. if(!IsValidProperty(propertyid)) return SendErrorMessage(playerid, "You specified an invalid property ID.");
  138. if(isnull(inputtext) || IsNumeric(inputtext))
  139. {
  140. SendErrorMessage(playerid, "You specified an invalid description.");
  141. return OnPlayerEditProperty(playerid, dialogidEx, responseEx, 5, inputtextEx);
  142. }
  143. if(strlen(inputtext) > MAX_PROP_DESCRIPTION - 1)
  144. {
  145. SendErrorMessageF(playerid, "Invalid description length, it must be below %d characters.", MAX_PROP_DESCRIPTION - 1);
  146. return OnPlayerEditProperty(playerid, dialogidEx, responseEx, 5, inputtextEx);
  147. }
  148. Property_SetDescription(propertyid, inputtext);
  149. SendAdminWarningF(playerid, "You've set Property ID %d description to %s.", propertyid, inputtext);
  150. }
  151. Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_INPUT, "Set the description", "{b3b3b3}Type the new description", "Ok", "Back");
  152. }
  153. case 6: // Set the address
  154. {
  155. inline _response(response, listitem, string:inputtext[])
  156. {
  157. #pragma unused listitem
  158. if(!response) return ShowPropertyEditingDialog(playerid, propertyid);
  159. if(!IsValidProperty(propertyid)) return SendErrorMessage(playerid, "You specified an invalid property ID.");
  160. if(isnull(inputtext) || IsNumeric(inputtext))
  161. {
  162. SendErrorMessage(playerid, "You specified an invalid address.");
  163. return OnPlayerEditProperty(playerid, dialogidEx, responseEx, 6, inputtextEx);
  164. }
  165. if(strlen(inputtext) > MAX_PROP_ADDRESS - 1)
  166. {
  167. SendErrorMessageF(playerid, "Invalid address length, it must be below %d characters.", MAX_PROP_ADDRESS - 1);
  168. return OnPlayerEditProperty(playerid, dialogidEx, responseEx, 6, inputtextEx);
  169. }
  170. Property_SetAddress(propertyid, inputtext);
  171. SendAdminWarningF(playerid, "You've set Property ID %d address to %s.", propertyid, inputtext);
  172. }
  173. Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_INPUT, "Set the address", "{b3b3b3}Type the new address", "Ok", "Back");
  174. }
  175. case 7: // Set the price
  176. {
  177. inline _response(response, listitem, string:inputtext[])
  178. {
  179. #pragma unused listitem
  180. if(!response) return ShowPropertyEditingDialog(playerid, propertyid);
  181. if(!IsValidProperty(propertyid)) return SendErrorMessage(playerid, "You specified an invalid property ID.");
  182. if(isnull(inputtext) || !IsNumeric(inputtext) || strval(inputtext) < 0)
  183. {
  184. SendErrorMessage(playerid, "You specified an invalid price.");
  185. return OnPlayerEditProperty(playerid, dialogidEx, responseEx, 7, inputtextEx);
  186. }
  187. new price = strval(inputtext);
  188. Property_SetPrice(propertyid, price);
  189. SendAdminWarningF(playerid, "You've set Property ID %d price to $%s.", propertyid, MoneyFormat(price));
  190. }
  191. Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_INPUT, "Set the price", "{b3b3b3}Type the new price", "Ok", "Back");
  192. }
  193. }
  194. return 1;
  195. }
  196. CMD:editproperty(playerid, params[])
  197. {
  198. new propertyid;
  199. if(isnull(params))
  200. {
  201. propertyid = GetCurrentProperty(playerid);
  202. if(propertyid == INVALID_PROPERTY_ID)
  203. {
  204. propertyid = GetNearbyProperty(playerid);
  205. if(propertyid == INVALID_PROPERTY_ID) return SendErrorMessage(playerid, "You need to be at one of the properties to edit it. (or type /editproperty id)");
  206. }
  207. }
  208. else
  209. {
  210. if(sscanf(params, "i", propertyid)) return SendSyntaxMessage(playerid, "/editproperty (id)");
  211. if(!IsValidProperty(propertyid)) return SendErrorMessage(playerid, "You specified an invalid property.");
  212. }
  213. ShowPropertyEditingDialog(playerid, propertyid);
  214. return 1;
  215. }