hlmod.hu
https://hlmod.hu/

Új menüpont
https://hlmod.hu/viewtopic.php?f=10&t=6510
Oldal: 1 / 1

Szerző:  Bence98007 [2012.11.02. 21:29 ]
Hozzászólás témája:  Új menüpont

Hi!

Van egy INC-m:
SMA Forráskód: [ Mindet kijelol ]
  1. #if defined _furien_shop
  2. #endinput
  3. #endif
  4. #define _furien_shop
  5.  
  6. #pragma reqlib furien_shop
  7.  
  8. #include <cstrike>
  9.  
  10. enum _:ShopReturns {
  11. ShopBought,
  12. ShopTeamNotAvail,
  13. ShopAlreadyHaveOne,
  14. ShopCantCarryAnymore,
  15. ShopNotEnoughMoney,
  16. ShopCannotBuyThis,
  17. ShopShowMenuAgain,
  18. ShopCloseMenu
  19. }
  20.  
  21. native furien_register_item(szFurienName[32], iFurienCost=0, szAntiName[32], iAntiCost=0, szCallBack[32] = "furien_buy_item", iExtra = 0);
  22.  
  23. stock furien_try_buy(id, iCost)
  24. {
  25. new iNewMoney = cs_get_user_money(id) - iCost;
  26.  
  27. if( iNewMoney < 0 )
  28. {
  29. return 0;
  30. }
  31.  
  32. cs_set_user_money(id, iNewMoney, 1);
  33. return 1;
  34. }
  35.  


