Kod:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <cstrike>
#define PLUGIN "xSurfing"
#define VERSION "1.0"
#define AUTHOR "Alka"
enum {
TIMER_INACTIVE = 0,
TIMER_ACTIVE = 1
}
new
SurfMenu,
SurfMenuCallback;
new const FinishButtonModel[] = "models/w_c4.mdl";
new const FinishButtonClassname[] = "surf_finish_button";
new const FinishSound[] = "buttons/bell1.wav";
new const PluginTag[] = "xSurfing";
new
Float:NextCheck[33],
Float:FloatTimer[2][33],
TimerStatus[33],
bool:FinishedMap[33],
bool:Restart_Attempt[33];
new
Float:BestTime = 99999.0,
BestSurfer;
new
MapRecName[32],
Float:MapRecTime = 99999.0;
stock const Weapons[][] = {
"", "P228", "", "Scout", "Hegrenade",
"XM1014", "C4", "Mac10", "Aug", "Smokegrenade",
"Elite", "Fiveseven", "Ump45", "Sg550", "Galil",
"Famas", "Usp", "Glock18", "Awp", "Mp5",
"M249", "M3", "M4a1", "Tmp", "G3sg1",
"Flashbang", "Deagle", "Sg552", "Ak47", "Knife",
"P90"
}
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
register_forward(FM_Think, "Fwd_Think");
register_forward(FM_PlayerPostThink, "Fwd_PlayerPostThink");
register_forward(FM_StartFrame, "Fwd_StartFrame");
register_event("ResetHUD", "EventPlayerSpawned", "be");
register_clcmd("fullupdate", "BlockCmd");
register_event("TextMsg", "RestartAttempt", "a", "2=#Game_will_restart_in");
register_event("DeathMsg", "EventPlayerDeath", "a")
register_clcmd("say /surfmenu", "ShowSurfMenu");
register_clcmd("say /restart", "RestartCourse");
register_clcmd("say /respawn", "RestartCourse");
register_clcmd("say /maprecord", "ShowMapRecord");
register_clcmd("say /maprec", "ShowMapRecord");
register_clcmd("drop", "BlockCmd");
register_clcmd("chooseteam", "BlockCmd");
set_msg_block(get_user_msgid("WeapPickup"), BLOCK_SET);
set_task(3.0, "LoadMapRecord");
}
public plugin_precache()
{
SurfMenu = menu_create("\yxSurfing Menu :", "MenuHandler");
SurfMenuCallback = menu_makecallback("MenuCallBack");
menu_additem(SurfMenu, "\wAdd finish button", "1", 0, SurfMenuCallback);
menu_additem(SurfMenu, "\wSave buttons origin", "2", 0, SurfMenuCallback);
menu_addblank(SurfMenu, 0);
menu_additem(SurfMenu, "\wNoclip toggle", "3", 0, SurfMenuCallback);
menu_additem(SurfMenu, "\wGodmode toggle", "4", 0, SurfMenuCallback);
menu_addblank(SurfMenu, 0);
menu_addblank(SurfMenu, 0);
precache_model(FinishButtonModel);
precache_sound(FinishSound);
SetNoBuy();
}
public SetNoBuy()
{
new Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_map_parameters"));
if(pev_valid(Ent))
{
fm_SetKeyValue(Ent, "buying", "3");
dllfunc(DLLFunc_Spawn, Ent);
}
}
public plugin_cfg()
{
new ConfigsDir[64], File[128], MapName[32];
get_configsdir(ConfigsDir, sizeof ConfigsDir - 1);
get_mapname(MapName, sizeof MapName - 1);
formatex(File, sizeof File - 1, "%s/surf_buttons/%s.cfg", ConfigsDir, MapName);
if(!file_exists(File))
{
server_print("[%s] Error : File with buttons for map %s was not founded!", PluginTag, MapName);
return 1;
}
new FileOrigin[3][32], Line = 0, Lenght = 0, Buffer[128];
new Float:Origin[3];
while(read_file(File, Line++, Buffer, sizeof Buffer - 1, Lenght))
{
if((Buffer[0]==';') || !Lenght)
continue;
parse(Buffer, FileOrigin[0], sizeof FileOrigin[] - 1, FileOrigin[1], sizeof FileOrigin[] - 1, FileOrigin[2], sizeof FileOrigin[] - 1);
Origin[0] = str_to_float(FileOrigin[0]);
Origin[1] = str_to_float(FileOrigin[1]);
Origin[2] = str_to_float(FileOrigin[2]);
CreateEntButton(Origin);
}
return 1;
}
public plugin_end()
{
new DataDir[64], File[64], MapName[32];
new MapsDir[64];
new Buffer[128];
get_datadir(DataDir, sizeof DataDir - 1);
get_mapname(MapName, sizeof MapName - 1);
formatex(File, sizeof File - 1, "%s/surf_maps_record/%s.ini", DataDir, MapName);
formatex(MapsDir, sizeof MapsDir - 1, "%s/surf_maps_record/", DataDir);
formatex(Buffer, sizeof Buffer - 1, "%s ;%f", MapRecName, MapRecTime);
if(!dir_exists(MapsDir))
mkdir(MapsDir);
write_file(File, Buffer, 0);
return 1;
}
public LoadMapRecord()
{
new DataDir[64], File[64], MapName[32];
get_datadir(DataDir, sizeof DataDir - 1);
get_mapname(MapName, sizeof MapName - 1);
formatex(File, sizeof File - 1, "%s/surf_maps_record/%s.ini", DataDir, MapName);
if(!file_exists(File))
{
server_print("[%s] Error : File with map record for %s was not founded!", PluginTag, MapName);
return 1;
}
new Name[32], Time[32];
new Line = 0, Lenght = 0, Buffer[128];
while(read_file(File, Line++, Buffer, sizeof Buffer - 1, Lenght))
{
if(!Lenght)
continue;
strtok(Buffer, Name, sizeof Name - 1, Time, sizeof Time - 1, ';');
copy(MapRecName, sizeof MapRecName - 1, Name);
MapRecTime = str_to_float(Time);
break;
}
return 1;
}
public ShowSurfMenu(id)
menu_display(id, SurfMenu, 0);
public MenuCallBack(id, menu, item)
return (get_user_flags(id) & ADMIN_IMMUNITY) ? ITEM_ENABLED : ITEM_DISABLED;
public MenuHandler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_cancel(id);
return 1;
}
new _Data[2];
new _Access, _Callback;
menu_item_getinfo(menu, item, _Access, _Data, sizeof _Data - 1, _, _, _Callback);
new Key = str_to_num(_Data);
switch(Key)
{
case 1:
{
static Float:Velocity[3];
pev(id, pev_velocity, Velocity);
if(vector_length(Velocity) > 1.0)
{
client_print(id, print_chat, "[%s]You can't make a finish button while moving!", PluginTag);
menu_display(id, menu, 0);
return 1;
}
static Float:Origin[3];
pev(id, pev_origin, Origin);
CreateEntButton(Origin);
client_print(id, print_chat, "[%s]Successfuly created an finish button.", PluginTag);
}
case 2:
{
new ConfigsDir[64], File[128], MapName[32];
new ButtonsDir[64];
get_configsdir(ConfigsDir, sizeof ConfigsDir - 1);
get_mapname(MapName, sizeof MapName - 1);
formatex(ButtonsDir, sizeof ButtonsDir - 1, "%s/surf_buttons/", ConfigsDir);
formatex(File, sizeof File - 1, "%s/surf_buttons/%s.cfg", ConfigsDir, MapName);
if(!dir_exists(ButtonsDir))
mkdir(ButtonsDir);
if(file_exists(File))
delete_file(File);
new Ent, Buffer[128];
static Float:EntOrigin[3];
while((Ent = engfunc(EngFunc_FindEntityByString, Ent, "classname", FinishButtonClassname)))
{
pev(Ent, pev_origin, EntOrigin);
formatex(Buffer, sizeof Buffer - 1, "%f %f %f", EntOrigin[0], EntOrigin[1], EntOrigin[2]);
write_file(File, Buffer, -1);
}
client_print(id, print_chat, "[%s]Successfuly saved buttons origin.", PluginTag);
}
case 3:
{
if(!GetEntityNoclip(id))
SetEntityNoclip(id, 1);
else
SetEntityNoclip(id, 0);
}
case 4:
{
if(!GetEntityGodmode(id))
set_pev(id, pev_takedamage, DAMAGE_NO);
else
set_pev(id, pev_takedamage, DAMAGE_YES);
}
}
menu_display(id, menu, 0);
return 1;
}
public Fwd_Think(Ent)
{
if(!pev_valid(Ent))
return FMRES_IGNORED;
static ClassName[32];
pev(Ent, pev_classname, ClassName, sizeof ClassName - 1);
if(equali(ClassName, FinishButtonClassname))
{
static Float:EntOrigin[3], Float:PlayerOrigin[3], Float:Distance;
static Float:TotalTime, StringTotalTime[32], Seconds[5], Miliseconds[10];
static RecTime[32], Seconds2[5], Miliseconds2[10];
static Players[32], Num, Player;
get_players(Players, Num, "ah");
pev(Ent, pev_origin, EntOrigin);
for(new i = 0 ; i < Num ; i++)
{
Player = Players[i];
pev(Player, pev_origin, PlayerOrigin);
Distance = get_distance_f(EntOrigin, PlayerOrigin);
if(Distance > 30.0)
continue;
if(TimerStatus[Player] == TIMER_ACTIVE)
{
static Name[32], Temp;
get_user_name(Player, Name, sizeof Name - 1);
Temp = get_user_weapon(Player, Temp, Temp);
FloatTimer[1][Player] = get_gametime();
TotalTime = FloatTimer[1][Player] - FloatTimer[0][Player];
float_to_str(TotalTime, StringTotalTime, sizeof StringTotalTime - 1);
strtok(StringTotalTime, Seconds, sizeof Seconds - 1, Miliseconds, sizeof Miliseconds - 1, '.');
PrintGreen(0, "[%s]%s finished the map in %s%d:%s%d.%d with a %s.", PluginTag, Name, str_to_num(Seconds) / 60 < 10 ? "0" : "", str_to_num(Seconds) / 60, str_to_num(Seconds) % 60 < 10 ? "0" : "", str_to_num(Seconds) % 60, str_to_num(Miliseconds), Weapons[Temp]);
client_cmd(0, "spk %s", FinishSound);
FinishedMap[Player] = true;
ResetTimer(Player);
if(TotalTime < BestTime)
{
PrintGreen(0, "[%s]%s is now the 1337 surfer and is glowing gold.", PluginTag, Name);
BestTime = TotalTime;
BestSurfer = Player;
}
if(TotalTime < MapRecTime)
{
float_to_str(MapRecTime, RecTime, sizeof RecTime - 1);
strtok(RecTime, Seconds2, sizeof Seconds2 - 1, Miliseconds2, sizeof Miliseconds2 - 1, '.');
PrintGreen(0, "[%s]%s has beated the map record time : %s%d:%s%d.%d .The new map record time is : %s%d:%s%d.%d", PluginTag, Name, str_to_num(Seconds2) / 60 < 10 ? "0" : "", str_to_num(Seconds2) / 60, str_to_num(Seconds2) % 60 < 10 ? "0" : "", str_to_num(Seconds2) % 60, str_to_num(Miliseconds2), str_to_num(Seconds) / 60 < 10 ? "0" : "", str_to_num(Seconds) / 60, str_to_num(Seconds) % 60 < 10 ? "0" : "", str_to_num(Seconds) % 60, str_to_num(Miliseconds));
copy(MapRecName, sizeof MapRecName - 1, Name);
MapRecTime = TotalTime;
plugin_end();
}
}
}
set_pev(Ent, pev_nextthink, get_gametime() + 0.1);
}
return FMRES_IGNORED;
}
public Fwd_PlayerPostThink(id)
{
if(!is_user_alive(id))
return FMRES_IGNORED;
static Float:GameTime, Flags, Float:Velocity[3];
GameTime = get_gametime();
Flags = pev(id, pev_flags);
pev(id, pev_velocity, Velocity);
Velocity[2] = 0.0;
if(!(Flags & FL_ONGROUND) && TimerStatus[id] == TIMER_INACTIVE && !FinishedMap[id] && vector_length(Velocity) > 1.0)
{
set_hudmessage(255, 0, 0, -1.0, 0.8, 0, 1.0, 2.0, 0.2, 0.1, 2);
show_hudmessage(id, "Timer started");
TimerStatus[id] = TIMER_ACTIVE;
FloatTimer[0][id] = get_gametime();
}
if(NextCheck[id] < GameTime)
{
if(TimerStatus[id] == TIMER_ACTIVE)
{
static Float:TotalTime;
FloatTimer[1][id] = get_gametime();
TotalTime = FloatTimer[1][id] - FloatTimer[0][id];
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("RoundTime"), _, id);
write_short(floatround(TotalTime) + 1);
message_end();
}
else
{
static Value = 1;
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("RoundTime"), _, id);
write_short(Value);
message_end();
}
NextCheck[id] = GameTime + 1.0;
}
if(id == BestSurfer)
SetEntityRendering(id, kRenderFxGlowShell, 155, 140, 0, kRenderNormal, 15);
else
SetEntityRendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderNormal, 10);
return FMRES_IGNORED;
}
public Fwd_StartFrame()
{
static Players[32], Num, Player, Person;
static Float:PlayerOrigin[3], Float:PersonOrigin[3];
get_players(Players, Num, "ah");
for(new i = 0 ; i < Num ; i++)
{
Player = Players[i];
set_pev(Player, pev_solid, SOLID_BBOX);
SetEntityRendering(Player);
pev(Player, pev_origin, PlayerOrigin);
for(new x = 0 ; x < Num ; x++)
{
Person = Players[x];
if(Player == Person || get_user_team(Player) != get_user_team(Person))
continue;
pev(Person, pev_origin, PersonOrigin);
if(vector_distance(PlayerOrigin, PersonOrigin) < 400)
{
set_pev(Player, pev_solid, SOLID_NOT);
SetEntityRendering(Player, kRenderFxNone, 0, 0, 0, kRenderTransAdd, 15);
set_pev(Person, pev_solid, SOLID_NOT);
SetEntityRendering(Person, kRenderFxNone, 0, 0, 0, kRenderTransAdd, 15);
}
}
}
if(get_cvar_num("sv_airaccelerate") != 100)
set_cvar_num("sv_airaccelerate", 100);
}
public RestartAttempt()
{
new players[32], num;
get_players(players, num, "a");
for(new i = 0 ; i < num ; ++i)
Restart_Attempt[players[i]] = true;
}
public EventPlayerSpawned(id)
{
if(Restart_Attempt[id])
{
Restart_Attempt[id] = false;
return;
}
PlayerRespawn(id);
}
public PlayerRespawn(id)
{
ResetTimer(id);
FinishedMap[id] = false;
set_hudmessage(255, 0, 0, -1.0, 0.8, 0, 1.0, 2.0, 0.2, 0.1, -1);
show_hudmessage(id, "Timer reseted");
set_task(0.2, "GiveWeapons", id + 1111);
set_task(0.3, "SetAmmo", id);
}
public EventPlayerDeath()
{
new Victim = read_data(2);
set_task(0.3, "RespawnPlayer", Victim + 123491);
}
public RespawnPlayer(id)
{
id -= 123491;
if(is_user_alive(id))
return;
UserSpawn(id);
}
public GiveWeapons(id)
{
id -= 1111;
if(!is_user_connected(id))
return;
client_cmd(id, "stopsound");
fm_strip_user_weapons(id);
fm_give_item(id, "weapon_c4");
fm_give_item(id, "weapon_usp");
fm_give_item(id, "weapon_knife");
}
public SetAmmo(id)
{
if(!is_user_connected(id))
return;
cs_set_weapon_ammo(fm_get_weapon_id(id, "weapon_usp"), 0);
}
public ResetTimer(index)
{
TimerStatus[index] = TIMER_INACTIVE;
FloatTimer[0][index] = 0.0;
}
public RestartCourse(id)
{
if(!is_user_connected(id))
return 1;
UserSpawn(id);
FinishedMap[id] = false;
return 1;
}
public ShowMapRecord(id)
{
static MapName[32];
get_mapname(MapName, sizeof MapName - 1);
static Time[32], Seconds[5], Miliseconds[10];
float_to_str(MapRecTime, Time, sizeof Time - 1);
strtok(Time, Seconds, sizeof Seconds - 1, Miliseconds, sizeof Miliseconds - 1, '.');
PrintGreen(id, "[%s]The map record for %s is : %s%d:%s%d.%d done by %s", PluginTag, MapName, str_to_num(Seconds) / 60 < 10 ? "0" : "", str_to_num(Seconds) / 60, str_to_num(Seconds) % 60 < 10 ? "0" : "", str_to_num(Seconds) % 60, str_to_num(Miliseconds), MapRecName);
}
public BlockCmd(id)
return 1;
stock CreateEntButton(const Float:Origin[3])
{
new FinishButton = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString,"info_target"));
if(!FinishButton)
return 0;
set_pev(FinishButton, pev_origin, Origin);
set_pev(FinishButton, pev_classname, FinishButtonClassname);
engfunc(EngFunc_SetModel, FinishButton, FinishButtonModel);
set_pev(FinishButton, pev_nextthink, get_gametime() + 0.1);
SetEntityRendering(FinishButton, kRenderFxGlowShell, 255, 0, 0, kRenderNormal, 30);
SetEntityRendering(FinishButton, kRenderFxGlowShell, 255, 0, 0, kRenderNormal, 60);
return 1;
}
stock SetEntityRendering(entity, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16)
{
static Float:rendercolor[3];
rendercolor[0] = float(r);
rendercolor[1] = float(g);
rendercolor[2] = float(b);
set_pev(entity, pev_renderfx, fx)
set_pev(entity, pev_rendercolor, rendercolor);
set_pev(entity, pev_rendermode, render);
set_pev(entity, pev_renderamt, float(amount));
return 1;
}
stock SetEntityNoclip(index, num)
{
if(num)
set_pev(index, pev_movetype, 8);
else
set_pev(index, pev_movetype, 3);
return 1;
}
stock bool:GetEntityNoclip(index)
{
if(pev(index, pev_movetype) == 8)
return true;
return false;
}
stock bool:GetEntityGodmode(index)
{
if(pev(index, pev_takedamage) == DAMAGE_NO)
return true;
return false;
}
stock UserSpawn(index)
{
set_pev(index, pev_deadflag, DEAD_NO);
dllfunc(DLLFunc_Spawn, index);
set_pev(index, pev_iuser1, 0);
return 1;
}
stock fm_strip_user_weapons(index)
{
new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "player_weaponstrip"));
if(!pev_valid(ent))
return 0;
dllfunc(DLLFunc_Spawn, ent);
dllfunc(DLLFunc_Use, ent, index);
engfunc(EngFunc_RemoveEntity, ent);
return 1;
}
stock fm_give_item(index, const item[])
{
if (!equal(item, "weapon_", 7) && !equal(item, "ammo_", 5) && !equal(item, "item_", 5) && !equal(item, "tf_weapon_", 10))
return 0;
new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, item));
if(!pev_valid(ent))
return 0;
new Float:origin[3];
pev(index, pev_origin, origin);
set_pev(ent, pev_origin, origin);
set_pev(ent, pev_spawnflags, pev(ent, pev_spawnflags) | SF_NORESPAWN);
dllfunc(DLLFunc_Spawn, ent);
new save = pev(ent, pev_solid);
dllfunc(DLLFunc_Touch, ent, index);
if(pev(ent, pev_solid) != save)
return ent;
engfunc(EngFunc_RemoveEntity, ent);
return -1;
}
stock fm_get_weapon_id(index, const weapon[])
{
new ent = -1;
while((ent = engfunc(EngFunc_FindEntityByString, ent, "classname", weapon)) != 0)
{
if(index == pev(ent, pev_owner))
return ent;
}
return 1;
}
stock fm_SetKeyValue(ent, const szKey[], const szValue[])
{
new szClassname[33];
pev(ent, pev_classname, szClassname, sizeof szClassname - 1);
set_kvd(0, KV_ClassName, szClassname);
set_kvd(0, KV_KeyName, szKey);
set_kvd(0, KV_Value, szValue);
set_kvd(0, KV_fHandled, 0);
dllfunc(DLLFunc_KeyValue, ent, 0);
}
stock PrintGreen(index, const message[], {Float, Sql, Result,_}:...) {
new Buffer[512], Buffer2[512], id, msg_type;
formatex(Buffer2, sizeof Buffer2 - 1, "^x04%s", message);
vformat(Buffer, sizeof Buffer - 1, Buffer2, 3);
if(index) {
id = index;
msg_type = MSG_ONE;
}
else {
id = FindPlayer();
msg_type = MSG_ALL;
}
message_begin(msg_type, get_user_msgid("SayText"), _, id);
write_byte(id);
write_string(Buffer);
message_end();
}
public FindPlayer()
{
new players[32], num;
get_players(players, num);
new i = -1;
while(i < num)
{
if(is_user_connected(++i))
{
return i;
}
}
return -1;
}