Guest User

Untitled

a guest
Mar 8th, 2018
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.68 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <streamer>
  4.  
  5. //Graffiti system by Arthur Kane
  6. //October 25, 2017
  7.  
  8. #define PRESSED(%0) \
  9. (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  10.  
  11. #define RELEASED(%0) \
  12. (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
  13.  
  14. #define DIALOG_GRAFFITI_MENU (888)
  15.  
  16. enum E_GRAFFITI_INFO
  17. {
  18. Float: graffitiPos_X,
  19. Float: graffitiPos_Y,
  20. Float: graffitiPos_Z,
  21.  
  22. Float: graffitiRot_X,
  23. Float: graffitiRot_Y,
  24. Float: graffitiRot_Z
  25. }
  26.  
  27. new g_aGraffitiInfo[][E_GRAFFITI_INFO] =
  28. {
  29. {2081.867675, -1255.466430, 24.712007, -12.800003, 0.000000, 0.000000},
  30. {2268.340332, -1031.824707, 53.437198, 0.000000, 0.000000, 135.800155}
  31. };
  32.  
  33. new g_GraffitiObject[sizeof g_aGraffitiInfo];
  34.  
  35. public OnFilterScriptInit()
  36. {
  37. for(new i; i < sizeof g_aGraffitiInfo; i++)
  38. {
  39. g_GraffitiObject[i] = CreateDynamicObject(18666, g_aGraffitiInfo[i][graffitiPos_X], g_aGraffitiInfo[i][graffitiPos_Y], g_aGraffitiInfo[i][graffitiPos_Z], g_aGraffitiInfo[i][graffitiRot_X], g_aGraffitiInfo[i][graffitiRot_Y], g_aGraffitiInfo[i][graffitiRot_Z], -1, 0, -1, 6000.0);
  40. }
  41.  
  42. print("Graffiti system is live.");
  43. return 1;
  44. }
  45.  
  46. new playerGraffitiTimer[ MAX_PLAYERS ];
  47.  
  48. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  49. {
  50. if(PRESSED( KEY_FIRE ) && GetPlayerWeapon(playerid) == WEAPON_SPRAYCAN && GetPVarInt(playerid, "SprayingGraffiti") == 0)
  51. {
  52. new
  53. bool: nearGraffiti;
  54.  
  55. for(new i; i < sizeof g_aGraffitiInfo; i++)
  56. {
  57. if(IsPlayerInRangeOfPoint(playerid, 2.0, g_aGraffitiInfo[i][graffitiPos_X], g_aGraffitiInfo[i][graffitiPos_Y], g_aGraffitiInfo[i][graffitiPos_Z]))
  58. {
  59. nearGraffiti = true;
  60.  
  61. SetPVarInt( playerid, "SprayingGraffiti", 1 );
  62. SetPVarInt( playerid, "NearGraffitiID", i );
  63. }
  64. }
  65. if(nearGraffiti)
  66. playerGraffitiTimer [ playerid ] = SetTimerEx("OnPlayerSpraying", 1000, true, "i", playerid);
  67. }
  68.  
  69. if(RELEASED( KEY_FIRE ) && GetPlayerWeapon(playerid) == WEAPON_SPRAYCAN && GetPVarInt(playerid, "SprayingGraffiti") == 1)
  70. {
  71. KillTimer( playerGraffitiTimer[playerid] );
  72.  
  73. DeletePVar( playerid, "SprayingGraffiti" );
  74. DeletePVar( playerid, "NearGraffitiID" );
  75.  
  76. GameTextForPlayer(playerid, "~w~] ~n~~r~Stopped", 3000, 5);
  77. }
  78. return 1;
  79. }
  80.  
  81. //Default Commands:
  82. CMD:graffiti(playerid, params[])
  83. {
  84. ShowPlayerDialog(playerid, DIALOG_GRAFFITI_MENU, DIALOG_STYLE_INPUT, "Graffiti Menu:", "These graffitis support color codes. Use:\nNew line (n), Black (b), Brown(br) Red (r), Blue (bl), Green (g), Orange (o), White (w), Yellow (y), Maroon (mr) before your text.\n\nEnter your graffitis text:", "Select", "Cancel");
  85. return 1;
  86. }
  87.  
  88. CMD:getcan(playerid, params[])
  89. {
  90. GivePlayerWeapon( playerid, WEAPON_SPRAYCAN, 99999 );
  91. return 1;
  92. }
  93.  
  94. //Admin Commands:
  95. new playerGraffitiObject[ MAX_PLAYERS ];
  96.  
  97. CMD:makegraffiti(playerid, params[])
  98. {
  99. if(GetPVarInt(playerid, "MakingGraffiti") > 0)
  100. return SendClientMessage(playerid, -1, "You already have a graffiti object spawned.");
  101.  
  102. new
  103. Float: myPos[3];
  104.  
  105. GetPlayerPos(playerid, myPos[0], myPos[1], myPos[2]);
  106.  
  107. SetPVarInt(playerid, "MakingGraffiti", 1);
  108.  
  109. playerGraffitiObject[playerid] = CreateDynamicObject(18666, myPos[0], myPos[1], myPos[2], 0.0, 0.0, 0.0);
  110. EditDynamicObject(playerid, playerGraffitiObject[playerid]);
  111.  
  112. SendClientMessage(playerid, -1, "Instructions:");
  113. SendClientMessage(playerid, -1, "Set your graffiti at a wall and adjust the rotations properly so you see the front.");
  114. SendClientMessage(playerid, -1, "Once you're done, press Save on the GUI and the coordinates will be printed in server_log.txt.");
  115. return 1;
  116. }
  117. //
  118.  
  119. public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
  120. {
  121. if(GetPVarInt(playerid, "MakingGraffiti") == 1)
  122. {
  123. if(response == EDIT_RESPONSE_CANCEL)
  124. {
  125. DestroyDynamicObject(playerGraffitiObject[playerid]);
  126. DeletePVar(playerid, "MakingGraffiti");
  127.  
  128. SendClientMessage(playerid, -1, "You cancelled your graffiti.");
  129. }
  130. else if(response == EDIT_RESPONSE_FINAL)
  131. {
  132. DestroyDynamicObject(playerGraffitiObject[playerid]);
  133. DeletePVar(playerid, "MakingGraffiti");
  134.  
  135. SendClientMessage(playerid, -1, "Your graffitis coordinates have been printed in the server_log.");
  136. printf("{%f, %f, %f, %f, %f, %f}", x, y, z, rx, ry, rz);
  137. }
  138. }
  139. return 1;
  140. }
  141.  
  142. //
  143.  
  144. forward OnPlayerSpraying(playerid);
  145. public OnPlayerSpraying(playerid)
  146. {
  147. new sprayCounter, sprayingGraffiti;
  148. new counter[60], graffitiText[65];
  149.  
  150. sprayCounter = GetPVarInt( playerid, "GraffitiLength" );
  151. sprayingGraffiti = GetPVarInt( playerid, "NearGraffitiID" );
  152.  
  153. GetPVarString(playerid, "GraffitiText", graffitiText, sizeof graffitiText);
  154.  
  155. if(IsPlayerInRangeOfPoint(playerid, 2.0, g_aGraffitiInfo[sprayingGraffiti][graffitiPos_X], g_aGraffitiInfo[sprayingGraffiti][graffitiPos_Y], g_aGraffitiInfo[sprayingGraffiti][graffitiPos_Z]))
  156. {
  157. sprayCounter--;
  158. SetPVarInt(playerid, "GraffitiLength", sprayCounter);
  159.  
  160. format(counter, sizeof counter, "~r~Spraying~n~~w~%d]", sprayCounter);
  161. GameTextForPlayer(playerid, counter, 3000, 3);
  162.  
  163. if(sprayCounter <= 0)
  164. {
  165. strreplace(graffitiText, "(n)", "\n");
  166. strreplace(graffitiText, "(o)", "{FF8B00}");
  167. strreplace(graffitiText, "(br)", "{5B3F01}");
  168. strreplace(graffitiText, "(bl)", "{0000FF}");
  169. strreplace(graffitiText, "(b)", "{000000}");
  170. strreplace(graffitiText, "(g)", "{008000}");
  171. strreplace(graffitiText, "(w)", "{FFFFFF}");
  172. strreplace(graffitiText, "(y)", "{FFFF00}");
  173. strreplace(graffitiText, "(r)", "{FF0000}");
  174. strreplace(graffitiText, "(mr)", "{800000}");
  175.  
  176. SetDynamicObjectMaterialText(g_GraffitiObject[sprayingGraffiti], 0, graffitiText, OBJECT_MATERIAL_SIZE_256x256, "Arial", 27, 1, 0xFFFFFFFF, 0, 1);
  177. GameTextForPlayer(playerid, "~g~Sprayed~n~ ~w~]", 2000, 3);
  178.  
  179. SetPVarInt(playerid, "GraffitiLength", GetPVarInt(playerid, "GraffitiLengthSave"));
  180.  
  181. DeletePVar(playerid, "NearGraffitiID");
  182. DeletePVar(playerid, "SprayingGraffiti");
  183.  
  184. KillTimer(playerGraffitiTimer[playerid]);
  185. }
  186. }
  187. else
  188. {
  189. SetPVarInt(playerid, "GraffitiLength", GetPVarInt(playerid, "GraffitiLengthSave"));
  190.  
  191. DeletePVar(playerid, "NearGraffitiID");
  192. DeletePVar(playerid, "SprayingGraffiti");
  193.  
  194. KillTimer(playerGraffitiTimer[playerid]);
  195. }
  196. return 1;
  197. }
  198.  
  199. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  200. {
  201. if( dialogid == DIALOG_GRAFFITI_MENU )
  202. {
  203. if(response)
  204. {
  205. if(strlen(inputtext) > 60 || strlen(inputtext) < 2)
  206. return cmd_graffiti(playerid, "");
  207.  
  208. SetPVarInt(playerid, "GraffitiLength", strlen(inputtext));
  209. SetPVarInt(playerid, "GraffitiLengthSave", strlen(inputtext));
  210.  
  211. SetPVarString(playerid, "GraffitiText", inputtext);
  212.  
  213. new
  214. text[63];
  215.  
  216. SendClientMessage(playerid, 0xFF6347FF, "You set your graffiti text. You can now spray at a graffiti.");
  217.  
  218. format(text, sizeof text, "%s", inputtext);
  219. SendClientMessage(playerid, -1, text);
  220. }
  221. else SendClientMessage(playerid, -1, "Cancelled!");
  222. return 1;
  223. }
  224. return 0;
  225. }
  226.  
  227. stock strreplace(string[], const search[], const replacement[], bool:ignorecase = false, pos = 0, limit = -1, maxlength = sizeof(string)) {
  228. // No need to do anything if the limit is 0.
  229. if (limit == 0)
  230. return 0;
  231.  
  232. new
  233. sublen = strlen(search),
  234. replen = strlen(replacement),
  235. bool:packed = ispacked(string),
  236. maxlen = maxlength,
  237. len = strlen(string),
  238. count = 0
  239. ;
  240.  
  241.  
  242. // "maxlen" holds the max string length (not to be confused with "maxlength", which holds the max. array size).
  243. // Since packed strings hold 4 characters per array slot, we multiply "maxlen" by 4.
  244. if (packed)
  245. maxlen *= 4;
  246.  
  247. // If the length of the substring is 0, we have nothing to look for..
  248. if (!sublen)
  249. return 0;
  250.  
  251. // In this line we both assign the return value from "strfind" to "pos" then check if it's -1.
  252. while (-1 != (pos = strfind(string, search, ignorecase, pos))) {
  253. // Delete the string we found
  254. strdel(string, pos, pos + sublen);
  255.  
  256. len -= sublen;
  257.  
  258. // If there's anything to put as replacement, insert it. Make sure there's enough room first.
  259. if (replen && len + replen < maxlen) {
  260. strins(string, replacement, pos, maxlength);
  261.  
  262. pos += replen;
  263. len += replen;
  264. }
  265.  
  266. // Is there a limit of number of replacements, if so, did we break it?
  267. if (limit != -1 && ++count >= limit)
  268. break;
  269. }
  270.  
  271. return count;
  272. }
Advertisement
Add Comment
Please, Sign In to add comment