[pawn]
- #include <amxmodx>
- #include <fakemeta>
- #include <nvault>
- #include <hamsandwich>
- #include <amxmisc>
- #include <colorchat>
- #define PLUGIN "SpeedMeter"
- #define VERSION "2.3"
- #define AUTHOR "No Swear"
- #define ACCESS_RESET ADMIN_IMMUNITY
- #define MAX_PLAYERS 32
- //Zmienne
- new Float:fPlayerMaxSpeed[MAX_PLAYERS+1], Float: fPlayerActualSpeed[MAX_PLAYERS+1], szPlayerName[MAX_PLAYERS+1][32]
- new szKeySpeed[32], szKeyName[34]
- new bool:NewRecord = false, szMapName[32];
- new szChampionName[32], Float:fMapRecord
- new nVault
- new SyncHud
- new bool:g_speed[33]
- //new speed[33]
- new pcvarEnabled, pcvarUpadte, pcvarTerro
- new HudBot//,showspeed
- public plugin_init()
- {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- //Cvars
- pcvarEnabled = register_cvar("sm_enabled", "1")
- pcvarUpadte = register_cvar("sm_upadte", "0.1")
- pcvarTerro = register_cvar("sm_terro", "1")
- //FM Part
- register_forward(FM_PlayerPreThink, "Fw_PlayerPreThink")
- register_forward(FM_ClientUserInfoChanged, "Fw_ClientUserInfoChanged", 1)
- //Others
- get_mapname(szMapName, charsmax(szMapName))
- register_clcmd("say /speed", "speed");
- SyncHud = CreateHudSyncObj()
- register_clcmd("say /speedrs", "CmdSpeedReset", ACCESS_RESET)
- //nVaultPart
- formatex(szKeySpeed,63,"%s-Speed",szMapName)
- formatex(szKeyName,63,"%s-Name",szMapName)
- }
- public plugin_cfg()
- {
- nVault = nvault_open("SpeedRecord")
- if (nVault == INVALID_HANDLE)
- set_fail_state( "Error opening nVault");
- fMapRecord = float(nvault_get(nVault,szKeySpeed))
- nvault_get(nVault, szKeyName, szChampionName, 31)
- CreateHudBot()
- }
- public plugin_end()
- {
- if (!NewRecord)
- return
- new szNewRecord[32]
- float_to_str(fMapRecord, szNewRecord, 31)
- nvault_set(nVault,szKeySpeed, szNewRecord)
- nvault_set(nVault,szKeyName,szChampionName)
- nvault_close(nVault)
- }
- public speed(id)
- {
- g_speed[id] = g_speed[id] ? false : true
- return PLUGIN_HANDLED
- }
- public client_authorized(id)
- {
- g_speed[id] = true
- if (!get_pcvar_num(pcvarEnabled))
- return
- get_user_name(id, szPlayerName[id], 31)
- fPlayerMaxSpeed[id] = 0.0
- }
- public Fw_ClientUserInfoChanged(id)
- {
- get_user_name(id, szPlayerName[id], 31)
- }
- public Fw_PlayerPreThink(id)
- {
- if (!is_user_alive(id)|| !get_pcvar_num(pcvarEnabled))
- return FMRES_IGNORED;
- if (get_pcvar_num(pcvarTerro) == 0 && get_user_team(id) == 1)
- return FMRES_IGNORED;
- fPlayerActualSpeed[id] = Player_Speed(id)
- if (fPlayerActualSpeed[id] > fPlayerMaxSpeed[id])
- fPlayerMaxSpeed[id] = fPlayerActualSpeed[id]
- return FMRES_IGNORED;
- }
- public CreateHudBot()
- {
- HudBot = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString,"info_target"));
- if(!pev_valid(HudBot))
- return;
- set_pev(HudBot, pev_classname, "HudBot");
- set_pev(HudBot, pev_nextthink, get_gametime()+ get_pcvar_float(pcvarUpadte))
- RegisterHamFromEntity(Ham_Think, HudBot, "Think_HudBot")
- }
- public Think_HudBot(Bot)
- {
- if (!pev_valid(Bot) || Bot != HudBot)
- return HAM_IGNORED;
- if (get_pcvar_num(pcvarEnabled))
- {
- new i;
- for (i = 1; i <= get_maxplayers(); i++)
- {
- if (!is_user_alive(i))
- continue
- set_hudmessage(0, 85, 255, -1.0, 0.8, 0, 0.0, 0.01, 0.0)
- if(g_speed[i])
- ShowSyncHudMsg(i, SyncHud, "Скорость: %.2f^nРекорд: %.2f", fPlayerActualSpeed[i], fPlayerMaxSpeed[i])
- if (fPlayerMaxSpeed[i] > fMapRecord)
- SetNewRecord(fPlayerMaxSpeed[i], szPlayerName[i])
- }
- }
- set_pev(Bot, pev_nextthink, get_gametime()+get_pcvar_float(pcvarUpadte))
- return HAM_IGNORED;
- }
- stock SetNewRecord(Float:Speed, Name[32])
- {
- fMapRecord = Speed
- szChampionName = Name
- NewRecord = true
- }
- stock Float:Player_Speed(id)
- {
- new Float:fVect[3]
- pev(id, pev_velocity,fVect)
- return floatsqroot(fVect[0]*fVect[0]+fVect[1]*fVect[1])
- }
- public CmdSpeedReset(id, level, cid)
- {
- if(!cmd_access(id,level, cid, 1))
- return PLUGIN_HANDLED;
- new iPlayers[32], iNum
- get_players(iPlayers, iNum)
- for(new i=0; i<iNum; i++)
- fPlayerMaxSpeed[iPlayers[id]] = 0.0
- SetNewRecord(0.0, "HeHaudeH")
- ColorChat(id, GREEN, "^1[^4Surf^1] ^4Вы поставили новый рекорд ^3по скорости!");
- return PLUGIN_HANDLED
- }
- stock ChatColor(const id, const input[], any:...)
- {
- new count = 1, players[32]
- static msg[191]
- vformat(msg, 190, input, 3)
- replace_all(msg, 190, "!g", "^4") // Green Color
- replace_all(msg, 190, "!d", "^1") // Default Color
- replace_all(msg, 190, "!team", "^3") // Team Color
- if (id) players[0] = id; else get_players(players, count, "ch")
- {
- for (new i = 0; i < count; i++)
- {
- if (is_user_connected(players[i]))
- {
- message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
- write_byte(players[i]);
- write_string(msg);
- message_end();
- }
- }
- }
- }