Guest User

3D Text Label By: DRY

a guest
Mar 1st, 2015
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.03 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dof2>
  3. #include <zcmd>
  4.  
  5. #if !defined MAX_TEXT
  6. #define MAX_TEXT ( 99 )
  7. #endif
  8.  
  9. #if !defined MAX_STRING
  10. #define MAX_STRING ( 1024 )
  11. #endif
  12.  
  13. #define FileLoad "3DTexts/%d.ini"
  14. #define cPadrao 0xE9433FFF
  15.  
  16. #define DIALOG_MAKE_LABEL 777
  17. #define DIALOG_MAKE_LABEL1 778
  18. #define DIALOG_MAKE_LABEL2 779
  19. #define DIALOG_MAKE_LABEL3 800
  20. #define DIALOG_MAKE_LABEL4 801
  21. #define DIALOG_EDIT_LABEL 802
  22. #define DIALOG_EDIT_LABELDESC 803
  23. #define DIALOG_EDIT_LABELDIST 804
  24. #define DIALOG_EDIT_LABELCOR 805
  25.  
  26. new dStr[500];
  27.  
  28. enum Params
  29. {
  30. Float:X,
  31. Float:Y,
  32. Float:Z,
  33. Float:DD,
  34. Text[128],
  35. VirtualW,
  36. bool:Loaded
  37. };
  38.  
  39. new TextInfo[MAX_TEXT][Params];
  40.  
  41. new Text3D:label[MAX_TEXT];
  42.  
  43. new labelid[MAX_PLAYERS],
  44. Float: nX[MAX_PLAYERS],
  45. Float: nZ[MAX_PLAYERS],
  46. Float: nY[MAX_PLAYERS],
  47. nDD[MAX_PLAYERS],
  48. nText[MAX_PLAYERS][128],
  49. nColor[MAX_PLAYERS][128],
  50. bool:Editando[MAX_PLAYERS];
  51.  
  52. public OnFilterScriptInit()
  53. {
  54. LoadTexts();
  55. return 1;
  56. }
  57.  
  58. public OnFilterScriptExit()
  59. {
  60. UnLoadSaveTexts();
  61. return 1;
  62. }
  63.  
  64. CMD:makelabel(playerid)
  65. {
  66. if ( !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, cPadrao, "Você não tem permissão para isso.");
  67. new Str[500];
  68. GetPlayerPos(playerid, nX[playerid], nY[playerid], nZ[playerid]);
  69. format ( Str, sizeof ( Str ), "{FFFFFF}Olá, bem vindo ao assiste de 3DLabel\n\nPos X: {E9433F}%f\n{FFFFFF}Pos Y: {E9433F}%f\n{FFFFFF}Pos Z: {E9433F}%f\n\n{FFFFFF}Deseja criar uma label neste local ?", nX, nY, nZ);
  70. ShowPlayerDialog(playerid, DIALOG_MAKE_LABEL, DIALOG_STYLE_MSGBOX, "{FFFFFF}Label Create", Str, "Sim", "Não");
  71. return 1;
  72. }
  73.  
  74. CMD:editlabel(playerid)
  75. {
  76. for ( new t; t < MAX_TEXT; t++)
  77. {
  78. if ( TextInfo[t][Loaded] == true)
  79. {
  80. if ( IsPlayerInRangeOfPoint(playerid, 1.0, TextInfo[t][X], TextInfo[t][Y], TextInfo[t][Z]))
  81. {
  82. ShowPlayerDialog(playerid, DIALOG_EDIT_LABEL, DIALOG_STYLE_LIST, "{FFFFFF}Edit Label", "{FFFFFF}- Deletar\n- Alterar Texto\n- Alterar Distância\n- Alterar Cor\n- Alterar Posição", "Selecionar", "Sair");
  83. labelid[playerid] = t;
  84. }
  85. }
  86. }
  87. return 1;
  88. }
  89.  
  90. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  91. {
  92. if ( dialogid == DIALOG_MAKE_LABEL)
  93. {
  94. if ( response )
  95. {
  96. ShowPlayerDialog(playerid, DIALOG_MAKE_LABEL1, DIALOG_STYLE_INPUT, "{FFFFFF}Label Create", "{FFFFFF}Vamos em frente!\n\nPor favor, nos informe o texto a ser exibido:", "Proximo", "Sair");
  97. }
  98. else
  99. {
  100. nX[playerid] = 0;
  101. nZ[playerid] = 0;
  102. nY[playerid] = 0;
  103. nDD[playerid] = 0;
  104. nColor[playerid] = "";
  105. nText[playerid] = "";
  106. }
  107. }
  108. if ( dialogid == DIALOG_MAKE_LABEL1)
  109. {
  110. if ( response )
  111. {
  112. new deStr[MAX_STRING];
  113. format ( nText[playerid], 128, "%s" ,inputtext);
  114. format ( deStr, MAX_STRING, "{FFFFFF}Precesso Atual:\n\nTexto: {E9433F}%s{FFFFFF}\n\n Agora nos informe uma distancia para a label ser exibida:", nText[playerid]);
  115. ShowPlayerDialog(playerid, DIALOG_MAKE_LABEL2, DIALOG_STYLE_INPUT, "{FFFFFF}Label Create", deStr, "Proximo", "Sair");
  116. }
  117. else
  118. {
  119. nX[playerid] = 0;
  120. nZ[playerid] = 0;
  121. nY[playerid] = 0;
  122. nDD[playerid] = 0;
  123. nColor[playerid] = "";
  124. nText[playerid] = "";
  125. }
  126. }
  127. if ( dialogid == DIALOG_MAKE_LABEL2)
  128. {
  129. if ( response )
  130. {
  131. new deStr[MAX_STRING];
  132. nDD[playerid] = strval(inputtext);
  133. format ( deStr, MAX_STRING, "{FFFFFF}Precesso Atual:\n\nTexto: {E9433F}%s\n{FFFFFF}Distância: {E9433F}%d{E9433F}\n\n Insira uma cor:", nText[playerid], nDD[playerid]);
  134. ShowPlayerDialog(playerid, DIALOG_MAKE_LABEL3, DIALOG_STYLE_INPUT, "{FFFFFF}Label Create", deStr, "Proximo", "Sair");
  135. }
  136. else
  137. {
  138. nX[playerid] = 0;
  139. nZ[playerid] = 0;
  140. nY[playerid] = 0;
  141. nDD[playerid] = 0;
  142. nColor[playerid] = "";
  143. nText[playerid] = "";
  144. }
  145. }
  146. if ( dialogid == DIALOG_MAKE_LABEL3)
  147. {
  148. if ( response )
  149. {
  150. new deStr[MAX_STRING];
  151. format ( nColor[playerid], 128, "%s", inputtext);
  152. format ( deStr, MAX_STRING, "{FFFFFF}Precesso Atual:\n\nTexto: {E9433F}%s\n{FFFFFF}Distância: {E9433F}%d{FFFFFF}\nCor: {E9433F}%s{FFFFFF}\n\n Deseja criar ?", nText[playerid], nDD[playerid], nColor[playerid]);
  153. ShowPlayerDialog(playerid, DIALOG_MAKE_LABEL4, DIALOG_STYLE_MSGBOX, "{FFFFFF}Label Create", deStr, "Criar", "Sair");
  154. }
  155. else
  156. {
  157. nX[playerid] = 0;
  158. nZ[playerid] = 0;
  159. nY[playerid] = 0;
  160. nDD[playerid] = 0;
  161. nColor[playerid] = "";
  162. nText[playerid] = "";
  163. }
  164. }
  165. if ( dialogid == DIALOG_MAKE_LABEL4)
  166. {
  167. if ( response )
  168. {
  169. Make3DText(nText[playerid], nColor[playerid], nX[playerid], nY[playerid], nZ[playerid], nDD[playerid], 0);
  170. }
  171. else
  172. {
  173. nX[playerid] = 0;
  174. nZ[playerid] = 0;
  175. nY[playerid] = 0;
  176. nDD[playerid] = 0;
  177. nColor[playerid] = "";
  178. nText[playerid] = "";
  179. }
  180. }
  181. if ( dialogid == DIALOG_EDIT_LABEL)
  182. {
  183. if ( response )
  184. {
  185. if ( listitem == 0 )
  186. {
  187. new deStr[128], lid = labelid[playerid];
  188. format ( deStr, 128, FileLoad, lid);
  189. TextInfo[lid][Loaded] = false;
  190. DOF2::RemoveFile(deStr);
  191. Delete3DTextLabel(label[lid]);
  192. UnLoadSaveTexts();
  193. LoadTexts();
  194. }
  195. if ( listitem == 1 )
  196. {
  197. new deStr[MAX_STRING], lid = labelid[playerid];
  198. format ( deStr, MAX_STRING, "Descrição atual: {E9433F}%s{FFFFFF}\n\nInsira uma nova descrição:", TextInfo[lid][Text]);
  199. ShowPlayerDialog(playerid, DIALOG_EDIT_LABELDESC, DIALOG_STYLE_INPUT, "Edit Label", deStr, "Editar", "Sair");
  200. }
  201. if ( listitem == 2 )
  202. {
  203. new xStr[128], deStr[MAX_STRING], lid = labelid[playerid];
  204. format (xStr, 128, FileLoad, lid);
  205. format ( deStr, MAX_STRING, "Distância atual: %s\n\nInsira uma nova distãncia:", DOF2::GetString(xStr, "TEXT3D_DrawDistance"));
  206. ShowPlayerDialog(playerid, DIALOG_EDIT_LABELDIST, DIALOG_STYLE_INPUT, "Edit Label", deStr, "Editar", "Sair");
  207. }
  208. if ( listitem == 3 )
  209. {
  210. new xStr[128], deStr[MAX_STRING], lid = labelid[playerid];
  211. format (xStr, 128, FileLoad, lid);
  212. format ( deStr, MAX_STRING, "Cor atual: %s\n\nInsira uma nova cor:", DOF2::GetString(xStr, "TEXT3D_COLOR"));
  213. ShowPlayerDialog(playerid, DIALOG_EDIT_LABELCOR, DIALOG_STYLE_INPUT, "Edit Label", deStr, "Editar", "Sair");
  214. }
  215. if ( listitem == 4 )
  216. {
  217. SendClientMessage(playerid, cPadrao, "Dirija-se ao novo local e pressione ' y '");
  218. Editando[playerid] = true;
  219. }
  220. }
  221. else
  222. {
  223. labelid[playerid] = INVALID_3DTEXT_ID;
  224. nX[playerid] = 0;
  225. nZ[playerid] = 0;
  226. nY[playerid] = 0;
  227. nDD[playerid] = 0;
  228. nColor[playerid] = "";
  229. nText[playerid] = "";
  230. }
  231. }
  232. if ( dialogid == DIALOG_EDIT_LABELDESC)
  233. {
  234. if ( response )
  235. {
  236. new lid = labelid[playerid];
  237. format ( TextInfo[lid][Text], 128, "%s", inputtext);
  238. UnLoadSaveTexts();
  239. LoadTexts();
  240. }
  241. else
  242. {
  243. labelid[playerid] = INVALID_3DTEXT_ID;
  244. nX[playerid] = 0;
  245. nZ[playerid] = 0;
  246. nY[playerid] = 0;
  247. nDD[playerid] = 0;
  248. nColor[playerid] = "";
  249. nText[playerid] = "";
  250. }
  251. }
  252. if ( dialogid == DIALOG_EDIT_LABELDIST)
  253. {
  254. if ( response )
  255. {
  256. new xStr[128], lid = labelid[playerid];
  257. format (xStr, 128, FileLoad, lid);
  258. TextInfo[lid][DD] = strval(inputtext);
  259. UnLoadSaveTexts();
  260. LoadTexts();
  261. }
  262. else
  263. {
  264. labelid[playerid] = INVALID_3DTEXT_ID;
  265. nX[playerid] = 0;
  266. nZ[playerid] = 0;
  267. nY[playerid] = 0;
  268. nDD[playerid] = 0;
  269. nColor[playerid] = "";
  270. nText[playerid] = "";
  271. }
  272. }
  273. if ( dialogid == DIALOG_EDIT_LABELCOR)
  274. {
  275. if ( response )
  276. {
  277. new xStr[128], lid = labelid[playerid];
  278. format (xStr, 128, FileLoad, lid);
  279. DOF2::SetString(xStr, "TEXT3D_COLOR", inputtext);
  280. UnLoadSaveTexts();
  281. LoadTexts();
  282. }
  283. else
  284. {
  285. labelid[playerid] = INVALID_3DTEXT_ID;
  286. nX[playerid] = 0;
  287. nZ[playerid] = 0;
  288. nY[playerid] = 0;
  289. nDD[playerid] = 0;
  290. nColor[playerid] = "";
  291. nText[playerid] = "";
  292. }
  293. }
  294. return 1;
  295. }
  296.  
  297. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  298. {
  299. if ( newkeys == 65536)
  300. {
  301. if ( Editando[playerid] == true)
  302. {
  303. new textt = labelid[playerid];
  304. GetPlayerPos(playerid, nX[playerid], nY[playerid], nZ[playerid]);
  305. TextInfo[textt][X] = nX[playerid];
  306. TextInfo[textt][Y] = nY[playerid];
  307. TextInfo[textt][Z] = nZ[playerid];
  308. UnLoadSaveTexts();
  309. LoadTexts();
  310. return 1;
  311. }
  312. }
  313. return 1;
  314. }
  315.  
  316. LoadTexts()
  317. {
  318. for ( new t = 0; t < MAX_TEXT; t++)
  319. {
  320. format ( dStr, sizeof ( dStr ), FileLoad, t);
  321. if ( DOF2::FileExists(dStr))
  322. {
  323. TextInfo[t][Loaded] = DOF2::GetBool(dStr, "TEXT3D_Created");
  324. TextInfo[t][X] = DOF2::GetFloat(dStr, "TEXT3D_PosX");
  325. TextInfo[t][Y] = DOF2::GetFloat(dStr, "TEXT3D_PosY");
  326. TextInfo[t][Z] = DOF2::GetFloat(dStr, "TEXT3D_PosZ");
  327. TextInfo[t][DD] = DOF2::GetFloat(dStr, "TEXT3D_DrawDistance");
  328. TextInfo[t][VirtualW] = DOF2::GetInt(dStr, "TEXT3D_VirtualW");
  329. format ( TextInfo[t][Text], 128, "%s", DOF2::GetString(dStr, "TEXT3D_STRING"));
  330. label[t] = Create3DTextLabel(TextInfo[t][Text], DOF2::GetHex(dStr, "TEXT3D_COLOR"), TextInfo[t][X], TextInfo[t][Y], TextInfo[t][Z], TextInfo[t][DD], TextInfo[t][VirtualW], 0);
  331. }
  332. }
  333. }
  334.  
  335. UnLoadSaveTexts()
  336. {
  337. for ( new t = 0; t < MAX_TEXT; t++)
  338. {
  339. format ( dStr, sizeof ( dStr ), FileLoad, t);
  340. if ( !DOF2::FileExists(dStr) && TextInfo[t][Loaded] == true) DOF2::CreateFile(dStr);
  341. if ( TextInfo[t][Loaded] == true )
  342. {
  343. DOF2::SetBool(dStr, "TEXT3D_Created", TextInfo[t][Loaded]);
  344. DOF2::SetFloat(dStr, "TEXT3D_PosX", TextInfo[t][X]);
  345. DOF2::SetFloat(dStr, "TEXT3D_PosY", TextInfo[t][Y]);
  346. DOF2::SetFloat(dStr, "TEXT3D_PosZ", TextInfo[t][Z]);
  347. DOF2::SetFloat(dStr, "TEXT3D_DrawDistance", TextInfo[t][DD]);
  348. DOF2::SetInt(dStr, "TEXT3D_VirtualW", TextInfo[t][VirtualW]);
  349. DOF2::SetString(dStr, "TEXT3D_STRING", TextInfo[t][Text]);
  350. DOF2::SaveFile();
  351. TextInfo[t][Loaded] = false;
  352. Delete3DTextLabel(label[t]);
  353. }
  354. }
  355. return 1;
  356. }
  357.  
  358. Make3DText(text[], dcolor[], Float: dX, Float: dY, Float: dZ, Float: Distance, VW)
  359. {
  360. for ( new t = 0; t < MAX_TEXT; t++)
  361. {
  362. if ( TextInfo[t][Loaded] == false)
  363. {
  364. format ( dStr, sizeof ( dStr ), FileLoad, t);
  365. DOF2::CreateFile(dStr);
  366. if ( !DOF2::FileExists(dStr)) return printf ("O 3DText %d não foi criado", t);
  367. TextInfo[t][Loaded] = true;
  368. TextInfo[t][X] = dX;
  369. TextInfo[t][Y] = dY;
  370. TextInfo[t][Z] = dZ;
  371. TextInfo[t][DD] = Distance;
  372. TextInfo[t][VirtualW] = VW;
  373. format ( TextInfo[t][Text], 128, "%s", text);
  374. DOF2::SetString(dStr, "TEXT3D_COLOR", dcolor);
  375. DOF2::SaveFile();
  376. label[t] = Create3DTextLabel(TextInfo[t][Text], DOF2::GetHex(dStr, "TEXT3D_COLOR"), TextInfo[t][X], TextInfo[t][Y], TextInfo[t][Z], TextInfo[t][DD], TextInfo[t][VirtualW], 0);
  377. UnLoadSaveTexts();
  378. LoadTexts();
  379. break;
  380. }
  381. }
  382. return 1;
  383. }
Advertisement
Add Comment
Please, Sign In to add comment