Русское сообщество по скриптингу

Спидометр

Все вопросы по скриптингу для AMXX, помощь в редактировании плагинов.

Модераторы: Subb98, liFe iS GoOD

Правила форума
1. Запрещено материться и оскорблять других участников форума.
2. Запрещен флуд, оффтоп, дабл постинг во всех разделах форума, кроме раздела "Болтовня".
3. Запрещено взламывать сайт/форум или наносить любой вред проекту.
4. Запрещено рекламировать другие ресурсы.
5. Запрещено создавать темы без информативного названия. Название темы должно отображать ее смысл.

В данном разделе форума разрешено создавать темы, касающие только скриптинга для AMX Mod X.

Правила при создании новой темы:
1. При вставке кода плагина необходимо использовать тег [code=php].
2. Любые изображения должны быть загружены, как вложения к вашему сообщению.
3. При описании проблемы или запросе на помощь в редактировании плагина обязательно выкладывайте исходник sma плагина.

Спидометр

Сообщение Rand0m » 25 окт 2012, 14:22

Почему спидометр не отключается и не обновляет рекорд?
[pawn]
  1. #include <amxmodx>

  2. #include <fakemeta>

  3. #include <nvault>

  4. #include <hamsandwich>

  5. #include <amxmisc>

  6. #include <colorchat>

  7.  

  8. #define PLUGIN "SpeedMeter"

  9. #define VERSION "2.3"

  10. #define AUTHOR "No Swear"

  11.  

  12.  

  13. #define ACCESS_RESET    ADMIN_IMMUNITY

  14. #define MAX_PLAYERS    32

  15.  

  16.  

  17. //Zmienne

  18. new Float:fPlayerMaxSpeed[MAX_PLAYERS+1], Float: fPlayerActualSpeed[MAX_PLAYERS+1], szPlayerName[MAX_PLAYERS+1][32]

  19. new szKeySpeed[32], szKeyName[34]

  20. new bool:NewRecord = false, szMapName[32];

  21. new szChampionName[32], Float:fMapRecord

  22. new nVault

  23. new SyncHud

  24. new bool:g_speed[33]

  25. //new speed[33]

  26. new pcvarEnabled, pcvarUpadte, pcvarTerro

  27. new HudBot//,showspeed

  28.  

  29. public plugin_init()

  30. {

  31. register_plugin(PLUGIN, VERSION, AUTHOR)

  32. //Cvars

  33. pcvarEnabled = register_cvar("sm_enabled", "1")

  34. pcvarUpadte = register_cvar("sm_upadte", "0.1")

  35. pcvarTerro = register_cvar("sm_terro", "1")

  36. //FM Part

  37. register_forward(FM_PlayerPreThink, "Fw_PlayerPreThink")

  38. register_forward(FM_ClientUserInfoChanged, "Fw_ClientUserInfoChanged", 1)

  39. //Others

  40. get_mapname(szMapName, charsmax(szMapName))

  41.  

  42. register_clcmd("say /speed", "speed");

  43. SyncHud = CreateHudSyncObj()

  44. register_clcmd("say /speedrs", "CmdSpeedReset", ACCESS_RESET)

  45. //nVaultPart

  46. formatex(szKeySpeed,63,"%s-Speed",szMapName)

  47. formatex(szKeyName,63,"%s-Name",szMapName)

  48. }

  49. public plugin_cfg()

  50. {

  51. nVault = nvault_open("SpeedRecord")

  52. if (nVault == INVALID_HANDLE)

  53. set_fail_state( "Error opening nVault");

  54.      

  55. fMapRecord = float(nvault_get(nVault,szKeySpeed))

  56. nvault_get(nVault, szKeyName, szChampionName, 31)

  57.    

  58. CreateHudBot()

  59. }

  60. public plugin_end()

  61. {

  62. if (!NewRecord)

  63. return

  64.      

  65. new szNewRecord[32]

  66. float_to_str(fMapRecord, szNewRecord, 31)

  67.    

  68. nvault_set(nVault,szKeySpeed, szNewRecord)

  69. nvault_set(nVault,szKeyName,szChampionName)

  70. nvault_close(nVault)

  71. }

  72.  

  73. public speed(id)

  74. {

  75.    g_speed[id] = g_speed[id] ? false : true

  76.    return PLUGIN_HANDLED

  77. }

  78.  

  79. public client_authorized(id)

  80. {

  81. g_speed[id] = true

  82.  

  83. if (!get_pcvar_num(pcvarEnabled))

  84. return

  85.      

  86. get_user_name(id, szPlayerName[id], 31)

  87. fPlayerMaxSpeed[id] = 0.0

  88. }

  89.  

  90. public Fw_ClientUserInfoChanged(id)

  91. {

  92. get_user_name(id, szPlayerName[id], 31)

  93. }

  94.  

  95. public Fw_PlayerPreThink(id)

  96. {

  97. if (!is_user_alive(id)|| !get_pcvar_num(pcvarEnabled))

  98. return FMRES_IGNORED;

  99.    

  100. if (get_pcvar_num(pcvarTerro) == 0 && get_user_team(id) == 1)

  101. return FMRES_IGNORED;

  102.      

  103. fPlayerActualSpeed[id] = Player_Speed(id)

  104.  

  105. if (fPlayerActualSpeed[id] > fPlayerMaxSpeed[id])

  106. fPlayerMaxSpeed[id] = fPlayerActualSpeed[id]      

  107.    

  108. return FMRES_IGNORED;  

  109. }

  110. public CreateHudBot()

  111. {

  112. HudBot = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString,"info_target"));

  113.    

  114. if(!pev_valid(HudBot))

  115. return;

  116.      

  117. set_pev(HudBot, pev_classname, "HudBot");

  118. set_pev(HudBot, pev_nextthink, get_gametime()+ get_pcvar_float(pcvarUpadte))

  119.    

  120. RegisterHamFromEntity(Ham_Think, HudBot, "Think_HudBot")

  121. }

  122. public Think_HudBot(Bot)

  123. {

  124.  

  125. if (!pev_valid(Bot) || Bot != HudBot)

  126. return HAM_IGNORED;

  127.      

  128. if (get_pcvar_num(pcvarEnabled))

  129. {

  130. new i;                      

  131.  

  132. for (i = 1; i <= get_maxplayers(); i++)

  133. {

  134. if (!is_user_alive(i))

  135. continue

  136.          

  137. set_hudmessage(0, 85, 255, -1.0, 0.8, 0, 0.0, 0.01, 0.0)

  138. if(g_speed[i])  

  139. ShowSyncHudMsg(i, SyncHud,  "Скорость: %.2f^nРекорд: %.2f", fPlayerActualSpeed[i], fPlayerMaxSpeed[i])

  140.          

  141. if (fPlayerMaxSpeed[i] > fMapRecord)

  142. SetNewRecord(fPlayerMaxSpeed[i], szPlayerName[i])

  143. }

  144. }

  145.    

  146. set_pev(Bot, pev_nextthink, get_gametime()+get_pcvar_float(pcvarUpadte))

  147.    

  148. return HAM_IGNORED;

  149. }

  150. stock SetNewRecord(Float:Speed, Name[32])

  151. {

  152.    fMapRecord = Speed

  153.    szChampionName = Name

  154.    NewRecord = true

  155. }

  156. stock Float:Player_Speed(id)

  157. {

  158. new Float:fVect[3]

  159. pev(id, pev_velocity,fVect)

  160. return floatsqroot(fVect[0]*fVect[0]+fVect[1]*fVect[1])

  161. }

  162.  

  163. public CmdSpeedReset(id, level, cid)

  164. {

  165. if(!cmd_access(id,level, cid, 1))

  166. return PLUGIN_HANDLED;

  167.    

  168. new iPlayers[32], iNum

  169. get_players(iPlayers, iNum)

  170. for(new i=0; i<iNum; i++)

  171. fPlayerMaxSpeed[iPlayers[id]] = 0.0

  172.      

  173. SetNewRecord(0.0, "HeHaudeH")

  174. ColorChat(id, GREEN, "^1[^4Surf^1] ^4Вы поставили новый рекорд ^3по скорости!");

  175. return PLUGIN_HANDLED

  176.  

  177. }

  178.  

  179. stock ChatColor(const id, const input[], any:...)

  180. {

  181.         new count = 1, players[32]

  182.         static msg[191]

  183.         vformat(msg, 190, input, 3)

  184.        

  185.         replace_all(msg, 190, "!g", "^4") // Green Color

  186.         replace_all(msg, 190, "!d", "^1") // Default Color

  187.         replace_all(msg, 190, "!team", "^3") // Team Color

  188.        

  189.         if (id) players[0] = id; else get_players(players, count, "ch")

  190.         {

  191.                 for (new i = 0; i < count; i++)

  192.                 {

  193.                         if (is_user_connected(players[i]))

  194.                         {

  195.                                 message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])

  196.                                 write_byte(players[i]);

  197.                                 write_string(msg);

  198.                                 message_end();

  199.                         }

  200.                 }

  201.         }

  202. }
[/pawn]

Аватара пользователя
Rand0m
 
Сообщения: 4
Зарегистрирован: 20 окт 2012, 20:16
Забанен
Благодарил (а): 1 раз.
Поблагодарили: 0 раз.

Вернуться в Скриптинг

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 10