Guest User

Untitled

a guest
Jul 23rd, 2016
3,370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.05 KB | None | 0 0
  1. /*==========================================================================
  2.  
  3. Dynamic Fast Food System
  4. ______________________
  5.  
  6.  
  7. Credits:-
  8. __________
  9.  
  10.  
  11. 1. Yashas for improved zcmd
  12. 2. Incognito for streamer plugin/include
  13. 3. Konstantinos for SQLite tutorial
  14. 4. adri1 for textdraw editor
  15. 5. Y_less for YSI library
  16.  
  17. ** Created by: SilentSoul
  18. ===========================================================================*/
  19. #include <a_samp>
  20. #include <izcmd>
  21. #include <streamer>
  22. #include <mSelection>
  23. #include <YSI\y_iterate>
  24.  
  25. #define MAX_FOOD (100) // Maximum to load from database, you may change that.
  26.  
  27. //Prices
  28. #define PIZZA_PRICE (10)
  29. #define FRIES_PRICE (5)
  30. #define COLA_PRICE (2)
  31. #define BURGER_PRICE (10)
  32. #define HOTDOG_PRICE (10)
  33.  
  34. enum FoodData
  35. {
  36. id,
  37. fmodelid,
  38. fcheckpointid,
  39. text[32],
  40. Text3D:textid,
  41.  
  42. Float:ObjPosX,
  43. Float:ObjPosY,
  44. Float:ObjPosZ,
  45. Float:ObjRotX,
  46. Float:ObjRotY,
  47. Float:ObjRotZ,
  48.  
  49. ActorID,
  50. ActorSkin,
  51. Float:ActorX,
  52. Float:ActorY,
  53. Float:ActorZ,
  54. Float:ActorRot
  55. };
  56.  
  57.  
  58. new
  59. FoodInfo[ MAX_FOOD ][FoodData ],
  60. DB:f_database,
  61. Iterator:Foods<MAX_FOOD>,
  62. Text:Foodobj[15],
  63. bool:Isviewingobj[MAX_PLAYERS],
  64. PlayerAttachedObject[MAX_PLAYERS];
  65.  
  66.  
  67. public OnFilterScriptInit()
  68. {
  69. print("\n--------------------------------------");
  70. print(" Dynamic fast food system loaded");
  71. print("--------------------------------------\n");
  72.  
  73. if ((f_database = db_open("food.db")) == DB: 0)
  74. {
  75. print("[SQLite]: Failed to open a connection to food.db");
  76. print("[SQLite]: Creating food.db database...");
  77. }
  78. else
  79. {
  80. db_query( f_database, "PRAGMA synchronous = OFF" );
  81. db_query( f_database, "CREATE TABLE IF NOT EXISTS food (id INTEGER, modelid INTEGER, text VARCHAR(32) COLLATE NOCASE, x FLOAT, y FLOAT, z FLOAT, rotx FLOAT, roty FLOAT, rotz FLOAT, Actorskin INTEGER, ActorX FLOAT, ActorY FLOAT, ActorZ FLOAT, ActorRot FLOAT)");
  82. }
  83.  
  84. new
  85. Query[ 23 ],
  86. DBResult: Result,
  87. str[ 64 ],
  88. fid;
  89. format( Query, sizeof( Query ) , "SELECT * FROM food" );
  90. Result = db_query( f_database, Query );
  91.  
  92. if (db_num_rows(Result))
  93. {
  94.  
  95. for ( new i = 0; i != db_num_rows(Result); i++ )
  96. {
  97. fid = db_get_field_assoc_int( Result, "id" );
  98. Iter_Add(Foods, fid);
  99.  
  100. FoodInfo[ fid ] [ fmodelid ] = db_get_field_assoc_int( Result, "modelid" );
  101.  
  102. db_get_field_assoc(Result, "text", FoodInfo[ fid ] [ text ], 32 );
  103.  
  104. FoodInfo[ fid ] [ ObjPosX ] = db_get_field_assoc_float( Result , "x" );
  105. FoodInfo[ fid ] [ ObjPosY ] = db_get_field_assoc_float( Result , "y" );
  106. FoodInfo[ fid ] [ ObjPosZ ] = db_get_field_assoc_float( Result , "z" );
  107.  
  108. FoodInfo[ fid ] [ ObjRotX ] = db_get_field_assoc_float( Result , "rotx" );
  109. FoodInfo[ fid ] [ ObjRotY ] = db_get_field_assoc_float( Result , "roty" );
  110. FoodInfo[ fid ] [ ObjRotZ ] = db_get_field_assoc_float( Result , "rotz" );
  111.  
  112. FoodInfo[ fid ] [ ActorSkin ] = db_get_field_assoc_int( Result, "Actorskin" );
  113. FoodInfo[ fid ] [ ActorX ] = db_get_field_assoc_float( Result , "ActorX" );
  114. FoodInfo[ fid ] [ ActorY ] = db_get_field_assoc_float( Result , "ActorY" );
  115. FoodInfo[ fid ] [ ActorZ ] = db_get_field_assoc_float( Result , "ActorZ" );
  116. FoodInfo[ fid ] [ ActorRot ] = db_get_field_assoc_float( Result , "ActorRot" );
  117.  
  118. format( str, sizeof( str ) , "%s\nID(%d)", FoodInfo[ fid ] [ text ], fid );
  119. FoodInfo[ fid ] [ textid ] = CreateDynamic3DTextLabel( str, -1, FoodInfo[ fid ] [ ObjPosX ], FoodInfo[ fid ] [ ObjPosY ], FoodInfo[ fid ] [ ObjPosZ ], 10.0 );
  120.  
  121. FoodInfo[ fid ] [ id ] = CreateDynamicObject( FoodInfo[ fid ] [ fmodelid ], FoodInfo[ fid ] [ ObjPosX ], FoodInfo[ fid ] [ ObjPosY ], FoodInfo[ fid ] [ ObjPosZ ], FoodInfo[ fid ] [ ObjRotX ], FoodInfo[ fid ] [ ObjRotY ], FoodInfo[ fid ] [ ObjRotZ ] );
  122.  
  123. FoodInfo[ fid ] [ ActorID ] = CreateActor( FoodInfo[ fid ] [ ActorSkin ] , FoodInfo[ fid ] [ ActorX ], FoodInfo[ fid ] [ ActorY ], FoodInfo[ fid ] [ ActorZ ], FoodInfo[ fid ] [ ActorRot ] );
  124.  
  125. GetXYInFrontOfActor( FoodInfo[ fid ] [ ActorID ], FoodInfo[ fid ] [ ActorX ], FoodInfo[ fid ] [ ActorY ], 2.0 );
  126. FoodInfo[ fid ] [ fcheckpointid ] = CreateDynamicCP( FoodInfo[ fid ] [ ActorX ], FoodInfo[ fid ] [ ActorY ],FoodInfo[ fid ] [ ActorZ ] , 1.0, -1, -1, -1, 10.0);
  127.  
  128. db_next_row(Result);
  129.  
  130. }
  131.  
  132. print("\n===========================================================================");
  133. printf( "[FOOD SYSTEM]: Loaded (%i) from the database.",db_num_rows(Result) );
  134. print("=============================================================================\n");
  135.  
  136. db_free_result(Result);
  137.  
  138. }
  139. Foodobj[1] = TextDrawCreate(192.699951, 118.449996, "");
  140. TextDrawLetterSize(Foodobj[1], 0.000000, 0.000000);
  141. TextDrawTextSize(Foodobj[1], 248.000000, 209.000000);
  142. TextDrawAlignment(Foodobj[1], 1);
  143. TextDrawColor(Foodobj[1], 255);
  144. TextDrawSetShadow(Foodobj[1], 0);
  145. TextDrawSetOutline(Foodobj[1], 0);
  146. TextDrawBackgroundColor(Foodobj[1], 0);
  147. TextDrawFont(Foodobj[1], 5);
  148. TextDrawSetProportional(Foodobj[1], 0);
  149. TextDrawSetShadow(Foodobj[1], 0);
  150. TextDrawSetPreviewModel(Foodobj[1], 1895);
  151. TextDrawSetPreviewRot(Foodobj[1], 0.000000, 0.000000, 0.000000, 1.000000);
  152.  
  153. Foodobj[0] = TextDrawCreate(278.500000, 120.000000, "box");
  154. TextDrawLetterSize(Foodobj[0], 0.000000, 15.299999);
  155. TextDrawTextSize(Foodobj[0], 350.000000, 0.000000);
  156. TextDrawAlignment(Foodobj[0], 1);
  157. TextDrawColor(Foodobj[0], -1);
  158. TextDrawUseBox(Foodobj[0], 1);
  159. TextDrawBoxColor(Foodobj[0], -935582209);
  160. TextDrawSetShadow(Foodobj[0], 0);
  161. TextDrawSetOutline(Foodobj[0], 0);
  162. TextDrawBackgroundColor(Foodobj[0], 255);
  163. TextDrawFont(Foodobj[0], 1);
  164. TextDrawSetProportional(Foodobj[0], 1);
  165. TextDrawSetShadow(Foodobj[0], 0);
  166.  
  167. Foodobj[2] = TextDrawCreate(219.500000, 206.187500, "");
  168. TextDrawLetterSize(Foodobj[2], 0.000000, 0.000000);
  169. TextDrawTextSize(Foodobj[2], 186.000000, 81.000000);
  170. TextDrawAlignment(Foodobj[2], 1);
  171. TextDrawColor(Foodobj[2], 255);
  172. TextDrawSetShadow(Foodobj[2], 0);
  173. TextDrawSetOutline(Foodobj[2], 0);
  174. TextDrawBackgroundColor(Foodobj[2], 0);
  175. TextDrawFont(Foodobj[2], 5);
  176. TextDrawSetProportional(Foodobj[2], 0);
  177. TextDrawSetShadow(Foodobj[2], 0);
  178. TextDrawSetPreviewModel(Foodobj[2], 19134);
  179. TextDrawSetPreviewRot(Foodobj[2], 0.000000, 0.000000, 90.000000, 1.000000);
  180.  
  181. Foodobj[3] = TextDrawCreate(296.500000, 144.062500, "FAST~n~~n~~n~MENU");
  182. TextDrawLetterSize(Foodobj[3], 0.400000, 1.600000);
  183. TextDrawAlignment(Foodobj[3], 1);
  184. TextDrawColor(Foodobj[3], -54630401);
  185. TextDrawSetShadow(Foodobj[3], 0);
  186. TextDrawSetOutline(Foodobj[3], 0);
  187. TextDrawBackgroundColor(Foodobj[3], 255);
  188. TextDrawFont(Foodobj[3], 1);
  189. TextDrawSetProportional(Foodobj[3], 1);
  190. TextDrawSetShadow(Foodobj[3], 0);
  191.  
  192. Foodobj[4] = TextDrawCreate(287.500000, 162.000000, "FOOD");
  193. TextDrawLetterSize(Foodobj[4], 0.539499, 1.888749);
  194. TextDrawAlignment(Foodobj[4], 1);
  195. TextDrawColor(Foodobj[4], -1);
  196. TextDrawSetShadow(Foodobj[4], 0);
  197. TextDrawSetOutline(Foodobj[4], 0);
  198. TextDrawBackgroundColor(Foodobj[4], 255);
  199. TextDrawFont(Foodobj[4], 1);
  200. TextDrawSetProportional(Foodobj[4], 1);
  201. TextDrawSetShadow(Foodobj[4], 0);
  202.  
  203. Foodobj[5] = TextDrawCreate(183.500000, 120.000000, "");
  204. TextDrawLetterSize(Foodobj[5], 0.000000, 0.000000);
  205. TextDrawTextSize(Foodobj[5], 90.000000, 90.000000);
  206. TextDrawAlignment(Foodobj[5], 1);
  207. TextDrawColor(Foodobj[5], -1);
  208. TextDrawSetShadow(Foodobj[5], 0);
  209. TextDrawSetOutline(Foodobj[5], 0);
  210. TextDrawBackgroundColor(Foodobj[5], 0);
  211. TextDrawFont(Foodobj[5], 5);
  212. TextDrawSetProportional(Foodobj[5], 0);
  213. TextDrawSetShadow(Foodobj[5], 0);
  214. TextDrawSetSelectable(Foodobj[5], true);
  215. TextDrawSetPreviewModel(Foodobj[5], 2702);
  216. TextDrawSetPreviewRot(Foodobj[5], 0.000000, -60.000000, 90.000000, 1.000000);
  217.  
  218. Foodobj[6] = TextDrawCreate(221.500000, 197.875000, "PIZZA~n~~g~$10");
  219. TextDrawLetterSize(Foodobj[6], 0.282500, 0.865000);
  220. TextDrawAlignment(Foodobj[6], 1);
  221. TextDrawColor(Foodobj[6], -1);
  222. TextDrawSetShadow(Foodobj[6], 0);
  223. TextDrawSetOutline(Foodobj[6], 0);
  224. TextDrawBackgroundColor(Foodobj[6], 255);
  225. TextDrawFont(Foodobj[6], 2);
  226. TextDrawSetProportional(Foodobj[6], 1);
  227. TextDrawSetShadow(Foodobj[6], 0);
  228.  
  229. Foodobj[7] = TextDrawCreate(183.000000, 193.500000, "");
  230. TextDrawLetterSize(Foodobj[7], 0.000000, 0.000000);
  231. TextDrawTextSize(Foodobj[7], 83.000000, 101.000000);
  232. TextDrawAlignment(Foodobj[7], 1);
  233. TextDrawColor(Foodobj[7], -1);
  234. TextDrawSetShadow(Foodobj[7], 0);
  235. TextDrawSetOutline(Foodobj[7], 0);
  236. TextDrawBackgroundColor(Foodobj[7], 0);
  237. TextDrawFont(Foodobj[7], 5);
  238. TextDrawSetProportional(Foodobj[7], 0);
  239. TextDrawSetShadow(Foodobj[7], 0);
  240. TextDrawSetSelectable(Foodobj[7], true);
  241. TextDrawSetPreviewModel(Foodobj[7], 2858);
  242. TextDrawSetPreviewRot(Foodobj[7], 0.000000, 0.000000, 270.000000, 1.000000);
  243.  
  244. Foodobj[8] = TextDrawCreate(227.500000, 260.875000, "FRIES~n~~g~$5");
  245. TextDrawLetterSize(Foodobj[8], 0.282500, 0.865000);
  246. TextDrawAlignment(Foodobj[8], 1);
  247. TextDrawColor(Foodobj[8], -1);
  248. TextDrawSetShadow(Foodobj[8], 0);
  249. TextDrawSetOutline(Foodobj[8], 0);
  250. TextDrawBackgroundColor(Foodobj[8], 255);
  251. TextDrawFont(Foodobj[8], 2);
  252. TextDrawSetProportional(Foodobj[8], 1);
  253. TextDrawSetShadow(Foodobj[8], 0);
  254.  
  255. Foodobj[9] = TextDrawCreate(282.000000, 239.437500, "");
  256. TextDrawLetterSize(Foodobj[9], 0.000000, 0.000000);
  257. TextDrawTextSize(Foodobj[9], 58.000000, 66.000000);
  258. TextDrawAlignment(Foodobj[9], 1);
  259. TextDrawColor(Foodobj[9], -1);
  260. TextDrawSetShadow(Foodobj[9], 0);
  261. TextDrawSetOutline(Foodobj[9], 0);
  262. TextDrawBackgroundColor(Foodobj[9], 0);
  263. TextDrawFont(Foodobj[9], 5);
  264. TextDrawSetProportional(Foodobj[9], 0);
  265. TextDrawSetShadow(Foodobj[9], 0);
  266. TextDrawSetSelectable(Foodobj[9], true);
  267. TextDrawSetPreviewModel(Foodobj[9], 2647);
  268. TextDrawSetPreviewRot(Foodobj[9], 0.000000, 0.000000, 270.000000, 1.000000);
  269.  
  270. Foodobj[10] = TextDrawCreate(300.000000, 294.562500, "COLA~n~~g~$2");
  271. TextDrawLetterSize(Foodobj[10], 0.282500, 0.865000);
  272. TextDrawAlignment(Foodobj[10], 1);
  273. TextDrawColor(Foodobj[10], -1);
  274. TextDrawSetShadow(Foodobj[10], 0);
  275. TextDrawSetOutline(Foodobj[10], 0);
  276. TextDrawBackgroundColor(Foodobj[10], 255);
  277. TextDrawFont(Foodobj[10], 2);
  278. TextDrawSetProportional(Foodobj[10], 1);
  279. TextDrawSetShadow(Foodobj[10], 0);
  280.  
  281. Foodobj[11] = TextDrawCreate(360.000000, 213.625000, "");
  282. TextDrawLetterSize(Foodobj[11], 0.000000, 0.000000);
  283. TextDrawTextSize(Foodobj[11], 58.000000, 66.000000);
  284. TextDrawAlignment(Foodobj[11], 1);
  285. TextDrawColor(Foodobj[11], -1);
  286. TextDrawSetShadow(Foodobj[11], 0);
  287. TextDrawSetOutline(Foodobj[11], 0);
  288. TextDrawBackgroundColor(Foodobj[11], 0);
  289. TextDrawFont(Foodobj[11], 5);
  290. TextDrawSetProportional(Foodobj[11], 0);
  291. TextDrawSetShadow(Foodobj[11], 0);
  292. TextDrawSetSelectable(Foodobj[11], true);
  293. TextDrawSetPreviewModel(Foodobj[11], 2880);
  294. TextDrawSetPreviewRot(Foodobj[11], 180.000000, 90.000000, 360.000000, 1.000000);
  295.  
  296. Foodobj[12] = TextDrawCreate(374.500000, 249.500000, "BURGER~n~~g~$10");
  297. TextDrawLetterSize(Foodobj[12], 0.282500, 0.865000);
  298. TextDrawAlignment(Foodobj[12], 1);
  299. TextDrawColor(Foodobj[12], -1);
  300. TextDrawSetShadow(Foodobj[12], 0);
  301. TextDrawSetOutline(Foodobj[12], 0);
  302. TextDrawBackgroundColor(Foodobj[12], 255);
  303. TextDrawFont(Foodobj[12], 2);
  304. TextDrawSetProportional(Foodobj[12], 1);
  305. TextDrawSetShadow(Foodobj[12], 0);
  306.  
  307. Foodobj[13] = TextDrawCreate(292.500000, 95.500000, "");
  308. TextDrawLetterSize(Foodobj[13], 0.000000, 0.000000);
  309. TextDrawTextSize(Foodobj[13], 165.000000, 125.000000);
  310. TextDrawAlignment(Foodobj[13], 1);
  311. TextDrawColor(Foodobj[13], -1);
  312. TextDrawSetShadow(Foodobj[13], 0);
  313. TextDrawSetOutline(Foodobj[13], 0);
  314. TextDrawBackgroundColor(Foodobj[13], 0);
  315. TextDrawFont(Foodobj[13], 5);
  316. TextDrawSetProportional(Foodobj[13], 0);
  317. TextDrawSetShadow(Foodobj[13], 0);
  318. TextDrawSetSelectable(Foodobj[13], true);
  319. TextDrawSetPreviewModel(Foodobj[13], 2769);
  320. TextDrawSetPreviewRot(Foodobj[13], 0.000000, 60.000000, 90.000000, 1.000000);
  321.  
  322. Foodobj[14] = TextDrawCreate(364.000000, 192.625000, "Hot-dog~n~~g~$15");
  323. TextDrawLetterSize(Foodobj[14], 0.282500, 0.865000);
  324. TextDrawAlignment(Foodobj[14], 1);
  325. TextDrawColor(Foodobj[14], -1);
  326. TextDrawSetShadow(Foodobj[14], 0);
  327. TextDrawSetOutline(Foodobj[14], 0);
  328. TextDrawBackgroundColor(Foodobj[14], 255);
  329. TextDrawFont(Foodobj[14], 2);
  330. TextDrawSetProportional(Foodobj[14], 1);
  331. TextDrawSetShadow(Foodobj[14], 0);
  332. return true;
  333. }
  334.  
  335. public OnFilterScriptExit()
  336. {
  337. for( new o = 0; o < 15; o++ )
  338. {
  339. TextDrawDestroy( Foodobj[o] );
  340. }
  341. for( new p = 0; p < MAX_FOOD; p ++ )
  342. {
  343. if( IsValidDynamicObject( FoodInfo[ p ] [ id ] ) ) { DestroyDynamicObject( FoodInfo[ p ] [ id ] ); }
  344. if( IsValidDynamicCP( FoodInfo[ p ] [ fcheckpointid ] ) ) { DestroyDynamicCP( FoodInfo[ p ] [ fcheckpointid ] ); }
  345. if( IsValidDynamic3DTextLabel( FoodInfo[ p ] [ textid ] ) ) { DestroyDynamic3DTextLabel( FoodInfo[ p ] [ textid ] ); }
  346. DestroyActor( FoodInfo[ p ] [ ActorID ] );
  347. }
  348. return true;
  349. }
  350. public OnPlayerConnect(playerid)
  351. {
  352. EnablePlayerCameraTarget(playerid, true);
  353.  
  354. return true;
  355. }
  356. public OnPlayerSpawn(playerid)
  357. {
  358. PreloadAnimLib( playerid, "FOOD" );
  359. PreloadAnimLib( playerid, "DEALER" );
  360. PreloadAnimLib( playerid, "VENDING" );
  361.  
  362. return true;
  363. }
  364. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  365. {
  366. if(dialogid == 122 )
  367. {
  368. if(response)
  369. {
  370. switch( listitem )
  371. {
  372. case 0:
  373. {
  374. new
  375. objects[ 3 ];
  376. objects [ 0 ] = 1340, objects[ 1 ] = 956, objects[ 2 ] = 1776;//you may add all the objects you want
  377. ShowModelSelectionMenuEx(playerid, objects, 3, "Select object model", 124, 16.0, 0.0, 180.0, 1.0, 0x00000033, 0x00000066, 0xA1A1A133);
  378. }
  379. case 1:
  380. {
  381. new
  382. str[ 256 ];
  383. for( new i = 0; i < MAX_FOOD; i++ )
  384. {
  385. if( IsValidDynamicObject( FoodInfo[ i ] [ id ] ) )
  386. {
  387. format( str, sizeof( str ), "%s %s [ID:%d]\n", str, FoodInfo[ i ] [ text ], i );
  388. }
  389. }
  390. ShowPlayerDialog( playerid, 0, DIALOG_STYLE_LIST, "Information", str, "Ok","" );
  391. }
  392. case 2:
  393. {
  394. ShowPlayerDialog( playerid, 124, DIALOG_STYLE_INPUT, "Type the ID", "Type the ID you would like to teleport there", "Ok","" );
  395. }
  396. case 3:
  397. {
  398. ShowPlayerDialog( playerid, 125, DIALOG_STYLE_INPUT, "Type the ID","Please type the ID of the desired one to be deleted\nNOTE: its found on the object", "Ok", "Back" );
  399. }
  400. }
  401. }
  402. }
  403. if( dialogid == 123 )
  404. {
  405. if( ! response ) return ShowPlayerDialog( playerid, 123, DIALOG_STYLE_INPUT, "Type text", "Type here the text you would like to attach to the object\n{FF0000}You can't skip this! its obligatory", "Ok", "");
  406. if( response )
  407. {
  408. new
  409. str[ 64 ], query[ 520 ], f_id;
  410. f_id = Iter_Free(Foods);
  411. format( str, sizeof( str ) , "%s\nID(%d)", inputtext, f_id );
  412. FoodInfo[ f_id] [ textid ] = CreateDynamic3DTextLabel( str, -1, FoodInfo[ f_id ] [ ObjPosX ], FoodInfo[ f_id ] [ ObjPosY ], FoodInfo[ f_id ] [ ObjPosZ ], 10.0 );
  413. format(FoodInfo[ f_id ] [ text ], 32, "%s", inputtext);
  414. format( query , sizeof( query ) , "INSERT INTO food (id, modelid, text, x, y, z, rotx, roty, rotz, Actorskin, ActorX, ActorY, ActorZ , ActorRot) VALUES (%d, %d, '%s', %f, %f, %f, %f, %f, %f, %d, %f, %f, %f, %f)",\
  415. f_id,
  416. FoodInfo[ f_id ] [ fmodelid ],
  417. inputtext ,
  418. FoodInfo[ f_id ] [ ObjPosX ] ,
  419. FoodInfo[ f_id ] [ ObjPosY ],
  420. FoodInfo[ f_id ] [ ObjPosZ ],
  421. FoodInfo[ f_id ] [ ObjRotX ],
  422. FoodInfo[ f_id ] [ ObjRotY ],
  423. FoodInfo[ f_id ] [ ObjRotZ ],
  424. FoodInfo[ f_id ] [ ActorSkin ] ,
  425. FoodInfo[ f_id ] [ ActorX ],
  426. FoodInfo[ f_id ] [ ActorY ],
  427. FoodInfo[ f_id ] [ ActorZ ],
  428. FoodInfo[ f_id ] [ ActorRot ] );
  429.  
  430. db_query( f_database, query );
  431.  
  432. GetXYInFrontOfActor( FoodInfo[ f_id ] [ ActorID ], FoodInfo[ f_id ] [ ActorX ], FoodInfo[ f_id ] [ ActorY ], 2.0 );
  433. FoodInfo[ f_id ] [ fcheckpointid ] = CreateDynamicCP( FoodInfo[ f_id ] [ ActorX ], FoodInfo[ f_id ] [ ActorY ],FoodInfo[ f_id ] [ ActorZ ] , 1.0, -1, -1, -1, 10.0);
  434.  
  435. Iter_Add(Foods, f_id);
  436. }
  437. }
  438. if( dialogid == 124 )
  439. {
  440. if( response )
  441. {
  442. new
  443. f_id = strval(inputtext);
  444. if(! strval( inputtext ) ) return SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} You must enter numbers only" );
  445. if( !IsValidDynamicObject( FoodInfo[ f_id ] [ id ] )) return SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} That object does not exist!" );
  446.  
  447. new
  448. Float:x, Float:y, Float:z;
  449. GetDynamicObjectPos( FoodInfo[ strval(inputtext) ] [ id ] , x, y, z );
  450. SetPlayerPos( playerid, x+2.0, y+1.0,z );
  451. GameTextForPlayer( playerid, "~b~~h~Teleported!", 2000, 3 );
  452. }
  453. }
  454. if( dialogid == 125 )
  455. {
  456. if(response)
  457. {
  458. new
  459. f_id = strval(inputtext);
  460. if(!Iter_Contains(Foods, f_id)) return SendClientMessage( playerid, 0x00B503FF, "[INFO]{FFFFFF} Please type the number only (0-99)" );
  461. if( !IsValidDynamicObject( FoodInfo[ f_id ] [ id ] )) return SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} That object does not exist!" );
  462.  
  463. DestroyDynamicObject( FoodInfo[ f_id ] [ id ] );
  464.  
  465. DestroyDynamic3DTextLabel( FoodInfo[ f_id ] [ textid ] );
  466. DestroyActor( FoodInfo[ f_id ] [ ActorID ] );
  467. DestroyDynamicCP( FoodInfo[ f_id ] [ fcheckpointid ] );
  468. new
  469. query[ 64 ];
  470. format( query, sizeof( query ) , "DELETE FROM `food` WHERE id = %d", f_id );
  471. db_query( f_database, query );
  472. GameTextForPlayer( playerid, "~g~Object Deleted!", 3000, 3 );
  473. Iter_Remove(Foods, f_id);
  474. }
  475. }
  476. return false;
  477. }
  478.  
  479. public OnPlayerClickTextDraw(playerid, Text:clickedid)
  480. {
  481. if( clickedid == Text:INVALID_TEXT_DRAW )//if escape button is pressed
  482. {
  483. if( Isviewingobj[ playerid ] == true )
  484. {
  485. HidefoodTD( playerid );
  486. Isviewingobj[ playerid ] = false;
  487. }
  488. }
  489. if( clickedid == Foodobj[5] )
  490. {
  491. if( GetPlayerMoney( playerid ) < PIZZA_PRICE ) return SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} You don't have money to buy that food" );
  492. GivePlayerMoney( playerid, - PIZZA_PRICE );
  493. SetPlayerArmedWeapon(playerid,0);
  494. HidefoodTD( playerid );
  495.  
  496. new
  497. actorid = GetPlayerCameraTargetActor(playerid);
  498. ApplyActorAnimation( actorid , "DEALER" , "shop_pay" , 4.0 , 0 , 0 , 0 , 0 , 0 );
  499.  
  500. PlayerAttachedObject[ playerid ] = FindFreeObjectSlot( playerid );
  501. SetPlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ], 2702, 6, 0.138999, 0.046999, 0.021999, 0.000000, -7.300000, -90.100006, 1.000000, 1.000000, 1.000000);
  502. ApplyAnimation(playerid, "FOOD", "EAT_Pizza", 4.0, 0 ,0 ,0 ,1 ,0 );
  503. SetTimerEx("RemoveObject", 3000, false, "i", playerid );
  504.  
  505. }
  506. if ( clickedid == Foodobj[7] )
  507. {
  508. if( GetPlayerMoney( playerid ) < FRIES_PRICE ) return SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} You don't have money to buy that food" );
  509. GivePlayerMoney( playerid, - FRIES_PRICE );
  510. SetPlayerArmedWeapon(playerid,0);
  511. HidefoodTD( playerid );
  512.  
  513. new
  514. actorid = GetPlayerCameraTargetActor(playerid);
  515. ApplyActorAnimation( actorid , "DEALER" , "shop_pay" , 4.0 , 0 , 0 , 0 , 0 , 0 );
  516.  
  517. PlayerAttachedObject[ playerid ] = FindFreeObjectSlot( playerid );
  518. SetPlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ], 2858, 6, 0.127000, 0.005999, 0.019999, 0.000000, -97.199974, 0.000000, 0.243000, 0.248000, 0.934000);
  519. ApplyAnimation(playerid, "FOOD", "EAT_Pizza", 4.0, 0 ,0 ,0 ,1 ,0 );
  520. SetTimerEx("RemoveObject", 3000, false, "i", playerid );
  521.  
  522. }
  523. if ( clickedid == Foodobj[9] )
  524. {
  525. if( GetPlayerMoney( playerid ) < COLA_PRICE ) return SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} You don't have money to buy that food" );
  526. GivePlayerMoney( playerid, - COLA_PRICE );
  527. SetPlayerArmedWeapon(playerid,0);
  528. HidefoodTD( playerid );
  529.  
  530. new
  531. actorid = GetPlayerCameraTargetActor(playerid);
  532. ApplyActorAnimation( actorid , "DEALER" , "shop_pay" , 4.0 , 0 , 0 , 0 , 0 , 0 );
  533.  
  534. PlayerAttachedObject[ playerid ] = FindFreeObjectSlot( playerid );
  535. SetPlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ], 2647, 5, 0.147000, 0.036000, -0.009999, -45.299995, -95.299987, 0.000000, 0.715999, 0.839999, 0.786000);
  536. ApplyAnimation(playerid, "VENDING", "VEND_Drink_P", 4.0, 0 ,0 ,0 ,1 ,0 );
  537. SetTimerEx("RemoveObject", 3000, false, "i", playerid );
  538.  
  539. }
  540. if ( clickedid == Foodobj[11] )
  541. {
  542. if( GetPlayerMoney( playerid ) < BURGER_PRICE ) return SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} You don't have money to buy that food" );
  543. GivePlayerMoney( playerid, - BURGER_PRICE );
  544. SetPlayerArmedWeapon(playerid,0);
  545. HidefoodTD( playerid );
  546.  
  547. new
  548. actorid = GetPlayerCameraTargetActor(playerid);
  549. ApplyActorAnimation( actorid , "DEALER" , "shop_pay" , 4.0 , 0 , 0 , 0 , 0 , 0 );
  550.  
  551. PlayerAttachedObject[ playerid ] = FindFreeObjectSlot( playerid );
  552. SetPlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ], 2880, 6, 0.111999, 0.178000, 0.007999, 0.000000, 0.000000, -157.000045, 1.000000, 1.000000, 1.000000);
  553. ApplyAnimation(playerid, "FOOD", "EAT_Burger", 4.0, 0 ,0 ,0 ,1 ,0 );
  554. SetTimerEx("RemoveObject", 3000, false, "i", playerid );
  555.  
  556. }
  557. if ( clickedid == Foodobj[13] )
  558. {
  559. if( GetPlayerMoney( playerid ) < HOTDOG_PRICE ) return SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} You don't have money to buy that food" );
  560. GivePlayerMoney( playerid, - HOTDOG_PRICE );
  561. HidefoodTD( playerid );
  562.  
  563. new
  564. actorid = GetPlayerCameraTargetActor(playerid);
  565. ApplyActorAnimation( actorid , "DEALER" , "shop_pay" , 4.0 , 0 , 0 , 0 , 0 , 0 );
  566.  
  567. PlayerAttachedObject[ playerid ] = FindFreeObjectSlot( playerid );
  568. SetPlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ], 2769, 6, 0.109999, 0.034999, 0.009000, 11.599999, 0.000000, -12.899994, 1.000000, 1.000000, 1.000000);
  569. ApplyAnimation(playerid, "FOOD", "EAT_Chicken", 4.0, 0 ,0 ,0 ,1 ,0 );
  570. SetTimerEx("RemoveObject", 3000, false, "i", playerid );
  571.  
  572. }
  573. return true;
  574. }
  575. forward RemoveObject( playerid );
  576. public RemoveObject( playerid )
  577. {
  578. new
  579. Float:h;
  580. GetPlayerHealth( playerid, h );
  581. printf("health %f", h);
  582. RemovePlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ] );
  583. ClearAnimations( playerid );
  584. if( h < 100 && h >= 89 )
  585. {
  586. SetPlayerHealth( playerid, 100 );
  587. }
  588. if( h < 89)
  589. {
  590. SetPlayerHealth( playerid, h+10 );
  591. }
  592. }
  593. public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
  594. {
  595. new f_id;
  596. f_id = Iter_Free(Foods);
  597. if( objectid == FoodInfo[ f_id ] [ id ] )
  598. {
  599. if( response == EDIT_RESPONSE_UPDATE )
  600. {
  601. SetDynamicObjectPos( objectid, x, y, z );
  602. SetDynamicObjectRot( objectid, rx, ry, rz );// to update it so others may see it.
  603. }
  604. if ( response == EDIT_RESPONSE_FINAL )
  605. {
  606. FoodInfo[ f_id ] [ id ]= objectid;
  607.  
  608. FoodInfo[ f_id ] [ ObjPosX ] = x;
  609. FoodInfo[ f_id ] [ ObjPosY ] = y;
  610. FoodInfo[ f_id ] [ ObjPosZ ] = z;
  611.  
  612. FoodInfo[ f_id ] [ ObjRotX ] = rx;
  613. FoodInfo[ f_id ] [ ObjRotY ] = ry;
  614. FoodInfo[ f_id ] [ ObjRotZ ] = rz;
  615. SetDynamicObjectPos( objectid, x, y, z );
  616. SetDynamicObjectRot( objectid, rx, ry, rz );
  617. new
  618. skins[ 6 ];
  619. skins [ 0 ] = 171, skins[ 1 ] = 172, skins[ 2 ] = 169, skins[ 3 ] = 167, skins[ 4 ] = 168, skins[ 5 ] = 161;
  620. ShowModelSelectionMenuEx(playerid, skins, 6, "Select actor skin", 123, 16.0, 0.0, -55.0, 1.0, 0x00000033, 0x00000066, 0xA1A1A133);
  621. }
  622. else if( response == EDIT_RESPONSE_CANCEL ) { print("not response hahahahha"); DestroyDynamicObject( FoodInfo[ f_id ] [ id ]) ; }
  623. }
  624. return true;
  625. }
  626. public OnPlayerModelSelectionEx(playerid, response, extraid, modelid)
  627. {
  628. if(extraid == 123)
  629. {
  630. if(response)
  631. {
  632. new
  633. f_id;
  634. f_id = Iter_Free(Foods);
  635. FoodInfo[ f_id ] [ ActorSkin ] = modelid;
  636. SendClientMessage( playerid, 0x00B503FF, "[INFO]{FFFFFF} Now stand where you want to add the actor and type /saveact" );
  637. GameTextForPlayer( playerid, "~w~Stand somewhere near object and type ~g~/saveact", 6000, 3 );
  638. }
  639. }
  640. if(extraid == 124)
  641. {
  642. new
  643. Float:x, Float:y, Float:z, f_id;
  644. f_id = Iter_Free(Foods);
  645. if( f_id == -1 || f_id == MAX_FOOD ) return SendClientMessage( playerid , 0xFF0000FF, "[ERROR]{FFFFFF}You have reached the maxium limit!" );
  646. GetPlayerPos( playerid, x, y, z );
  647. FoodInfo[ f_id ] [ id ] = CreateDynamicObject( modelid, x+2.0, y, z, 0.0, 0.0, 0,0 );
  648. EditDynamicObject( playerid, FoodInfo[ f_id ] [ id ] );
  649. FoodInfo[ f_id ] [ fmodelid ] = modelid;
  650. }
  651. return 1;
  652. }
  653. public OnPlayerEnterDynamicCP(playerid, checkpointid)
  654. {
  655. for( new i = 0; i <= MAX_FOOD; i++ )
  656. {
  657. if( checkpointid == FoodInfo[ i ] [ fcheckpointid ] )
  658. {
  659. if(Isviewingobj[ playerid ] == false)
  660. {
  661. ShowfoodTD( playerid );
  662. Isviewingobj[ playerid ] = true;
  663. }
  664. }
  665. }
  666. return true;
  667. }
  668. /*==========================================================
  669. Functions
  670. ============================================================*/
  671. ShowfoodTD( playerid )
  672. {
  673. for ( new i = 0; i < 15; i ++ )
  674. {
  675. TextDrawShowForPlayer( playerid, Foodobj[ i ] );
  676.  
  677. }
  678. SelectTextDraw(playerid, 0x00FF00FF);
  679. }
  680. HidefoodTD( playerid )
  681. {
  682. for ( new i = 0; i < 15; i ++ )
  683. {
  684. TextDrawHideForPlayer( playerid, Foodobj[ i ] );
  685. }
  686. CancelSelectTextDraw(playerid);
  687. }
  688.  
  689. stock GetXYInFrontOfActor(actorid, &Float:x, &Float:y, Float:distance)
  690. {
  691. // Created by Y_Less, just modified by me
  692.  
  693. new Float:a;
  694.  
  695. GetActorPos(actorid, x, y, a);
  696. GetActorFacingAngle(actorid, a);
  697.  
  698. x += (distance * floatsin(-a, degrees));
  699. y += (distance * floatcos(-a, degrees));
  700. }
  701. FindFreeObjectSlot( playerid )
  702. {
  703. new
  704. objid;
  705. for( new i = 0; i < MAX_PLAYER_ATTACHED_OBJECTS; i++ )
  706. {
  707. if( IsPlayerAttachedObjectSlotUsed( playerid, i ) ) continue;
  708. objid = i;
  709. }
  710. return objid;
  711. }
  712. PreloadAnimLib(playerid, animlib[]) // not by me
  713. {
  714. ApplyAnimation( playerid,animlib,"null",0.0,0,0,0,0,0 );
  715. }
  716. /*==========================================================
  717. commands
  718. ============================================================*/
  719. CMD:food( playerid )
  720. {
  721. ShowPlayerDialog( playerid, 122, DIALOG_STYLE_LIST, "Choose option", "Create new food machine\nList of food machines\nTeleport to food machine\nDelete food machine", "Select", "Cancel" );
  722. return true;
  723. }
  724. CMD:saveact( playerid )
  725. {
  726. new
  727. Float:x, Float:y, Float:z, Float:ang, f_id;
  728. f_id = Iter_Free(Foods);
  729. GetPlayerPos( playerid, x, y, z );
  730. GetPlayerFacingAngle( playerid, ang );
  731. if(! IsPlayerInRangeOfPoint( playerid, 3.0, FoodInfo[ f_id ] [ ObjPosX ], FoodInfo[ f_id ] [ ObjPosY ], FoodInfo[ f_id ] [ ObjPosZ ] ) ) return SendClientMessage( playerid, -1, "You're far from that object!" );
  732.  
  733.  
  734. FoodInfo[ f_id ] [ ActorX ] = x;
  735. FoodInfo[ f_id ] [ ActorY ] = y;
  736. FoodInfo[ f_id ] [ ActorZ ] = z;
  737. FoodInfo[ f_id ] [ ActorRot ] = ang;
  738.  
  739. FoodInfo[ f_id ] [ ActorID ] = CreateActor( FoodInfo[ f_id ] [ ActorSkin ] , FoodInfo[ f_id ] [ ActorX ], FoodInfo[ f_id ] [ ActorY ], FoodInfo[ f_id ] [ ActorZ ], FoodInfo[ f_id ] [ ActorRot ] );
  740.  
  741. SetPlayerPos( playerid, x+2.0, y, z );
  742.  
  743. ShowPlayerDialog( playerid, 123, DIALOG_STYLE_INPUT, "Type text", "Type here the text you would like to attach to the object", "Ok", "");
  744. return true;
  745. }
Advertisement
Add Comment
Please, Sign In to add comment