Garry's Mod

[Code Help] Change crosshair if switch to some weapon

Submitted by jackymacky, , Thread ID: 99211

Thread Closed
17-08-2018, 10:38 PM
#1
I not understand how to write good and work code for change crosshair if player use weapon from table, for example if "ak47" from "rifle" table then crosshair changes to "example_crosshair". But I write one code, but this bad code
for crosshairs I use this addon
Code:
local shotgun =
{
*i remove weapon list - it so big
}
local rifles =
{
*i remove weapon list - it so big*
}
local blastguns =
{
*i remove weapon list - it so big
}
local explosives =
{
"sanctum2_bc", "weapon_doom3_rocketlauncher", "weapon_q4_rocketlauncher", "weapon_q4_rocketlauncher_mp"
}
local pistols =
{
*i remove weapon list - it so big*
}
local srifles =
{
"sanctum2_sr"
}
local mines =
{
*i remove weapon list - it so big*
}
local medik =
{
"weapon_medkit"
}

function player_crosshair_changing( )
if shotgun[ply:PlayerSwitchWeapon( player, oldWeapon, newWeapon ) = true] then ply:ConCommand("set_crosshair quater_circle") end
if rifle[ply:PlayerSwitchWeapon( player, oldWeapon, newWeapon )] then ply:ConCommand("set_crosshair circle") end
if pistol[ply:PlayerSwitchWeapon( player, oldWeapon, newWeapon )] then ply:ConCommand("set_crosshair circle") end
if explosives[ply:PlayerSwitchWeapon( player, oldWeapon, newWeapon )] then ply:ConCommand("set_crosshair rocket") end
if mines[ply:PlayerSwitchWeapon( player, oldWeapon, newWeapon )] then ply:ConCommand("set_crosshair v") end
if srifles[ply:PlayerSwitchWeapon( player, oldWeapon, newWeapon )] then ply:ConCommand("set_crosshair circle2") end
if blastguns[ply:PlayerSwitchWeapon( player, oldWeapon, newWeapon )] then ply:ConCommand("set_crosshair rocket") end
if medik[ply:PlayerSwitchWeapon( player, oldWeapon, newWeapon )] then ply:ConCommand("set_crosshair simple") end
else ply:ConCommand("set_crosshair no") end
end

Users browsing this thread: 2 Guest(s)