|
- #include <amxmodx>
- #include <fun>
- #define PAST 10
- new position[32][PAST][3] // array to store positions for every player (position[playerID][moment in past][axis])
- // [0] = newest position, [PAST - 1] = oldest position
- new mode_cvar, team_cvar, speed_cvar, glow_cvar;
- // primary function
- public set_alpha()
- {
- new mode = get_pcvar_num(mode_cvar)
- new team = get_pcvar_num(team_cvar)
- new speed = get_pcvar_num(speed_cvar)
- new glow = get_pcvar_num(glow_cvar)
- // if ghosts_mode is not in range, disable plugin
- if (mode < 0 || mode > 2)
- {
- mode = 0
- set_pcvar_num(mode_cvar, 0)
- }
- // if ghosts_team, ghosts_speed or ghosts_glow are not in range, fix them
- if (team < 0 || team > 2)
- {
- team = 0
- set_pcvar_num(team_cvar, 0)
- }
- if (speed < 1)
- {
- speed = 1
- set_pcvar_num(speed_cvar, 1)
- }
- else
- if (speed > 50)
- {
- speed = 50
- set_pcvar_num(speed_cvar, 50)
- }
- if (glow < 0)
- {
- glow = 0
- set_pcvar_num(glow_cvar, 0)
- }
- else
- if (glow > 100)
- {
- glow = 100
- set_pcvar_num(glow_cvar, 100)
- }
- new player[32], number, i
- get_players(player, number)
- // if the plugin is disabled, render the players correctly
- if (mode != 1 && mode != 2)
- {
- for (i = 0; i < number; i++)
- set_user_rendering(player[i], kRenderFxGlowShell, 0, 0, 0, kRenderNormal, 25)
- return PLUGIN_CONTINUE
- }
- new distance, j, x, y, z, player_team
- for (i = 0; i < number; i++)
- {
- // check if player is allowed to be a ghost
- player_team = get_user_team(player[i])
- if (player_team != team)
- {
- // shift all positions one right to make room for the new position
- for (j = PAST - 1; j > 0; j--)
- {
- position[player[i]][j][0] = position[player[i]][j - 1][0]
- position[player[i]][j][1] = position[player[i]][j - 1][1]
- position[player[i]][j][2] = position[player[i]][j - 1][2]
- }
- get_user_origin(player[i], position[player[i]][0]) // get the new position
- // compute distance traveled in the last PAST frames
- distance = 0
- for (j = 1; j < PAST; j++)
- {
- x = position[player[i]][j - 1][0] - position[player[i]][j][0]
- y = position[player[i]][j - 1][1] - position[player[i]][j][1]
- z = position[player[i]][j - 1][2] - position[player[i]][j][2]
- distance += sqroot(x * x + y * y + z * z)
- }
- distance /= (PAST - 1) // make average distance; PAST points => PAST - 1 lines
- // make the player transparent or glow
- if (distance > speed)
- set_user_rendering(player[i], kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, 0) // moving very fast :)
- else
- if (mode == 2 && distance < speed * glow / 100) // if condition is true then glow
- if (player_team == 1)
- set_user_rendering(player[i], kRenderFxGlowShell, 0, 191, 255, kRenderNormal, 5) // CT
- else
- set_user_rendering(player[i], kRenderFxGlowShell, 255, 255, 0, kRenderNormal, 5) // T
- else // partially visible (or totaly if not moving)
- set_user_rendering(player[i], kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, 255 - 255 * distance / speed)
- }
- else
- {
- set_user_rendering(player[i], kRenderFxGlowShell, 0, 0, 0, kRenderNormal, 25) // normal rendering
- }
- }
- return PLUGIN_CONTINUE
- }
- // when a new round begins, set all the positions of the players to their original one (or players will be invisible when round begins)
- public new_round(id)
- {
- new mode = get_pcvar_num(mode_cvar)
- if (mode == 1 || mode == 2)
- {
- get_user_origin(id, position[id][0])
- new i
- for (i = 1; i < PAST; i++)
- {
- position[id][i][0] = position[id][0][0]
- position[id][i][1] = position[id][0][1]
- position[id][i][2] = position[id][0][2]
- }
- }
- return PLUGIN_CONTINUE
- }
- // not interesting
- public plugin_init()
- {
- register_plugin("Ghosts", "0.3a", "Spike7d8")
- register_event("ResetHUD", "new_round", "b")
- set_task(0.1, "set_alpha", 0, "", 0, "b")
- mode_cvar = register_cvar("ghosts_mode", "2")
- team_cvar = register_cvar("ghosts_team", "0")
- speed_cvar = register_cvar("ghosts_speed", "25000")
- glow_cvar = register_cvar("ghosts_glow", "25000")
- }
复制代码 |
|