Senior Member
Join Date: Jul 2013
Location: Bulgaria
|
02-28-2018
, 07:41
Re: cs:go Flash light and nightvision for my server
|
#2
|
Nightvision:
PHP Code:
#pragma semicolon 1
#include <sdktools>
#include <sdktools_sound>
#define VERSION "0.2"
#define AUTHOR "TummieTum (TumTum)"
#define MAX_FILE_LEN 80
// CVAR Handles
new Handle:cvarnven = INVALID_HANDLE;
new Handle:cvarnvspawn = INVALID_HANDLE;
new Handle:cvarnvonoff = INVALID_HANDLE;
new Handle:cvarnvsoundnameon = INVALID_HANDLE;
new String:g_soundNameOn[MAX_FILE_LEN];
// Basic Information (Do not change it)
public Plugin:myinfo =
{
name = "Night Vision Goggles",
author = AUTHOR,
description = "CS:GO Night Vision",
version = VERSION,
url = "https://www.team-secretforce.com"
};
// Command
public OnPluginStart()
{
// Default
RegConsoleCmd("sm_nvg", Command_nightvision);
// Events
HookEvent("player_spawn", PlayerSpawn);
//Cvars
cvarnvspawn = CreateConVar("nv_spawnmsg", "1", "Enable or Disable Spawnmessages");
cvarnvonoff = CreateConVar("nv_onoff", "1", "Disable Enable / Disable Messages");
cvarnven = CreateConVar("nv_command", "1", "Enable or Disable !NVG");
cvarnvsoundnameon = CreateConVar("nv_sound", "music/nightvision/nvon.mp3", "Turn on sound");
// Version
CreateConVar("sm_nightvision_version", VERSION, "Plugin info", FCVAR_DONTRECORD|FCVAR_NOTIFY);
//Generate
AutoExecConfig(true, "Night_Vision_TummieTum");
}
public OnConfigsExecuted()
{
// Get Convars
GetConVarString(cvarnvsoundnameon, g_soundNameOn, MAX_FILE_LEN);
// Buffer
decl String:bufferOn[MAX_FILE_LEN];
// Precache Sounds
PrecacheSound(g_soundNameOn, true);
// Format
Format(bufferOn, sizeof(bufferOn),"sound/%s", g_soundNameOn);
// Add to Downloadstable
AddFileToDownloadsTable(bufferOn);
}
public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
// Get Client
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (GetClientTeam(client) == 1 && !IsPlayerAlive(client))
{
return;
}
// Check Convar & Spawnmsg
if (GetConVarInt(cvarnvspawn) == 1)
{
PrintToChat(client,"[Night Vision] Type \x03!nvg \x01to enable NV.");
}
}
// Enable
public Action:Command_nightvision(client, args)
{
if (GetConVarInt(cvarnven) == 1)
{
if (IsPlayerAlive(client) && GetClientTeam(client) == 2)
{
if(GetEntProp(client, Prop_Send, "m_bNightVisionOn") == 0)
{
SetEntProp(client, Prop_Send, "m_bNightVisionOn", 1);
if (GetConVarInt(cvarnvonoff) == 1)
{
PrintToChat(client,"[Night Vision] \x03NV is Enabled!");
}
EmitSoundToClient(client,g_soundNameOn);
}
else
{
SetEntProp(client, Prop_Send, "m_bNightVisionOn", 0);
if (GetConVarInt(cvarnvonoff) == 1)
{
PrintToChat(client,"[Night Vision] \x03NV is Disabled!");
}
}
}
}
return Plugin_Handled;
}
Flashlight:
PHP Code:
#pragma semicolon 1
#include <sdktools>
#define PVERSION "1.3.63"
new Handle:gH_Enabled = INVALID_HANDLE;
new Handle:gH_LAW = INVALID_HANDLE;
new Handle:gH_Return = INVALID_HANDLE;
new Handle:gH_Sound = INVALID_HANDLE;
new Handle:gH_SoundAll = INVALID_HANDLE;
new bool:bEnabled = true;
new bool:bLAW = true;
new bool:bRtn = false;
new bool:bSnd = false;
new bool:bSndAll = true;
new String:zsSnd[255];
public Plugin:myinfo =
{
name = "Flashlight",
author = "Mitch",
description = "Replaces +lookatweapon with a toggleable flashlight. Also adds the command: sm_flashlight",
version = PVERSION,
url = "https://forums.alliedmods.net/showthread.php?t=227224"
};
public OnPluginStart()
{
gH_Enabled = CreateConVar("sm_flashlight_enabled", "1",
"0 = Disables flashlight; 1 = Enables flashlight", FCVAR_PLUGIN, true, 0.0, true, 1.0);
gH_LAW = CreateConVar("sm_flashlight_lookatweapon", "1",
"0 = Doesn't use +lookatweapon; 1 = hooks +lookatweapon", FCVAR_PLUGIN, true, 0.0, true, 1.0);
gH_Return = CreateConVar("sm_flashlight_return", "0",
"0 = Doesn't return blocking +look at weapon; 1 = Does return", FCVAR_PLUGIN, true, 0.0, true, 1.0);
gH_Sound = CreateConVar("sm_flashlight_sound", "items/flashlight1.wav",
"Sound path to use when a player uses the flash light.", FCVAR_PLUGIN);
gH_SoundAll = CreateConVar("sm_flashlight_sound_all", "1",
"Play the sound to all players, or just to the activator?", FCVAR_PLUGIN);
UpdateSound();
HookConVarChange(gH_Sound, ConVarChanged);
HookConVarChange(gH_Enabled, ConVarChanged);
HookConVarChange(gH_LAW, ConVarChanged);
HookConVarChange(gH_Return, ConVarChanged);
HookConVarChange(gH_SoundAll, ConVarChanged);
AutoExecConfig();
CreateConVar("sm_flashlight_version", PVERSION, "CsGoFlashlight Version", FCVAR_DONTRECORD|FCVAR_NOTIFY);
AddCommandListener(Command_LAW, "+lookatweapon"); //Hooks cs:go's flashlight replacement 'look at weapon'.
RegConsoleCmd("sm_flashlight", Command_FlashLight); //Bindable Flashlight command
}
public ConVarChanged(Handle:cvar, const String:oldVal[], const String:newVal[])
{
if(cvar == gH_Enabled)
bEnabled = bool:StringToInt(newVal);
if(cvar == gH_LAW)
bLAW = bool:StringToInt(newVal);
if(cvar == gH_Return)
bRtn = bool:StringToInt(newVal);
if(cvar == gH_SoundAll)
bSndAll = bool:StringToInt(newVal);
if(cvar == gH_Sound) {
UpdateSound();
}
}
public UpdateSound() {
decl String:formatedSound[256];
GetConVarString(gH_Sound, formatedSound, sizeof(formatedSound));
if(StrEqual(formatedSound, "") || StrEqual(formatedSound, "0")) {
bSnd = false;
} else {
strcopy(zsSnd, sizeof(zsSnd), formatedSound);
bSnd = true;
PrecacheSound(zsSnd);
if(!StrEqual(formatedSound, "items/flashlight1.wav")) {
Format(formatedSound, sizeof(formatedSound), "sound/%s", formatedSound);
AddFileToDownloadsTable(formatedSound);
}
}
}
public OnMapStart() {
if(bSnd) {
PrecacheSound(zsSnd, true);
}
}
public Action:Command_LAW(client, const String:command[], argc)
{
if(!bLAW || !bEnabled) //Enable this hook?
return Plugin_Continue;
if(!IsClientInGame(client)) //If player is not in-game then ignore!
return Plugin_Continue;
if(!IsPlayerAlive(client)) //If player is not alive then continue the command.
return Plugin_Continue;
ToggleFlashlight(client);
return (bRtn) ? Plugin_Continue : Plugin_Handled;
}
public Action:Command_FlashLight(client, args)
{
if(!bEnabled)
return Plugin_Handled;
if (IsClientInGame(client) && IsPlayerAlive(client) && GetClientTeam(client) == 3) {
ToggleFlashlight(client);
}
return Plugin_Handled;
}
ToggleFlashlight(client) {
SetEntProp(client, Prop_Send, "m_fEffects", GetEntProp(client, Prop_Send, "m_fEffects") ^ 4);
if(bSnd) {
if(bSndAll) {
EmitSoundToAll(zsSnd, client);
} else {
EmitSoundToClient(client, zsSnd);
}
}
}
__________________
|
|