Guest User

AirAdvertisingBoards v0.1

a guest
Apr 29th, 2015
956
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // AirAdvertising boards v0.1 //
  2.  
  3. #define FILTERSCRIPT
  4.  
  5. #include <a_samp>
  6.  
  7.  
  8. #define MAX_BOARDS 51
  9.  
  10. #define COLOR_ALIREZA 0xFFFFFFFF
  11. #define COLOR_GREY 0xAFAFAFFF
  12.  
  13. #include <zcmd>
  14. #include <streamer>
  15. #include <sscanf>
  16.  
  17. new bEdit[MAX_PLAYERS]; //
  18. new bEditID[MAX_PLAYERS]; // Object's ID
  19. new Float:bPos[MAX_PLAYERS][3];
  20. new Float:bRot[MAX_PLAYERS][3];
  21.  
  22. public OnFilterScriptInit()
  23. {
  24. print("\n--------------------------------------");
  25. print(" ------AirAdvertising boards v0.1-------");
  26. print("--------------------------------------\n");
  27. LoadBoards();
  28. return 1;
  29. }
  30. enum boardInfo
  31. {
  32. bBoard,
  33. Text3D:bText,
  34. bModel,
  35. Float:bCX,
  36. Float:bCY,
  37. Float:bCZ,
  38. Float:bCRX,
  39. Float:bCRY,
  40. Float:bCRZ,
  41. bStatus,
  42. bTextM[128],
  43. bFontSiz
  44. }
  45. new BoardInfo[MAX_BOARDS][boardInfo];
  46.  
  47.  
  48. stock LoadBoards()
  49. {
  50.  
  51. new dinfo[9][128];
  52. new string[256];
  53. if(!fexist("boards.cfg")) fcreate("boards.cfg");
  54. new File:file = fopen("boards.cfg", io_read);
  55. if(file)
  56. {
  57. new idx = 1;
  58. while(idx < MAX_BOARDS)
  59. {
  60. fread(file, string);
  61. split(string, dinfo, '|');
  62. BoardInfo[idx][bModel] = strval(dinfo[0]);
  63. BoardInfo[idx][bCX] = floatstr(dinfo[1]);
  64. BoardInfo[idx][bCY] = floatstr(dinfo[2]);
  65. BoardInfo[idx][bCZ] = floatstr(dinfo[3]);
  66. BoardInfo[idx][bCRX] = floatstr(dinfo[4]);
  67. BoardInfo[idx][bCRY] = floatstr(dinfo[5]);
  68. BoardInfo[idx][bCRZ] = floatstr(dinfo[6]);
  69. format(BoardInfo[idx][bTextM],32,"%s",dinfo[7]);
  70. BoardInfo[idx][bFontSiz] = strval(dinfo[8]);
  71. if(BoardInfo[idx][bModel]) // If board exists
  72. {
  73. format(string, sizeof(string), "{60D754}(%d)", idx);
  74. BoardInfo[idx][bBoard] = CreateDynamicObject(BoardInfo[idx][bModel], BoardInfo[idx][bCX], BoardInfo[idx][bCY], BoardInfo[idx][bCZ], BoardInfo[idx][bCRX], BoardInfo[idx][bCRY], BoardInfo[idx][bCRZ]);
  75. BoardInfo[idx][bText] = CreateDynamic3DTextLabel(string, COLOR_ALIREZA, BoardInfo[idx][bCX], BoardInfo[idx][bCY], BoardInfo[idx][bCZ], 10);
  76. SetDynamicObjectMaterialText(BoardInfo[idx][bBoard],0,BoardInfo[idx][bTextM],OBJECT_MATERIAL_SIZE_256x128,"a51_glass",BoardInfo[idx][bFontSiz],1,0x000000FF,0xFFFFFFFF,OBJECT_MATERIAL_TEXT_ALIGN_CENTER);
  77. BoardInfo[idx][bStatus] = 1; // 0
  78. }
  79. idx++;
  80. }
  81. }
  82. print("ADBoard loaded successfully.");
  83. return 1;
  84. }
  85.  
  86. stock SaveBoards()
  87. {
  88. new idx = 1, File:file;
  89. new string[256];
  90. if(!fexist("boards.cfg")) fcreate("boards.cfg");
  91. while(idx < MAX_BOARDS)
  92. {
  93. format(string, sizeof(string), "%d|%f|%f|%f|%f|%f|%f|%s|%d\r\n",
  94. BoardInfo[idx][bModel],
  95. BoardInfo[idx][bCX],
  96. BoardInfo[idx][bCY],
  97. BoardInfo[idx][bCZ],
  98. BoardInfo[idx][bCRX],
  99. BoardInfo[idx][bCRY],
  100. BoardInfo[idx][bCRZ],
  101. BoardInfo[idx][bTextM],
  102. BoardInfo[idx][bFontSiz]);
  103. BoardInfo[idx][bStatus] = 1; // 0
  104. if(idx == 1)
  105. {
  106. file = fopen("boards.cfg", io_write);
  107. }
  108. else
  109. {
  110. file = fopen("boards.cfg", io_append);
  111. }
  112. fwrite(file, string);
  113. fclose(file);
  114. idx++;
  115. }
  116. print("ADBoard saved successfully.");
  117. return 1;
  118. }
  119.  
  120. public OnFilterScriptExit()
  121. {
  122. return 1;
  123. }
  124.  
  125. CMD:editbfontsize(playerid, params[])
  126. {
  127. new sizz,idx,string[128];
  128.  
  129. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You Are Not Admin.");
  130. if(sscanf(params, "ii", idx, sizz)) return SendClientMessage(playerid, COLOR_ALIREZA, "USAGE: /editbfontsize [boardid] [size]");
  131. if(!BoardInfo[idx][bModel]) return SendClientMessage(playerid, COLOR_GREY, "Invalid board id.");
  132. BoardInfo[idx][bFontSiz] = sizz;
  133. SetDynamicObjectMaterialText(BoardInfo[idx][bBoard],0,BoardInfo[idx][bTextM],OBJECT_MATERIAL_SIZE_256x128,"a51_glass",BoardInfo[idx][bFontSiz],1,0x000000FF,0xFFFFFFFF,OBJECT_MATERIAL_TEXT_ALIGN_CENTER);
  134. format(string,128,"You set board id %d FontSize To %d",idx,sizz);
  135. SendClientMessage(playerid,COLOR_ALIREZA,string);
  136. SaveBoards();
  137. return 1;
  138. }
  139. CMD:editbtext(playerid, params[])
  140. {
  141. new idx,string[128],text[128];
  142. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You Are Not Admin.");
  143. if(!sscanf(params, "is[128]", idx, text)) return SendClientMessage(playerid, COLOR_ALIREZA, "USAGE: /editbtext [boardid] [text]");
  144. if(!BoardInfo[idx][bModel]) return SendClientMessage(playerid, COLOR_GREY, "Invalid board id.");
  145. format(BoardInfo[idx][bTextM],sizeof(text),"{2641FE}%s",text);
  146. SetDynamicObjectMaterialText(BoardInfo[idx][bBoard],0,BoardInfo[idx][bTextM],OBJECT_MATERIAL_SIZE_256x128,"a51_glass",BoardInfo[idx][bFontSiz],1,0x000000FF,0xFFFFFFFF,OBJECT_MATERIAL_TEXT_ALIGN_CENTER);
  147. format(string,256,"You set board id %d text To: %s",idx,BoardInfo[idx][bTextM]);
  148. SendClientMessage(playerid,COLOR_ALIREZA,string);
  149. SaveBoards();
  150. return 1;
  151. }
  152. CMD:editbpos(playerid, params[])
  153. {
  154. new idx,string[128];
  155. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You Are Not Admin.");
  156. if(sscanf(params, "i", idx)) return SendClientMessage(playerid, COLOR_ALIREZA, "USAGE: /editbpos [boardid]");
  157. if(!BoardInfo[idx][bModel]) return SendClientMessage(playerid, COLOR_GREY, "Invalid board id.");
  158. bEdit[playerid] = 1;
  159. bEditID[playerid] = idx;
  160. GetDynamicObjectPos(BoardInfo[idx][bBoard], bPos[playerid][0], bPos[playerid][1], bPos[playerid][2]);
  161. GetDynamicObjectRot(BoardInfo[idx][bBoard], bRot[playerid][0], bRot[playerid][1], bRot[playerid][2]);
  162. EditDynamicObject(playerid, BoardInfo[idx][bBoard]);
  163. format(string, sizeof(string), " You are now editing board ID %d's position.", idx);
  164. SendClientMessage(playerid, COLOR_ALIREZA, string);
  165. return 1;
  166. }
  167.  
  168.  
  169. CMD:gotoboard(playerid, params[])
  170. {
  171. new idx, string[128];
  172. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You Are Not Admin.");
  173. if(sscanf(params, "i", idx)) return SendClientMessage(playerid, COLOR_ALIREZA, "USAGE: /gotoboard [boardid]");
  174. if(!BoardInfo[idx][bModel]) return SendClientMessage(playerid, COLOR_GREY, "Invalid board id.");
  175. SetPlayerPos(playerid, BoardInfo[idx][bCX], BoardInfo[idx][bCY], BoardInfo[idx][bCZ]);
  176. format(string, sizeof(string), " You have teleported to board ID %d.", idx);
  177. SendClientMessage(playerid, COLOR_ALIREZA, string);
  178. return 1;
  179. }
  180. CMD:deleteboard(playerid, params[])
  181. {
  182. new idx, string[128];
  183. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You Are Not Admin.");
  184. if(sscanf(params, "i", idx)) return SendClientMessage(playerid, COLOR_ALIREZA, "USAGE: /deleteboard [boardid]");
  185. if(!BoardInfo[idx][bModel]) return SendClientMessage(playerid, COLOR_GREY, "Invalid board id.");
  186. BoardInfo[idx][bModel] = 0;
  187. BoardInfo[idx][bCX] = 0;
  188. BoardInfo[idx][bCY] = 0;
  189. BoardInfo[idx][bCZ] = 0;
  190. BoardInfo[idx][bCRX] = 0;
  191. BoardInfo[idx][bCRY] = 0;
  192. BoardInfo[idx][bCRZ] = 0;
  193. BoardInfo[idx][bStatus] = 0;
  194. DestroyDynamicObject(BoardInfo[idx][bBoard]);
  195. DestroyDynamic3DTextLabel(BoardInfo[idx][bText]);
  196. format(string, sizeof(string), " deleted board ID %d.", idx);
  197. SendClientMessage(playerid,COLOR_ALIREZA, string);
  198. SaveBoards();
  199. return 1;
  200. }
  201. CMD:createboard(playerid, params[])
  202. {
  203. new string[128];
  204. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You Are Not Admin.");
  205. for(new idx=1; idx<MAX_BOARDS; idx++)
  206. {
  207. if(!BoardInfo[idx][bModel])
  208. {
  209. GetPlayerPos(playerid, BoardInfo[idx][bCX], BoardInfo[idx][bCY], BoardInfo[idx][bCZ]);
  210. BoardInfo[idx][bModel] = 5846;
  211. BoardInfo[idx][bCX] = BoardInfo[idx][bCX] + 2;
  212. BoardInfo[idx][bCY] = BoardInfo[idx][bCY] + 2;
  213. BoardInfo[idx][bCRX] = 0;
  214. BoardInfo[idx][bCRY] = 0;
  215. BoardInfo[idx][bCRZ] = 0;
  216. BoardInfo[idx][bStatus] = 0;
  217. BoardInfo[idx][bFontSiz] = 0;
  218. format(BoardInfo[idx][bTextM],32,"");
  219. // Creating
  220. format(string, sizeof(string), "{60D754}(%d)", idx);
  221. BoardInfo[idx][bBoard] = CreateDynamicObject(BoardInfo[idx][bModel], BoardInfo[idx][bCX], BoardInfo[idx][bCY], BoardInfo[idx][bCZ], BoardInfo[idx][bCRX], BoardInfo[idx][bCRY], BoardInfo[idx][bCRZ]);
  222. BoardInfo[idx][bText] = CreateDynamic3DTextLabel(string, COLOR_ALIREZA, BoardInfo[idx][bCX], BoardInfo[idx][bCY], BoardInfo[idx][bCZ], 10);
  223. // Text
  224. SetDynamicObjectMaterialText(BoardInfo[idx][bBoard],0,BoardInfo[idx][bTextM],OBJECT_MATERIAL_SIZE_256x128,"a51_glass",BoardInfo[idx][bFontSiz],1,0x000000FF,0xFFFFFFFF,OBJECT_MATERIAL_TEXT_ALIGN_CENTER);
  225. format(string, sizeof(string), " created board ID %d. (Object: 5846)", idx);
  226. SendClientMessage(playerid,COLOR_ALIREZA, string);
  227. idx = MAX_BOARDS;
  228. SaveBoards();
  229. }
  230. }
  231. return 1;
  232. }
  233.  
  234.  
  235.  
  236. public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
  237. {
  238. new string[128], idx = bEditID[playerid];
  239. if(response == EDIT_RESPONSE_UPDATE)
  240. {
  241. SetDynamicObjectPos(objectid, x, y, z);
  242. SetDynamicObjectRot(objectid, rx, ry, rz);
  243. }
  244. else if(response == EDIT_RESPONSE_CANCEL)
  245. {
  246. SetDynamicObjectPos(objectid, bPos[playerid][0], bPos[playerid][1], bPos[playerid][2]);
  247. SetDynamicObjectRot(objectid, bRot[playerid][0], bRot[playerid][1],bRot[playerid][2]);
  248. bPos[playerid][0] = 0; bPos[playerid][1] = 0; bPos[playerid][2] = 0;
  249. bRot[playerid][0] = 0; bRot[playerid][1] = 0; bRot[playerid][2] = 0;
  250. format(string, sizeof(string), " You have canceled editing board ID %d.", idx);
  251. SendClientMessage(playerid, COLOR_ALIREZA, string);
  252. }
  253. else if(response == EDIT_RESPONSE_FINAL)
  254. {
  255. SetDynamicObjectPos(objectid, x, y, z);
  256. SetDynamicObjectRot(objectid, rx, ry, rz);
  257. if(bEdit[playerid] == 1)
  258. {
  259. BoardInfo[idx][bCX] = x;
  260. BoardInfo[idx][bCY] = y;
  261. BoardInfo[idx][bCZ] = z;
  262. BoardInfo[idx][bCRX] = rx;
  263. BoardInfo[idx][bCRY] = ry;
  264. BoardInfo[idx][bCRZ] = rz;
  265. if(IsValidDynamic3DTextLabel(BoardInfo[idx][bText])) DestroyDynamic3DTextLabel(BoardInfo[idx][bText]);
  266. format(string, sizeof(string), "{60D754}(%d)", idx);
  267. BoardInfo[idx][bText] = CreateDynamic3DTextLabel(string, COLOR_ALIREZA, BoardInfo[idx][bCX], BoardInfo[idx][bCY], BoardInfo[idx][bCZ], 10);
  268. bEdit[playerid] = 0;
  269. bEditID[playerid] = 0;
  270. format(string, sizeof(string), " You have finished editing board ID %d's position.", idx);
  271. SendClientMessage(playerid, COLOR_ALIREZA, string);
  272. BoardInfo[idx][bStatus] = 0;
  273. SaveBoards();
  274. }
  275. }
  276. return 1;
  277. }
  278.  
  279.  
  280. //------------------------------------------------------------------------------
  281. stock fcreate(filename[])
  282. {
  283. if (fexist(filename)) return false;
  284. new File:fhnd;
  285. fhnd=fopen(filename,io_write);
  286. if (fhnd) {
  287. fclose(fhnd);
  288. return true;
  289. }
  290. return false;
  291. }
  292. //------------------------------------------------------------------------------
  293. stock split(const strsrc[], strdest[][], delimiter)
  294. {
  295. new i, li;
  296. new aNum;
  297. new len;
  298. while(i <= strlen(strsrc))
  299. {
  300. if(strsrc[i] == delimiter || i == strlen(strsrc))
  301. {
  302. len = strmid(strdest[aNum], strsrc, li, i, 128);
  303. strdest[aNum][len] = 0;
  304. li = i+1;
  305. aNum++;
  306. }
  307. i++;
  308. }
  309. return 1;
  310. }
RAW Paste Data