és ez maga a bolt(shop):
SMA Forráskód: [ Mindet kijelol ]
  1. /* Formatright © 2010, ConnorMcLeod
  2.  
  3. Furien Shop is free software;
  4. you can redistribute it and/or modify it under the terms of the
  5. GNU General Public License as published by the Free Software Foundation.
  6.  
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11.  
  12. You should have received a copy of the GNU General Public License
  13. along with Furien Shop; if not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17.  
  18. #include <amxmodx>
  19. #include <cstrike>
  20.  
  21. #include "furien.inc"
  22. #include "furien_shop.inc"
  23.  
  24. new const szPickAmmoSound[] = "items/9mmclip1.wav"
  25.  
  26. enum _:ItemDatas
  27. {
  28. m_szItemName[32],
  29. m_iItemCost,
  30. m_iItemForwardIndex,
  31. m_iItemExtraArg
  32. }
  33.  
  34. enum ( <<= 1 )
  35. {
  36. ShouldBeInBuyZone = 1,
  37. ShouldBeInBuyTime
  38. }
  39.  
  40. #define HUD_PRINTCENTER 4
  41.  
  42. new g_iBlinkAcct, g_iTextMsg
  43.  
  44. new g_iBuyType, g_pCvarBuyTime
  45.  
  46. new Array:g_aItems[2]
  47. new g_iMenuId[2] = {-1, -1}
  48.  
  49. new bool:g_bFreezeTime = true, bool:g_bBuyTime = true
  50. new bool:g_bSwitchTime
  51. new Float:g_flRoundStartGameTime
  52.  
  53. public plugin_init()
  54. {
  55. register_plugin("Furien Shop", FURIEN_VERSION, "ConnorMcLeod")
  56.  
  57. register_dictionary("common.txt")
  58.  
  59. new pCvar = register_cvar("furien_shop_version", FURIEN_VERSION, FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY)
  60. set_pcvar_string(pCvar, FURIEN_VERSION)
  61.  
  62. ReadCfgFile()
  63.  
  64. if( g_iBuyType & ShouldBeInBuyZone )
  65. {
  66. register_event("StatusIcon", "Event_StatusIcon_OutOfBuyZone", "b", "1=0", "2=buyzone")
  67. }
  68.  
  69. register_event("HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0")
  70. register_logevent("LogEvent_Round_Start", 2, "1=Round_Start")
  71.  
  72. register_clcmd("shop", "ClientCommand_Shop")
  73. register_clcmd("say shop", "ClientCommand_Shop")
  74. register_clcmd("say_team shop", "ClientCommand_Shop")
  75. register_clcmd("buy", "ClientCommand_Shop")
  76.  
  77. g_iBlinkAcct = get_user_msgid("BlinkAcct")
  78. g_iTextMsg = get_user_msgid("TextMsg")
  79. g_pCvarBuyTime = get_cvar_pointer("mp_buytime")
  80. }
  81.  
  82. ReadCfgFile()
  83. {
  84. new szConfigFile[128]
  85. get_localinfo("amxx_configsdir", szConfigFile, charsmax(szConfigFile))
  86. format(szConfigFile, charsmax(szConfigFile), "%s/furien/shop.ini", szConfigFile);
  87.  
  88. new fp = fopen(szConfigFile, "rt")
  89. if( !fp )
  90. {
  91. return
  92. }
  93.  
  94. new szDatas[32], szKey[16], szValue[16]
  95. while( !feof(fp) )
  96. {
  97. fgets(fp, szDatas, charsmax(szDatas))
  98. trim(szDatas)
  99. if(!szDatas[0] || szDatas[0] == ';' || szDatas[0] == '#' || (szDatas[0] == '/' && szDatas[1] == '/'))
  100. {
  101. continue
  102. }
  103.  
  104. parse(szDatas, szKey, charsmax(szKey), szValue, charsmax(szValue))
  105.  
  106. switch( szKey[0] )
  107. {
  108. case 'B':
  109. {
  110. if( equal(szKey, "BUY_TYPE" ) )
  111. {
  112. g_iBuyType = str_to_num(szValue)
  113. }
  114. }
  115. }
  116. }
  117. fclose( fp )
  118. }
  119.  
  120. public plugin_precache()
  121. {
  122. precache_sound(szPickAmmoSound)
  123. }
  124.  
  125. public Event_HLTV_New_Round()
  126. {
  127. g_bFreezeTime = true
  128. g_bBuyTime = true
  129. g_bSwitchTime = false
  130. }
  131.  
  132. public LogEvent_Round_Start()
  133. {
  134. g_bFreezeTime = false
  135. g_bBuyTime = true
  136. g_bSwitchTime = false
  137. g_flRoundStartGameTime = get_gametime()
  138. }
  139.  
  140. bool:bIsBuyTime( id = 0 )
  141. {
  142. new Float:flBuyTime
  143. if( !g_bFreezeTime
  144. && ( !g_bBuyTime || !(g_bBuyTime = get_gametime() < g_flRoundStartGameTime + (flBuyTime = get_buytime_value() * 60.0)) ) )
  145. {
  146. if( id )
  147. {
  148. new szBuyTime[3]
  149. float_to_str(flBuyTime, szBuyTime, charsmax(szBuyTime))
  150. Util_ClientPrint(id, HUD_PRINTCENTER, "#Cant_buy", szBuyTime)
  151. }
  152. return false
  153. }
  154. return true
  155. }
  156.  
  157. Float:get_buytime_value()
  158. {
  159. new Float:flBuyTime = get_pcvar_float(g_pCvarBuyTime)
  160. if( flBuyTime < 0.25 )
  161. {
  162. set_pcvar_float(g_pCvarBuyTime, 0.25)
  163. flBuyTime = 0.25
  164. }
  165. if( flBuyTime > 1.5 )
  166. {
  167. set_pcvar_float(g_pCvarBuyTime, 1.5)
  168. flBuyTime = 1.5
  169. }
  170. return flBuyTime
  171. }
  172.  
  173. public furien_team_change()
  174. {
  175. g_bSwitchTime = true
  176.  
  177. new iPlayers[32], iNum
  178. get_players(iPlayers, iNum, "a")
  179. for(new i; i<iNum; i++)
  180. {
  181. CheckMenuClose(iPlayers[i])
  182. }
  183. }
  184.  
  185. public Event_StatusIcon_OutOfBuyZone( id )
  186. {
  187. CheckMenuClose(id)
  188. }
  189.  
  190. CheckMenuClose(id)
  191. {
  192. new iCrap, iMenuId
  193. player_menu_info(id, iCrap, iMenuId)
  194. if( iMenuId > -1 && (iMenuId == g_iMenuId[Furien] || iMenuId == g_iMenuId[AntiFurien]) )
  195. {
  196. menu_cancel(id)
  197. }
  198. }
  199.  
  200. public plugin_natives()
  201. {
  202. register_library("furien_shop")
  203. register_native("furien_register_item", "fr_register_item")
  204. }
  205.  
  206. public fr_register_item(iPlugin)
  207. {
  208. new mDatas[ItemDatas], szCallBack[32]
  209.  
  210. get_string(5, szCallBack, charsmax(szCallBack))
  211. mDatas[m_iItemForwardIndex] = CreateOneForward(iPlugin, szCallBack, FP_CELL, FP_CELL)
  212.  
  213. mDatas[m_iItemExtraArg] = get_param(6)
  214.  
  215. if( (mDatas[m_iItemCost] = get_param(2)) > 0 )
  216. {
  217. get_string(1, mDatas[m_szItemName], charsmax(mDatas[m_szItemName]))
  218. AddItemToMenu( Furien , mDatas )
  219. }
  220.  
  221. if( (mDatas[m_iItemCost] = get_param(4)) > 0 )
  222. {
  223. get_string(3, mDatas[m_szItemName], charsmax(mDatas[m_szItemName]))
  224. AddItemToMenu( AntiFurien , mDatas )
  225. }
  226.  
  227. return mDatas[m_iItemForwardIndex]
  228. }
  229.  
  230. AddItemToMenu( iTeam , mDatas[ItemDatas] )
  231. {
  232. new Array:iArray = g_aItems[iTeam]
  233. if( iArray == Invalid_Array )
  234. {
  235. iArray = g_aItems[iTeam] = ArrayCreate(ItemDatas)
  236. }
  237.  
  238. new iMenu = g_iMenuId[iTeam]
  239. if( iMenu == -1 )
  240. {
  241. new szMenuNames[][] = {"Furien Shop", "AntiFurien Shop"}
  242. new szHandlers[][] = {"FurienMenuHandler", "AntiMenuHandler"}
  243. iMenu = g_iMenuId[iTeam] = menu_create(szMenuNames[iTeam], szHandlers[iTeam])
  244. menu_setprop(iMenu, MPROP_NUMBER_COLOR, "\y")
  245. }
  246.  
  247. ArrayPushArray(iArray, mDatas)
  248. new szItemInformation[64]
  249. formatex(szItemInformation, charsmax(szItemInformation), "%s\R\y$%d", mDatas[m_szItemName], mDatas[m_iItemCost])
  250. menu_additem(iMenu, szItemInformation)
  251. }
  252.  
  253. public ClientCommand_Shop( id )
  254. {
  255. if( !g_bSwitchTime && is_user_alive(id) )
  256. {
  257. if( !bCanBuy( id ) )
  258. {
  259. return PLUGIN_HANDLED_MAIN
  260. }
  261.  
  262. ShowShopMenu(id)
  263. return PLUGIN_CONTINUE
  264. }
  265.  
  266. return PLUGIN_HANDLED_MAIN
  267. }
  268.  
  269. bCanBuy( id )
  270. {
  271. if( ( g_iBuyType & ShouldBeInBuyZone && !cs_get_user_buyzone(id) )
  272. || ( g_iBuyType & ShouldBeInBuyTime && !bIsBuyTime(id) ) )
  273. {
  274. return false
  275. }
  276.  
  277. return true
  278. }
  279.  
  280. ShowShopMenu(id)
  281. {
  282. new iTeam = furien_get_user_team(id)
  283. menu_display(id, g_iMenuId[iTeam])
  284. }
  285.  
  286. public FurienMenuHandler(id, iMenu, iItem)
  287. {
  288. if( iItem > MENU_MORE && is_user_alive(id) && furien_get_user_team(id) == Furien && bCanBuy( id ) )
  289. {
  290. new mDatas[ItemDatas]
  291. ArrayGetArray(Array:g_aItems[Furien], iItem, mDatas)
  292. Function(mDatas, id)
  293. }
  294. }
  295.  
  296. public AntiMenuHandler(id, iMenu, iItem)
  297. {
  298. if( iItem > MENU_MORE && is_user_alive(id) && furien_get_user_team(id) == AntiFurien && bCanBuy( id ) )
  299. {
  300. new mDatas[ItemDatas]
  301. ArrayGetArray(Array:g_aItems[AntiFurien], iItem, mDatas)
  302. Function(mDatas, id)
  303. }
  304. }
  305.  
  306. Function(mDatas[ItemDatas], id)
  307. {
  308. new iRet
  309. ExecuteForward(mDatas[m_iItemForwardIndex], iRet, id, mDatas[m_iItemExtraArg])
  310. switch( iRet )
  311. {
  312. case ShopBought:
  313. {
  314. emit_sound(id, CHAN_ITEM, szPickAmmoSound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  315. return 1
  316. }
  317. case ShopTeamNotAvail:
  318. {
  319. Util_ClientPrint
  320. (
  321. id,
  322. HUD_PRINTCENTER,
  323. "#Alias_Not_Avail",
  324. mDatas[ m_szItemName ]
  325. )
  326. }
  327. case ShopNotEnoughMoney:
  328. {
  329. client_print(id, print_center, "Ehez nincs eleg penzed!")
  330.  
  331. message_begin(MSG_ONE_UNRELIABLE, g_iBlinkAcct, .player=id)
  332. {
  333. write_byte(2)
  334. }
  335. message_end()
  336. }
  337. case ShopAlreadyHaveOne:
  338. {
  339. client_print(id, print_center, "Mar van ilyened!")
  340. }
  341. case ShopCantCarryAnymore:
  342. {
  343. client_print(id, print_center, "Ebbol nem tudsz tobbet vasarolni!")
  344. }
  345. case ShopCannotBuyThis:
  346. {
  347. client_print(id, print_center, "Ezt nem tudod megvenni!")
  348. }
  349. case ShopCloseMenu:
  350. {
  351. return 1
  352. }
  353. }
  354. return 0
  355. }
  356.  
  357. // Only submessage1 is used but fully implemented for example.
  358. // Based on HLSDK ClientPrint and UTIL_ClientPrintAll from util.cpp
  359. Util_ClientPrint(id, iMsgDest, szMessage[], szSubMessage1[] = "", szSubMessage2[] = "", szSubMessage3[] = "", szSubMessage4[] = "")
  360. {
  361. message_begin(id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, g_iTextMsg, .player=id)
  362. {
  363. write_byte(iMsgDest)
  364. write_string(szMessage)
  365. if( szSubMessage1[0] )
  366. {
  367. write_string(szSubMessage1)
  368. }
  369. if( szSubMessage2[0] )
  370. {
  371. write_string(szSubMessage2)
  372. }
  373. if( szSubMessage3[0] )
  374. {
  375. write_string(szSubMessage3)
  376. }
  377. if( szSubMessage4[0] )
  378. {
  379. write_string(szSubMessage4)
  380. }
  381. }
  382. message_end()
  383. }
  384.  
  385. ////// client_print //////
  386. // #Cstrike_TitlesTXT_Cannot_Buy_This "You cannot buy this item!"
  387. // #Cstrike_TitlesTXT_Cannot_Carry_Anymore "You cannot carry anymore!"
  388. // #Cstrike_Already_Own_Weapon "You already own that weapon."
  389. // #Cstrike_TitlesTXT_Weapon_Not_Available "This weapon is not available to you!"
  390. // #Cstrike_TitlesTXT_Not_Enough_Money "You have insufficient funds!"
  391. // #Cstrike_TitlesTXT_CT_cant_buy "CTs aren't allowed to buy"
  392. // #Cstrike_TitlesTXT_Terrorist_cant_buy "Terrorists aren't allowed to buy anything on this map!"
  393. // #Cstrike_TitlesTXT_VIP_cant_buy "You are the VIP. You can't buy anything!"
  394.  
  395. ////// Util_ClientPrint ///////
  396. // #Cstrike_TitlesTXT_Alias_Not_Avail + szWeapon "The \"%s1\"is not available for your team to buy."
  397. // #Cstrike_TitlesTXT_Cant_buy + szSeconds "%s1 seconds have passed. You can't buy anything now!"
  398.  



Az lenne a kérdésem, hogy hogyan tudok ebbe a shopba új menüpontot csinálni? Nem jöttem rá sehogy....külön plugin kell? vagy csak ebbe kell átírogatni?

Válaszokat köszönöm előre is!

Szerző:  Vinnice [2012.11.03. 12:58 ]
Hozzászólás témája:  Re: Új menüpont

SMA Forráskód: [ Mindet kijelol ]
  1. public plugin_natives()
  2. {
  3. register_library("furien_shop")
  4. register_native("furien_register_item", "fr_register_item")
  5. }
  6.  
  7. public fr_register_item(iPlugin)
  8. {
  9. new mDatas[ItemDatas], szCallBack[32]
  10.  
  11. get_string(5, szCallBack, charsmax(szCallBack))
  12. mDatas[m_iItemForwardIndex] = CreateOneForward(iPlugin, szCallBack, FP_CELL, FP_CELL)
  13.  
  14. mDatas[m_iItemExtraArg] = get_param(6)
  15.  
  16. if( (mDatas[m_iItemCost] = get_param(2)) > 0 )
  17. {
  18. get_string(1, mDatas[m_szItemName], charsmax(mDatas[m_szItemName]))
  19. AddItemToMenu( Furien , mDatas )
  20. }
  21.  
  22. if( (mDatas[m_iItemCost] = get_param(4)) > 0 )
  23. {
  24. get_string(3, mDatas[m_szItemName], charsmax(mDatas[m_szItemName]))
  25. AddItemToMenu( AntiFurien , mDatas )
  26. }
  27.  
  28. return mDatas[m_iItemForwardIndex]
  29. }
  30.  
  31. AddItemToMenu( iTeam , mDatas[ItemDatas] )
  32. {
  33. new Array:iArray = g_aItems[iTeam]
  34. if( iArray == Invalid_Array )
  35. {
  36. iArray = g_aItems[iTeam] = ArrayCreate(ItemDatas)
  37. }
  38.  
  39. new iMenu = g_iMenuId[iTeam]
  40. if( iMenu == -1 )
  41. {
  42. new szMenuNames[][] = {"Furien Shop", "AntiFurien Shop"}
  43. new szHandlers[][] = {"FurienMenuHandler", "AntiMenuHandler"}
  44. iMenu = g_iMenuId[iTeam] = menu_create(szMenuNames[iTeam], szHandlers[iTeam])
  45. menu_setprop(iMenu, MPROP_NUMBER_COLOR, "\y")
  46. }
  47.  
  48. ArrayPushArray(iArray, mDatas)
  49. new szItemInformation[64]
  50. formatex(szItemInformation, charsmax(szItemInformation), "%s\R\y$%d", mDatas[m_szItemName], mDatas[m_iItemCost])
  51. menu_additem(iMenu, szItemInformation)
  52. }
  53.  

Sztem valahol ebben van (furien_register_item, tehát vagy beleirod vagy külön plugint írsz hozzá.)

Szerző:  Bence98007 [2012.11.03. 13:40 ]
Hozzászólás témája:  Re: Új menüpont

Jah erre gondoltam én is :S

Szerző:  Metal [2012.11.03. 13:56 ]
Hozzászólás témája:  Re: Új menüpont

Köszönjük, hogy erre gondolt... akkor minek teszed ki???

Bence98007 írta:
Jah erre gondoltam én is :S

Szerző:  Bence98007 [2012.11.03. 14:04 ]
Hozzászólás témája:  Re: Új menüpont

azért hogy kérjek egy példakódot hátha ír valaki...

Szerző:  DeteCT0R [2012.11.03. 14:50 ]
Hozzászólás témája:  Re: Új menüpont

Furien shop asszem inibol olvassa a cuccokat.

Szerző:  Bence98007 [2012.11.03. 15:06 ]
Hozzászólás témája:  Re: Új menüpont

de az init is be kell olvasnia...

Szerző:  DeteCT0R [2012.11.03. 15:13 ]
Hozzászólás témája:  Re: Új menüpont

Bence98007 írta:
de az init is be kell olvasnia...

Beis olvassa:)
Kód:
new szConfigFile[128]
   get_localinfo("amxx_configsdir", szConfigFile, charsmax(szConfigFile))
   format(szConfigFile, charsmax(szConfigFile), "%s/furien/shop.ini", szConfigFile);

Szerző:  Bence98007 [2012.11.03. 17:07 ]
Hozzászólás témája:  Re: Új menüpont

Kép

Oldal: 1 / 1 Minden időpont UTC+02:00 időzóna szerinti
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/