Advertisement
CyPh3R

Wings model Shop v1.0

Apr 30th, 2017
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.57 KB | None | 0 0
  1. #include < amxmodx >
  2. #include < fakemeta_util >
  3. #include < engine >
  4. #include < fun >
  5. #include < fvault >
  6.  
  7. native get_user_cash(client);
  8. native set_user_cash(client, amount);
  9.  
  10. new UseWing[ 33 ];
  11. new Wings[ 33 ];
  12.  
  13. new szVault[ ] = "Wings_vault";
  14. new g_Sprite[ ][ ] = {"sprites/lgtning.spr" };
  15. new Sprite;
  16. new para_ent[33]
  17.  
  18. enum _:WingsBrowse{
  19. modelplace[ 128 ],
  20. Name[ 33 ],
  21. price
  22. }
  23.  
  24. new const g_szWings[ 5 ][ WingsBrowse ] =
  25. {
  26. { "models/AMXX/wings1.mdl", "Wing #1", 100000 },
  27. { "models/AMXX/wings2.mdl", "Wing #2", 200000 },
  28. { "models/AMXX/wings3.mdl", "Wing #3", 300000 },
  29. { "models/AMXX/wings4.mdl", "Wing #4", 400000 },
  30. { "models/AMXX/wings5.mdl", "Wing #5", 500000 }
  31. }
  32.  
  33. public plugin_init()
  34. {
  35. register_clcmd("say /wing","MainMenu");
  36. register_clcmd("say /wings","MainMenu");
  37.  
  38. register_event("ResetHUD", "newSpawn", "be")
  39. register_event("DeathMsg", "death_event", "a")
  40. }
  41.  
  42. public plugin_precache()
  43. {
  44. for ( new i = 0; i < sizeof( g_szWings ); i++ )
  45. precache_model( g_szWings[ i ][ modelplace ] );
  46.  
  47. Sprite = precache_model( g_Sprite[ 0 ] );
  48. }
  49.  
  50. public death_event()
  51. {
  52. new id = read_data(2)
  53. parachute_reset(id)
  54. }
  55.  
  56. parachute_reset(id)
  57. {
  58. if(para_ent[id] > 0)
  59. {
  60. if (is_valid_ent(para_ent[id]))
  61. {
  62. remove_entity(para_ent[id])
  63. }
  64. }
  65.  
  66. if(is_user_alive(id)) set_user_gravity(id, 1.0)
  67. para_ent[id] = 0
  68. }
  69.  
  70. public newSpawn(id)
  71. {
  72. if(para_ent[id] > 0)
  73. {
  74. remove_entity(para_ent[id])
  75. set_user_gravity(id, 1.0)
  76. para_ent[id] = 0
  77. }
  78. }
  79.  
  80. public client_PreThink(id)
  81. {
  82. if( UseWing[ id ] >= 1 && Wings[ id ] >= 1 )
  83. {
  84.  
  85. new Float:fallspeed = 100 * -1.0
  86. new Float:frame
  87. new button = get_user_button(id)
  88. new oldbutton = get_user_oldbutton(id)
  89. new flags = get_entity_flags(id)
  90. if(para_ent[id] > 0 && (flags & FL_ONGROUND))
  91. {
  92. if(get_user_gravity(id) == 0.1) set_user_gravity(id, 1.0)
  93. {
  94. if(entity_get_int(para_ent[id],EV_INT_sequence) != 2)
  95. {
  96. entity_set_int(para_ent[id], EV_INT_sequence, 2)
  97. entity_set_int(para_ent[id], EV_INT_gaitsequence, 1)
  98. entity_set_float(para_ent[id], EV_FL_frame, 0.0)
  99. entity_set_float(para_ent[id], EV_FL_fuser1, 0.0)
  100. entity_set_float(para_ent[id], EV_FL_animtime, 0.0)
  101. entity_set_float(para_ent[id], EV_FL_framerate, 0.0)
  102. return
  103. }
  104. frame = entity_get_float(para_ent[id],EV_FL_fuser1) + 2.0
  105. entity_set_float(para_ent[id],EV_FL_fuser1,frame)
  106. entity_set_float(para_ent[id],EV_FL_frame,frame)
  107. if(frame > 254.0)
  108. {
  109. remove_entity(para_ent[id])
  110. para_ent[id] = 0
  111. }
  112. else
  113. {
  114. remove_entity(para_ent[id])
  115. set_user_gravity(id, 1.0)
  116. para_ent[id] = 0
  117. }
  118. return
  119. }
  120. }
  121. if (button & IN_USE)
  122. {
  123. new Float:velocity[3]
  124. entity_get_vector(id, EV_VEC_velocity, velocity)
  125. if(velocity[2] < 0.0)
  126. {
  127. if(para_ent[id] <= 0)
  128. {
  129. para_ent[id] = create_entity("info_target")
  130. if(para_ent[id] > 0)
  131. {
  132. entity_set_edict( para_ent[id], EV_ENT_euser1, id );
  133. entity_set_int( para_ent[id], EV_INT_iuser1, 0 );
  134. entity_set_size( para_ent[id], Float:{-6.0,-6.0,-6.0}, Float:{6.0,6.0,6.0} );
  135. entity_set_float( para_ent[id], EV_FL_friction, 0.6 );
  136.  
  137. message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
  138. write_byte( TE_BEAMFOLLOW );
  139. write_short( para_ent[id] );
  140. write_short( Sprite );
  141. write_byte( 20 );
  142. write_byte( 13 );
  143. write_byte( 12 );
  144. write_byte( 122 );
  145. write_byte( 221 );
  146. write_byte( 255 );
  147. message_end( );
  148.  
  149. entity_set_string(para_ent[id],EV_SZ_classname,"parachute")
  150. entity_set_edict(para_ent[id], EV_ENT_aiment, id)
  151. entity_set_edict(para_ent[id], EV_ENT_owner, id)
  152. entity_set_int(para_ent[id], EV_INT_movetype, MOVETYPE_FOLLOW)
  153. fm_set_rendering( para_ent[id], kRenderFxGlowShell, random_num( 1, 255 ), random_num( 1, 255 ), random_num( 1, 255 ),kRenderNormal, 200 );
  154.  
  155. entity_set_model(para_ent[id], g_szWings[ UseWing[ id ]-1 ][ modelplace ]);
  156.  
  157. entity_set_int(para_ent[id], EV_INT_sequence, 0)
  158. entity_set_int(para_ent[id], EV_INT_gaitsequence, 1)
  159. entity_set_float(para_ent[id], EV_FL_frame, 0.0)
  160. entity_set_float(para_ent[id], EV_FL_fuser1, 0.0)
  161. }
  162. }
  163. if(para_ent[id] > 0)
  164. {
  165. entity_set_int(id, EV_INT_sequence, 3)
  166. entity_set_int(id, EV_INT_gaitsequence, 1)
  167. entity_set_float(id, EV_FL_frame, 1.0)
  168. entity_set_float(id, EV_FL_framerate, 1.0)
  169. set_user_gravity(id, 0.1)
  170. velocity[2] = (velocity[2] + 40.0 < fallspeed) ? velocity[2] + 40.0 : fallspeed
  171. entity_set_vector(id, EV_VEC_velocity, velocity)
  172. if(entity_get_int(para_ent[id],EV_INT_sequence) == 0)
  173. {
  174. frame = entity_get_float(para_ent[id],EV_FL_fuser1) + 1.0
  175. entity_set_float(para_ent[id],EV_FL_fuser1,frame)
  176. entity_set_float(para_ent[id],EV_FL_frame,frame)
  177. if (frame > 100.0)
  178. {
  179. entity_set_float(para_ent[id], EV_FL_animtime, 0.0)
  180. entity_set_float(para_ent[id], EV_FL_framerate, 0.4)
  181. entity_set_int(para_ent[id], EV_INT_sequence, 1)
  182. entity_set_int(para_ent[id], EV_INT_gaitsequence, 1)
  183. entity_set_float(para_ent[id], EV_FL_frame, 0.0)
  184. entity_set_float(para_ent[id], EV_FL_fuser1, 0.0)
  185. }
  186. }
  187. }
  188. }
  189. else if(para_ent[id] > 0)
  190. {
  191. remove_entity(para_ent[id])
  192. set_user_gravity(id, 1.0)
  193. para_ent[id] = 0
  194. }
  195. }
  196. else if((oldbutton & IN_USE) && para_ent[id] > 0 )
  197. {
  198. remove_entity(para_ent[id])
  199. set_user_gravity(id, 1.0)
  200. para_ent[id] = 0
  201. }
  202. }
  203. }
  204.  
  205. public MainMenu(id)
  206. {
  207. new szMenu[ 128 ];
  208.  
  209. formatex( szMenu, charsmax( szMenu ), "\r[\d AMXX \r] \wWings main menu" )
  210.  
  211. new Menu1 = menu_create( szMenu, "MainMenu_sub" );
  212.  
  213.  
  214. formatex( szMenu, charsmax( szMenu ), "\wWings Shop");
  215. menu_additem( Menu1, szMenu, "0" );
  216.  
  217. formatex( szMenu, charsmax( szMenu ), "\wUse Wings");
  218. menu_additem( Menu1, szMenu, "1" );
  219.  
  220. menu_setprop(Menu1, MPROP_EXIT, MEXIT_ALL );
  221. menu_setprop(Menu1, MPROP_EXITNAME, "\wExit" )
  222. menu_setprop(Menu1, MPROP_NUMBER_COLOR, "\r" )
  223. menu_display(id, Menu1, 0);
  224.  
  225. return PLUGIN_HANDLED;
  226.  
  227. }
  228. public MainMenu_sub(id, Menu, item)
  229. {
  230. if( item == MENU_EXIT )
  231. {
  232. menu_destroy(Menu);
  233. return PLUGIN_HANDLED;
  234. }
  235.  
  236. new data[6], iName[64];
  237. new access, callback;
  238. menu_item_getinfo(Menu, item, access, data, 6, iName, 63, callback)
  239.  
  240. new key = str_to_num(data);
  241.  
  242. switch(key)
  243. {
  244. case 0: wing( id )
  245. case 1: usewings( id )
  246. }
  247. menu_destroy(Menu);
  248. return PLUGIN_HANDLED;
  249. }
  250.  
  251. public wing( client )
  252. {
  253. new szItem[ 208 ];
  254.  
  255. formatex( szItem, charsmax( szItem ), "\r[\d AMXX \r] \wWings Shop:");
  256. new menu = menu_create( szItem, "handler" );
  257.  
  258. new iColor[ 33 ]
  259.  
  260. for ( new i = 0; i < sizeof( g_szWings ); i++ )
  261. {
  262. if( Wings[ client ] >= i+1 )
  263. iColor = "\w";
  264.  
  265. else
  266. iColor = "\d";
  267.  
  268. if( i <= Wings[ client ]-1 )
  269. formatex( szItem, charsmax( szItem ), "%s%s \d[ Purchased ]", iColor, g_szWings[ i ][ Name ] );
  270.  
  271. else
  272. formatex( szItem, charsmax( szItem ), "%s%s \r[ %i Cash ]", iColor, g_szWings[ i ][ Name ], g_szWings[ i ][ price ] );
  273.  
  274. menu_additem( menu, szItem );
  275. }
  276.  
  277. menu_display( client, menu );
  278.  
  279. return 1;
  280. }
  281. public handler( client, menu, item )
  282. {
  283. if( item == MENU_EXIT )
  284. {
  285. menu_destroy( menu );
  286. MainMenu( client );
  287. return 1;
  288. }
  289.  
  290. if( item <= Wings[ client ]-1 )
  291. return ColorChat( client, "You have already^4 bought^1 this wings." );
  292.  
  293. if( item > Wings[ client ] )
  294. return ColorChat( client, "You have to buy the previous wings." );
  295.  
  296. if( get_user_cash( client ) >= g_szWings[ item ][ price ] )
  297. {
  298. Wings[ client ]++
  299.  
  300. CmdSave( client );
  301.  
  302. set_user_cash( client, get_user_cash( client ) - g_szWings[ item ][ price ] )
  303.  
  304. ColorChat(0, "Congratulation,^3 %s^1 has purchase ^4%s^1.", GetUserName(client), g_szWings[ item ][ Name ])
  305.  
  306. return 1;
  307. }
  308.  
  309. else
  310. {
  311. ColorChat( client, "You don't have enough cash. Missing: ^4%i ^1cash.", g_szWings[ item ][ price ] - get_user_cash( client ) );
  312. wing( client )
  313.  
  314. return 1;
  315. }
  316.  
  317. return 1;
  318. }
  319.  
  320. public usewings( client )
  321. {
  322. new szItem[ 208 ];
  323.  
  324. formatex( szItem, charsmax( szItem ), "\r[\d AMXX \r] \wUse Wings menu:");
  325. new menu = menu_create( szItem, "handler_use" );
  326.  
  327. for ( new i = 0; i < sizeof( g_szWings ); i++ )
  328. {
  329. formatex( szItem, charsmax( szItem ), "%s%s %s", Wings[ client ] >= i+1 ? "\w" : "\d", g_szWings[ i ][ Name ], UseWing[ client ]-1 == i ? "\d[ USED ]" : "\r[ USE ]");
  330. menu_additem( menu, szItem );
  331. }
  332.  
  333. menu_display( client, menu );
  334.  
  335. return 1;
  336. }
  337. public handler_use( client, menu, item )
  338. {
  339. if( item == MENU_EXIT )
  340. {
  341. menu_destroy( menu );
  342. MainMenu( client );
  343. return 1;
  344. }
  345.  
  346. if( item+1 > Wings[ client ] )
  347. return ColorChat( client, "You have to^4 bought^1 this wings before using." );
  348.  
  349. ColorChat( client, "You have been used:^4 %s^1.", g_szWings[ item ][ Name ] );
  350.  
  351. UseWing[ client ] = item+1;
  352.  
  353. CmdSave( client );
  354.  
  355.  
  356. return 1;
  357. }
  358.  
  359. public client_putinserver( index )
  360. {
  361. CmdLoad( index );
  362. }
  363.  
  364. public client_disconnect( client )
  365. {
  366. CmdSave( client );
  367. }
  368.  
  369. stock GetAuth( id )
  370. {
  371. static szAuth[ 60 ];
  372. get_user_authid( id, szAuth, charsmax( szAuth ) );
  373. if( contain( szAuth, "VALVE_" ) != -1 || contain( szAuth, "ID_LAN" ) != -1 )
  374. get_user_ip( id, szAuth, charsmax( szAuth ), 1 );
  375. return szAuth;
  376. }
  377.  
  378. stock CmdSave(index)
  379. {
  380. if(is_user_bot(index) || is_user_hltv(index))
  381. return;
  382.  
  383. new szKey[ 64 ], szData[ 256 ];
  384. formatex( szKey, charsmax( szKey ), "%s", GetAuth( index ) );
  385. formatex( szData, charsmax( szData ), "%i %i %s",Wings[ index ], UseWing[ index ] ,GetUserName( index ));
  386. fvault_set_data( szVault, szKey, szData );
  387. }
  388.  
  389. stock CmdLoad( index )
  390. {
  391. new szKey[ 64 ], szData[ 256 ];
  392.  
  393. formatex( szKey, charsmax( szKey ), "%s", GetAuth( index ) );
  394.  
  395. formatex( szData, charsmax( szData ), "%i %i %s",Wings[ index ], UseWing[ index ] ,GetUserName( index ));
  396. fvault_get_data( szVault, szKey, szData, 255 );
  397.  
  398. new SetData[ 2 ][ 32 ];
  399. parse( szData, SetData[ 0 ], 31, SetData[ 1 ], 31 );
  400.  
  401. Wings[ index ] = str_to_num( SetData[ 0 ] );
  402. UseWing[ index ] = str_to_num( SetData[ 1 ] );
  403. }
  404.  
  405. stock GetUserName( client )
  406. {
  407. new szName[ 33 ];
  408.  
  409. get_user_name( client, szName, charsmax( szName ) );
  410.  
  411. return szName;
  412. }
  413. stock ColorChat( const index, const string[], any:... )
  414. {
  415. new szMsg[ 191 ], Players[ 32 ], PNum = 1;
  416.  
  417. static iLen; iLen = formatex( szMsg, charsmax( szMsg ), "^4[AMXX]^1 ");
  418.  
  419. vformat( szMsg[ iLen ], charsmax( szMsg ) - iLen, string, 3 );
  420.  
  421. if ( index )
  422. Players[ 0 ] = index;
  423.  
  424. else
  425. get_players( Players, PNum, "ch" );
  426.  
  427. for ( new i; i < PNum; i++ )
  428. {
  429. if( is_user_connected( Players[ i ] ) )
  430. {
  431. message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, Players[ i ] );
  432.  
  433. write_byte( Players[ i ] );
  434.  
  435. write_string( szMsg );
  436.  
  437. message_end( );
  438. }
  439. }
  440.  
  441. return 1;
  442. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement