Guest User

Dynamic Food stall creator with food items and textdraw menu

a guest
Mar 28th, 2013
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.58 KB | None | 0 0
  1. /*
  2. VERSION 2
  3. Please try keeping them credits cuz it's took me quite a lot of time for this.
  4. */
  5. #define FILTERSCRIPT
  6. #define COLOR_GREEN 0x33AA33AA
  7. #define COLOR_RED 0xAA3333AA
  8. #include <a_samp>
  9. #include <sscanf2>
  10. #include <zcmd>
  11. #include <rInfoBox>
  12. #include <mapandreas>
  13. #include <streamer>
  14. #define MAX_STANDS 50
  15. enum hInfo
  16. {
  17. CP,
  18. baseprice,
  19. menuid,
  20. name[40],
  21. bool:exists,
  22. objectid,
  23. owner[24],
  24. price,
  25. Text3D:namelabel,
  26. Text3D:pricelabel,
  27. bool:owned,
  28. offeredcash,
  29. offerer[24]
  30. }
  31. new HotInfo[MAX_STANDS][hInfo];
  32. public OnFilterScriptInit()
  33. {
  34. print("\n--------------------------------------");
  35. print(" Dynamic hot dog stand creator ! ");
  36. print(" Author: Rajat _ Pawar ");
  37. print(" Version: 2 ");
  38. print(" Hunger: 100% ");
  39. print(" Thanks, cheers ");
  40. print("--------------------------------------\n");
  41. MapAndreas_Init(1);
  42. for( new i; i < MAX_STANDS; i++)
  43. {
  44. HotInfo[i][exists] = false;
  45. HotInfo[i][owned] = false;
  46. HotInfo[i][offeredcash] = 0;
  47. }
  48. return 1;
  49. }
  50.  
  51.  
  52. public OnFilterScriptExit()
  53. {
  54. return 1;
  55. }
  56.  
  57. CMD:createfoodstall(playerid, params[])
  58. {
  59. new costbase, st[20];
  60. if(GetPlayerState(playerid) == 0) return SendClientMessage(playerid, COLOR_RED, "You need to be spawned.");
  61. if(sscanf(params, "s[20]d", st, costbase)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /createfoodstall (name of stall) (baseprice)");
  62. else
  63. {
  64. for( new i; i < MAX_STANDS; i++)
  65. {
  66. if( HotInfo[i][exists] == false)
  67. {
  68. new Float:x, Float:y, Float:z, Float:tz, Float:angle;
  69. GivePlayerMoney(playerid, -costbase);
  70. GetPlayerPos(playerid, x, y, z );
  71. MapAndreas_FindZ_For2DCoord(x, y, tz);
  72. GetPlayerFacingAngle(playerid, angle);
  73. HotInfo[i][objectid] = CreateObject(1340, x + (2.0 * floatsin(-angle - 28, degrees)), y + (2.0 * floatcos(-angle - 20, degrees)), tz + 1.3, 0, 0, angle, 100);
  74. HotInfo[i][CP] = CreateDynamicCP(x + 2*floatcos(90+angle, degrees), y+ 2*floatsin(90-angle, degrees), tz, 1.3, 0, 0, 0, 100);
  75. SendClientMessage(playerid, COLOR_GREEN, "You have created a hotdog stand! Enjoy !");
  76. printf("%d", HotInfo[i][CP]);
  77. HotInfo[i][exists] = true;
  78. HotInfo[i][baseprice] = costbase;
  79. format(HotInfo[i][name], 40, "%s", st);
  80. HotInfo[i][namelabel] = Create3DTextLabel(st, 0xF5BC11FF, x + 2*floatcos(90+angle, degrees), y+ 2*floatsin(90-angle, degrees), tz + 0.8, 10, GetPlayerVirtualWorld(playerid), 0);
  81. HotInfo[i][pricelabel] = Create3DTextLabel("Price: $50,000.", COLOR_GREEN, x + 2*floatcos(90+angle, degrees), y+ 2*floatsin(90-angle, degrees), tz + 0.6, 10, GetPlayerVirtualWorld(playerid), 0);
  82. new string[220], nstring[50];
  83. format(string, 450, "~w~1. ~y~Buy a ~r~hotdog. ~g~($%d)~n~~w~2.~y~ Buy a ~r~pork sandwich. ~g~($%d)~n~~w~3.~y~ Buy a ~r~pizza. ~g~($%d)~n~~w~4.~y~ Buy a ~r~nachos packet. ~g~($%d)", HotInfo[i][baseprice], HotInfo[i][baseprice] + 10, HotInfo[i][baseprice] + 36, HotInfo[i][baseprice] + 19);
  84. format(nstring, 50, "~n~~w~5.~y~ Buy a~r~ taco. ~g~($%d)", HotInfo[i][baseprice] + 11);
  85. strcat(string, nstring);
  86. HotInfo[i][menuid] = CreateTDboxForPlayer(playerid, HotInfo[i][name], COLOR_GREEN, string);
  87. break;
  88. }
  89. else continue;
  90. }
  91. }
  92. return 1;
  93. }
  94.  
  95. CMD:cfs(playerid, params[])
  96. {
  97. return cmd_createfoodstall(playerid, params);
  98. }
  99.  
  100.  
  101.  
  102. public OnPlayerEnterDynamicCP(playerid, checkpointid)
  103. {
  104. for( new i = 0; i < MAX_STANDS; i++)
  105. {
  106. if(HotInfo[i][exists] != false)
  107. {
  108. if(checkpointid == HotInfo[i][CP])
  109. {
  110. ShowTDboxToPlayer(playerid, HotInfo[i][menuid]);
  111. if(HotInfo[i][owned] == false) SendClientMessage(playerid, COLOR_GREEN, "This stall is for sale. Use /buystall to buy it!");
  112. else { new string[90]; format(string, 90, "This stall is owned by {00FF00}%s. Use /offer to offer a price for it.", HotInfo[i][owner]); SendClientMessage(playerid, COLOR_GREEN, string); }
  113. new names[MAX_PLAYER_NAME], string[128];
  114. GetPlayerName(playerid, names, 24);
  115. if(strcmp(names, HotInfo[i][owner], true) == 0)
  116. {
  117. if( HotInfo[i][offeredcash] > 0)
  118. {
  119. format(string, 128, "You have been offered~g~ $%d ~n~for ~w~this stall by %s.", HotInfo[i][offeredcash], HotInfo[i][offerer]);
  120. GameTextForPlayer(playerid, string, 10000, 5);
  121. return SendClientMessage(playerid, COLOR_GREEN, "Use /reply (YES/NO) to reply to the offer.");
  122.  
  123. }
  124. SendClientMessage(playerid, COLOR_GREEN, "Welcome back to your stall. Use /changeprice to change the price of your stall.");
  125. SendClientMessage(playerid, COLOR_GREEN, "Also, you can use /changename to change the name of your stall.");
  126. }
  127. break;
  128.  
  129.  
  130. }
  131. }
  132. else continue;
  133. }
  134. return 1;
  135. }
  136. CMD:changeprice(playerid, params[])
  137. {
  138. new pricef;
  139. if(sscanf(params, "d", pricef)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /changeprice (new price)");
  140. {
  141. for( new i = 0; i < MAX_STANDS; i++)
  142. {
  143. if(HotInfo[i][exists] != false)
  144. {
  145. if(HotInfo[i][owned] != false)
  146. {
  147. if(IsPlayerInDynamicCP(playerid, HotInfo[i][CP]))
  148. {
  149. new names[MAX_PLAYER_NAME];
  150. GetPlayerName(playerid, names, 24);
  151. if(strcmp(names, HotInfo[i][owner], true) == 0)
  152. {
  153. SendClientMessage(playerid, COLOR_GREEN, "You have successfully changed the food items' price of your stall.");
  154. HotInfo[i][baseprice] = pricef;
  155. HideTDboxForPlayer(playerid, HotInfo[i][menuid]);
  156. new string[220], nstring[50];
  157. format(string, 450, "~w~1. ~y~Buy a ~r~hotdog. ~g~($%d)~n~~w~2.~y~ Buy a ~r~pork sandwich. ~g~($%d)~n~~w~3.~y~ Buy a ~r~pizza. ~g~($%d)~n~~w~4.~y~ Buy a ~r~nachos packet. ~g~($%d)", HotInfo[i][baseprice], HotInfo[i][baseprice] + 10, HotInfo[i][baseprice] + 36, HotInfo[i][baseprice] + 19);
  158. format(nstring, 50, "~n~~w~5.~y~ Buy a~r~ taco. ~g~($%d)", HotInfo[i][baseprice] + 11);
  159. strcat(string, nstring);
  160. HotInfo[i][menuid] = 0;
  161. HotInfo[i][menuid] = CreateTDboxForPlayer(playerid, HotInfo[i][name], COLOR_GREEN, string);
  162. break;
  163. }
  164. }
  165. }
  166. }
  167. }
  168. }
  169. return 1;
  170. }
  171. CMD:changename(playerid, params[])
  172. {
  173. new namez[40];
  174. if(sscanf(params, "s[40]", namez)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /changename (new name of stall)");
  175. {
  176. for( new i = 0; i < MAX_STANDS; i++)
  177. {
  178. if(HotInfo[i][exists] != false)
  179. {
  180. if(HotInfo[i][owned] != false)
  181. {
  182. if(IsPlayerInDynamicCP(playerid, HotInfo[i][CP]))
  183. {
  184. new names[MAX_PLAYER_NAME];
  185. GetPlayerName(playerid, names, 24);
  186. if(strcmp(names, HotInfo[i][owner], true) == 0)
  187. {
  188. SendClientMessage(playerid, COLOR_GREEN, "You have successfully changed the name of your stall.");
  189. HideTDboxForPlayer(playerid, HotInfo[i][menuid]);
  190. format(HotInfo[i][name], 40, "%s", namez);
  191. new string[220], nstring[50];
  192. format(string, 450, "~w~1. ~y~Buy a ~r~hotdog. ~g~($%d)~n~~w~2.~y~ Buy a ~r~pork sandwich. ~g~($%d)~n~~w~3.~y~ Buy a ~r~pizza. ~g~($%d)~n~~w~4.~y~ Buy a ~r~nachos packet. ~g~($%d)", HotInfo[i][baseprice], HotInfo[i][baseprice] + 10, HotInfo[i][baseprice] + 36, HotInfo[i][baseprice] + 19);
  193. format(nstring, 50, "~n~~w~5.~y~ Buy a~r~ taco. ~g~($%d)", HotInfo[i][baseprice] + 11);
  194. strcat(string, nstring);
  195. HotInfo[i][menuid] = 0;
  196. HotInfo[i][menuid] = CreateTDboxForPlayer(playerid, HotInfo[i][name], COLOR_GREEN, string);
  197. Update3DTextLabelText(HotInfo[i][namelabel], COLOR_GREEN, HotInfo[i][name]);
  198. return 1;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. }
  205. return 1;
  206. }
  207.  
  208.  
  209.  
  210.  
  211.  
  212. CMD:reply(playerid, params[])
  213. {
  214. new names[MAX_PLAYER_NAME], string[6];
  215. GetPlayerName(playerid, names, 24);
  216. if(sscanf(params, "s[6]", string)) return SendClientMessage(playerid, COLOR_GREEN, "USAGE: /reply (YES/NO)");
  217. for( new i = 0; i < MAX_STANDS; i++)
  218. {
  219. if(HotInfo[i][exists] != false)
  220. {
  221. if(strcmp(names, HotInfo[i][owner], true) == 0)
  222. {
  223. if(HotInfo[i][offeredcash] > HotInfo[i][price])
  224. {
  225. if(strcmp(string, "yes", true) != -1)
  226. {
  227. format(HotInfo[i][owner], 24, "%s", HotInfo[i][offerer]);
  228. HotInfo[i][price] += HotInfo[i][offeredcash];
  229. new st[80]; format(st, 80, "Owner: %s", names);
  230. Update3DTextLabelText(HotInfo[i][pricelabel], COLOR_RED, st);
  231. Update3DTextLabelText(HotInfo[i][namelabel], COLOR_GREEN, HotInfo[i][name]);
  232. format(HotInfo[i][offerer], 24, "%s", " ");
  233. format(st, 80, "You have sold %s your stall for $%d. You are no longer the owner.", names, HotInfo[i][offeredcash]);
  234. HotInfo[i][offeredcash] = 0;
  235. SendClientMessage(playerid, COLOR_GREEN, st);
  236. if(GetPlayerID(HotInfo[i][offerer]) != INVALID_PLAYER_ID)
  237. {
  238. SendClientMessage(GetPlayerID(HotInfo[i][offerer]), COLOR_GREEN, "You have been sold the stall for your offered cash. Good luck.");
  239. GivePlayerMoney(GetPlayerID(HotInfo[i][offerer]), - HotInfo[i][offeredcash]);
  240. }
  241.  
  242. }
  243. else if(strcmp(string, "no", true) != -1)
  244. {
  245. new st[80];
  246. format(st, 80, "You have rejected %s's offer for your stall of $%d.", names, HotInfo[i][offeredcash]);
  247. SendClientMessage(playerid, COLOR_GREEN, st);
  248. HotInfo[i][offeredcash] = 0;
  249. format(HotInfo[i][offerer], 24, "%s", " ");
  250. if(GetPlayerID(HotInfo[i][offerer]) != INVALID_PLAYER_ID)
  251. {
  252. SendClientMessage(GetPlayerID(HotInfo[i][offerer]), COLOR_GREEN, "Your offer for the stall was rejected. Better luck next time.");
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. return 1;
  260. }
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. public OnPlayerLeaveDynamicCP(playerid, checkpointid)
  271. {
  272. for( new i = 0; i < MAX_STANDS; i++)
  273. {
  274. if(HotInfo[i][exists] != false)
  275. {
  276. if(checkpointid == HotInfo[i][CP])
  277. {
  278. HideTDboxForPlayer(playerid, HotInfo[i][menuid]);
  279. break;
  280. }
  281. else continue;
  282. }
  283. else continue;
  284. }
  285. return 1;
  286. }
  287.  
  288.  
  289. CMD:buystall(playerid)
  290. {
  291. for( new i = 0; i < MAX_STANDS; i++)
  292. {
  293. if(HotInfo[i][exists] == false) continue;
  294. {
  295. if(!IsPlayerInDynamicCP(playerid, HotInfo[i][CP])) continue;
  296. {
  297. if(HotInfo[i][owned] == true) continue;
  298. {
  299. if(GetPlayerMoney(playerid) - 50000 < 0 ) return SendClientMessage(playerid, COLOR_RED, "You cannot buy this stall, you need more money!");
  300. else {
  301. GivePlayerMoney(playerid, -50000);
  302. SendClientMessage(playerid, COLOR_GREEN, "Congratulations, you have bought this stall.");
  303. GameTextForPlayer(playerid, "~g~Congratulations, you have bought ~n~this ~r~stall.", 5000, 5);
  304. new names[MAX_PLAYER_NAME], string[30], s[30];
  305. format(s, 30, "%s", HotInfo[i][name]);
  306. GetPlayerName(playerid, names, 24);
  307. format(HotInfo[i][owner], 24, "%s", names);
  308. format(string, 30, "Owner: %s", names);
  309. HotInfo[i][owned] = true;
  310. HotInfo[i][price] = 50000;
  311. Update3DTextLabelText(HotInfo[i][pricelabel], COLOR_RED, string);
  312. Update3DTextLabelText(HotInfo[i][namelabel], COLOR_GREEN, s);
  313. }
  314. }
  315. }
  316. }
  317. }
  318. return 1;
  319. }
  320.  
  321. CMD:offer(playerid, params[])
  322. {
  323. new offeredcas; new namez[MAX_PLAYER_NAME]; GetPlayerName(playerid, namez, 24);
  324. for( new i = 0; i < MAX_STANDS; i++)
  325. {
  326. if(HotInfo[i][exists] == false) continue;
  327. {
  328. if(strcmp(namez, HotInfo[i][owner], true) == 0) return SendClientMessage(playerid, COLOR_RED, "You already have a stall.");
  329. {
  330. if(!IsPlayerInDynamicCP(playerid, HotInfo[i][CP])) continue;
  331. {
  332. if(HotInfo[i][owned] == false) return SendClientMessage(playerid, COLOR_RED, "This stall is for sale, just use /buystall!");
  333. {
  334. if(GetPlayerMoney(playerid) < HotInfo[i][price]) return SendClientMessage(playerid, COLOR_RED, "Get some cash first. *More than $50, 000 to offer*");
  335. else if(sscanf(params, "d", offeredcas)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /offer (cash) (cash should be greater than original price.");
  336. {
  337. if(offeredcas < HotInfo[i][price]) return SendClientMessage(playerid, COLOR_RED, "More than $50000.");
  338. new names[MAX_PLAYER_NAME], string[110];
  339. GetPlayerName(playerid, names, 24);
  340. format(HotInfo[i][offerer], 24, "%s", names);
  341. HotInfo[i][offeredcash] = offeredcas;
  342. format(string, 110, "You (%s) have offered %s $%d for his stall. Wait to see if he replies.", HotInfo[i][offerer], HotInfo[i][owner], offeredcas);
  343. SendClientMessage(playerid, COLOR_GREEN, string);
  344. return 1;
  345. }
  346. }
  347. }
  348. }
  349. }
  350. }
  351. return 1;
  352. }
  353.  
  354.  
  355.  
  356. public OnPlayerText(playerid, text[])
  357. {
  358. if(text[0] == '1' || text[0] == '2' || text[0] == '3' || text[0] == '4' || text[0] == '5')
  359. {
  360. for( new i = 0; i < MAX_STANDS; i++)
  361. {
  362. if(HotInfo[i][exists] == false) continue;
  363. {
  364. if(!IsPlayerInDynamicCP(playerid, HotInfo[i][CP])) continue;
  365. {
  366. new s = strval(text[0]);
  367. switch(s)
  368. {
  369. case 1:
  370. {
  371. if(GetPlayerMoney(playerid) - HotInfo[i][baseprice] > 0)
  372. {
  373. GivePlayerMoney(playerid, - HotInfo[i][baseprice]); new st[70];
  374. format(st, 70, "You have bought a hot dog for $%d.", HotInfo[i][baseprice]);
  375. SendClientMessage(playerid, COLOR_GREEN, st);
  376. ApplyAnimation(playerid,"FOOD","EAT_Burger", 3, 0, 1, 1, 1, 1, 1);
  377. }
  378. else
  379. {
  380. SendClientMessage(playerid, COLOR_RED, "You don't have enough money to buy a hot dog.");
  381. ApplyAnimation(playerid,"ped","fucku", 3, 0, 1, 1, 1, 1, 1);
  382. return 0;
  383. }
  384. }
  385. case 2:
  386. {
  387. if(GetPlayerMoney(playerid) - (HotInfo[i][baseprice] + 10) > 0)
  388. {
  389. GivePlayerMoney(playerid, - (HotInfo[i][baseprice] + 10)); new st[70];
  390. format(st, 70, "You have bought a pork sandwich for $%d.", HotInfo[i][baseprice] + 10);
  391. SendClientMessage(playerid, COLOR_GREEN, st);
  392. ApplyAnimation(playerid,"FOOD","EAT_Burger", 3, 0, 1, 1, 1, 1, 1);
  393. }
  394. else
  395. {
  396. SendClientMessage(playerid, COLOR_RED, "You don't have enough money to buy a pork sandwich.");
  397. ApplyAnimation(playerid,"ped","fucku", 3, 0, 1, 1, 1, 1, 1);
  398. return 0;
  399. }
  400. }
  401. case 3:
  402. {
  403. if(GetPlayerMoney(playerid) - (HotInfo[i][baseprice] + 36) > 0)
  404. {
  405. GivePlayerMoney(playerid, - (HotInfo[i][baseprice] + 36)); new st[70];
  406. format(st, 70, "You have bought a pizza for $%d.", HotInfo[i][baseprice] + 36);
  407. SendClientMessage(playerid, COLOR_GREEN, st);
  408. ApplyAnimation(playerid,"FOOD","EAT_Burger", 3, 0, 1, 1, 1, 1, 1);
  409. }
  410. else
  411. {
  412. SendClientMessage(playerid, COLOR_RED, "You don't have enough money to buy a pizza.");
  413. ApplyAnimation(playerid,"ped","fucku", 3, 0, 1, 1, 1, 1, 1);
  414. return 0;
  415. }
  416. }
  417. case 4:
  418. {
  419. if(GetPlayerMoney(playerid) - (HotInfo[i][baseprice] + 19) > 0)
  420. {
  421. GivePlayerMoney(playerid, - (HotInfo[i][baseprice] + 19)); new st[70];
  422. format(st, 70, "You have bought a nachos packet for $%d.", HotInfo[i][baseprice] + 19);
  423. SendClientMessage(playerid, COLOR_GREEN, st);
  424. ApplyAnimation(playerid,"FOOD","EAT_Burger", 3, 0, 1, 1, 1, 1, 1);
  425. }
  426. else
  427. {
  428. SendClientMessage(playerid, COLOR_RED, "You don't have enough money to buy a packet of nachos.");
  429. ApplyAnimation(playerid,"ped","fucku", 3, 0, 1, 1, 1, 1, 1);
  430. return 0;
  431. }
  432. }
  433. case 5:
  434. {
  435. if(GetPlayerMoney(playerid) - (HotInfo[i][baseprice] + 11) > 0)
  436. {
  437. GivePlayerMoney(playerid, - (HotInfo[i][baseprice] + 11)); new st[70];
  438. format(st, 70, "You have bought a taco for $%d.", HotInfo[i][baseprice] + 11);
  439. SendClientMessage(playerid, COLOR_GREEN, st);
  440. ApplyAnimation(playerid,"FOOD","EAT_Burger", 3, 0, 1, 1, 1, 1, 1);
  441. }
  442. else
  443. {
  444. SendClientMessage(playerid, COLOR_RED, "You don't have enough money to buy a taco.");
  445. ApplyAnimation(playerid,"ped","fucku", 3, 0, 1, 1, 1, 1, 1);
  446. return 0;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. return 0;
  453. }
  454.  
  455. }
  456. return 1;
  457. }
  458. CMD:money(playerid)
  459. {
  460. GivePlayerMoney(playerid, 125112);
  461. return 1;
  462. }
  463. stock GetPlayerID(playername[])
  464. {
  465. for(new i = 0; i <= MAX_PLAYERS; i++)
  466. {
  467. if(IsPlayerConnected(i))
  468. {
  469. new playername2[MAX_PLAYER_NAME];
  470. GetPlayerName(i, playername2, sizeof(playername2));
  471. if(strcmp(playername2, playername, true, strlen(playername)) == 0)
  472. {
  473. return i;
  474. }
  475. }
  476. }
  477. return INVALID_PLAYER_ID;
  478. }
Advertisement
Add Comment
Please, Sign In to add comment