Raised This Month: $32 Target: $400
 8% 

Subplugin Submission [ZP 5.0] New Night Vision / Lighting System [No Lag]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 07-11-2015 , 22:19   [ZP 5.0] New Night Vision / Lighting System [No Lag]
Reply With Quote #1

Well, lately i noticed that ZP 5.0 has FPS problems on a full server
So i felt like the replacement of the lighting and night vision system were absolutely necesary until we get a new update for it to fix these problems.

By running this new lighting/night vision system i managed to boost the FPS from a minimum of 30 to a minimum 60 on my pc.

This Night Vision plugin is similar to the Zombie Escape one, you also have cvars for screenfade color for modes/zombie/human/etc

Requirements:

In plugins.ini disable the following plugins:
1. zp50_effects_lighting.amxx
2. zp50_item_nightvision.amxx
3. zp50_nightvision.amxx

Known Bugs:

Major:
1. On very dark maps in the darkest places the visibility is very low ( cannot be fixed )

Normal:
1. The thunder lighting was disabled ( i was too lazy and not in need of it to convert )

Minor:
1. The screenfade disapears after the player is frozen or if any other screen fade is executed on the player ( the lighting is not affected ) and it can be fixed by dezactivating and reactivating the night vision, again i was too lazy to fix it

2. The Night Vision doesn't have radius ( cannot be fixed )

Note:

1. Please note that you may still encounter lower fps on some bad created maps, not related to our lighting / night vision system ( even tho i didn't see the problem on ZP 4.3 and i have no ideea why it is happening on ZP 5.0)

P.S: If anyone wants to edit/optimize it please feel free ! also, im sorry for not posting it as a .sma file
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <amx_settings_api>
#include <cs_ham_bots_api>
#include <zp50_core_const>
#include <zp50_class_nemesis>
#include <zp50_class_assassin>
#include <zp50_class_survivor>
#include <zp50_class_sniper>
#include <zp50_gamemodes>
#include <zp50_items>

// Settings file
new const ZP_SETTINGS_FILE[] = "zombieplague.ini"

// Sky Related

new const sky_names[][] = { "space" }

#define SKYNAME_MAX_LENGTH 32

new g_sky_custom_enable 1
new Array:g_sky_names

new g_SkyArrayIndex

// Lighting
new cvar_lightingcvar_vlightingcvar_triggered_lights

// Night Vision
new g_msgScreenFade

new g_itemid
new g_item[33], g_active[33]

new 
cvar_vcolor_human_rcvar_vcolor_human_gcvar_vcolor_human_b
new cvar_vcolor_zombie_rcvar_vcolor_zombie_gcvar_vcolor_zombie_b
new cvar_vcolor_nemesis_rcvar_vcolor_nemesis_gcvar_vcolor_nemesis_b
new cvar_vcolor_assassin_rcvar_vcolor_assassin_gcvar_vcolor_assassin_b
new cvar_vcolor_survivor_rcvar_vcolor_survivor_gcvar_vcolor_survivor_b
new cvar_vcolor_sniper_rcvar_vcolor_sniper_gcvar_vcolor_sniper_b

public plugin_init() 
{
    
register_plugin("[ZP] New Lighting System""1.0""ADN")
    
    
register_event("HLTV""event_round_start""a""1=0""2=0")
    
register_clcmd("nightvision""vision_switch")
    
RegisterHam(Ham_Killed"player""fw_PlayerKilled_Post"1)
    
RegisterHamBots(Ham_Killed"fw_PlayerKilled_Post"1)
    
    
    
    
        
// Set a random skybox?
    
if (g_sky_custom_enable)
    {
        new 
skyname[SKYNAME_MAX_LENGTH]
        
ArrayGetString(g_sky_namesg_SkyArrayIndexskynamecharsmax(skyname))
        
set_cvar_string("sv_skyname"skyname)
    }
    
        
// Disable sky lighting so it doesn't mess with our custom lighting
    
set_cvar_num("sv_skycolor_r"0)
    
set_cvar_num("sv_skycolor_g"0)
    
set_cvar_num("sv_skycolor_b"0)

    
g_itemid zp_items_register("New Night Vision"5)
    
    
cvar_lighting register_cvar("zp_lighting""g")
    
cvar_vlighting register_cvar("zp_lighting_vision""m")
    
cvar_triggered_lights register_cvar("zp_triggered_lights""1")
    
    
// Night Vision Colors
    
cvar_vcolor_human_r register_cvar("zp_nvision_human_color_R""150")
    
cvar_vcolor_human_g register_cvar("zp_nvision_human_color_G""150")
    
cvar_vcolor_human_b register_cvar("zp_nvision_human_color_B""150")
    
    
cvar_vcolor_zombie_r register_cvar("zp_nvision_zombie_color_R""150")
    
cvar_vcolor_zombie_g register_cvar("zp_nvision_zombie_color_G""150")
    
cvar_vcolor_zombie_b register_cvar("zp_nvision_zombie_color_B""150")
    
    
cvar_vcolor_nemesis_r register_cvar("zp_nvision_nemesis_color_R""150")
    
cvar_vcolor_nemesis_g register_cvar("zp_nvision_nemesis_color_G""150")
    
cvar_vcolor_nemesis_b register_cvar("zp_nvision_nemesis_color_B""150")
    
    
cvar_vcolor_assassin_r register_cvar("zp_nvision_assassin_color_R""150")
    
cvar_vcolor_assassin_g register_cvar("zp_nvision_assassin_color_G""150")
    
cvar_vcolor_assassin_b register_cvar("zp_nvision_assassin_color_B""150")

    
cvar_vcolor_survivor_r register_cvar("zp_nvision_survivor_color_R""150")
    
cvar_vcolor_survivor_g register_cvar("zp_nvision_survivor_color_G""150")
    
cvar_vcolor_survivor_b register_cvar("zp_nvision_survivor_color_B""150")
    
    
cvar_vcolor_sniper_r register_cvar("zp_nvision_sniper_color_R""150")
    
cvar_vcolor_sniper_g register_cvar("zp_nvision_sniper_color_G""150")
    
cvar_vcolor_sniper_b register_cvar("zp_nvision_sniper_color_B""150")
    
    
register_message(g_msgScreenFade"message_screenfade")
    
g_msgScreenFade get_user_msgid("ScreenFade")
    
}

public 
plugin_precache()
{
    
g_sky_names ArrayCreate(SKYNAME_MAX_LENGTH1)
    
    
// Load from external file
    
if (!amx_load_setting_int(ZP_SETTINGS_FILE"Custom Skies""ENABLE"g_sky_custom_enable))
        
amx_save_setting_int(ZP_SETTINGS_FILE"Custom Skies""ENABLE"g_sky_custom_enable)
    
amx_load_setting_string_arr(ZP_SETTINGS_FILE"Custom Skies""SKY NAMES"g_sky_names)

    
// If we couldn't load from file, use and save default ones
    
new index
    
if (ArraySize(g_sky_names) == 0)
    {
        for (
index 0index sizeof sky_namesindex++)
            
ArrayPushString(g_sky_namessky_names[index])
        
        
// Save to external file
        
amx_save_setting_string_arr(ZP_SETTINGS_FILE"Custom Skies""SKY NAMES"g_sky_names)
    }
    
    if (
g_sky_custom_enable)
    {
        
// Choose random sky and precache sky files
        
new path[128], skyname[SKYNAME_MAX_LENGTH]
        
g_SkyArrayIndex random_num(0ArraySize(g_sky_names) - 1)
        
ArrayGetString(g_sky_namesg_SkyArrayIndexskynamecharsmax(skyname))
        
formatex(pathcharsmax(path), "gfx/env/%sbk.tga"skyname)
        
precache_generic(path)
        
formatex(pathcharsmax(path), "gfx/env/%sdn.tga"skyname)
        
precache_generic(path)
        
formatex(pathcharsmax(path), "gfx/env/%sft.tga"skyname)
        
precache_generic(path)
        
formatex(pathcharsmax(path), "gfx/env/%slf.tga"skyname)
        
precache_generic(path)
        
formatex(pathcharsmax(path), "gfx/env/%srt.tga"skyname)
        
precache_generic(path)
        
formatex(pathcharsmax(path), "gfx/env/%sup.tga"skyname)
        
precache_generic(path)
    }    
}

public 
plugin_cfg()
{
    
server_cmd("mp_playerid 1")
    
    
set_task(5.0"lighting_task"___"b")
    
    
// Call roundstart manually
    
event_round_start()
    
}

// EVENTS ==========================================================================================

public event_round_start()
{
    
// Remove lights?
    
if (!get_pcvar_num(cvar_triggered_lights))
        
set_task(0.1"remove_lights")

}

public 
client_putinserver(id)
{
    
set_task(3.0"set_vision_spec"id)
}

public 
fw_PlayerKilled_Post(victimattackershouldgib)
{
    
set_vision_spec(victim)
}

public 
zp_fw_core_spawn_post(id)
{    
    
g_item[id] = false
    
    set_task
(0.5"set_vision_off"id)
}

public 
zp_fw_core_cure_post(idattacker)
{
    if(
zp_class_survivor_get(id) || zp_class_sniper_get(id))
    {
        
g_item[id] = true
        set_task
(0.5"set_vision_color"id)
    }
    else
    {
        
g_item[id] = false
        set_task
(0.5"set_vision_off"id)
    }
}
    
public 
zp_fw_core_infect_post(idattacker)
{
    
g_item[id] = true
    set_task
(0.5"set_vision_color"id)
}    
    
public 
client_disconnect(id)
{
    
g_item[id] = false
    g_active
[id] = false
}
// LIGHTING TASK ===================================================================================

public remove_lights()
{
    new 
ent
    
    
// Triggered lights
    
ent = -1
    
while ((ent engfunc(EngFunc_FindEntityByStringent"classname""light")) != 0)
    {
        
dllfunc(DLLFunc_Useent0); // turn off the light
        
set_pev(entpev_targetname0// prevent it from being triggered
    
}
}

public 
lighting_task()
{

    new 
lighting[2]
    
get_pcvar_string(cvar_lightinglightingcharsmax(lighting))
    
    
// Lighting disabled? ["0"]
    
if (lighting[0] == '0')
        return;

    
    new 
Players[32], Numid
    get_players
(PlayersNum)
    for(new 
i<= Numi++)
    {
        
id Players[i]
        
        if(!
g_active[id])
        {
            
set_player_light(idlighting
        }
        
    }
    
    
}  

// EXTRA ITEM ======================================================================================

public zp_fw_items_select_pre(iditemidigc)
{
    if( 
itemid == g_itemid)
    {
        if( 
zp_core_is_zombie(id) || zp_class_survivor_get(id) || zp_class_sniper_get(id))
        return 
ZP_ITEM_DONT_SHOW   
        
        
if(g_item[id])
        return 
ZP_ITEM_NOT_AVAILABLE
    
}
    return 
ZP_ITEM_AVAILABLE
     
}

public 
zp_fw_items_select_post(iditemigc)
{
    if(
item == g_itemid)
    {
        
g_item[id] = true
        set_vision_color
(id)
        
    }
    return 
PLUGIN_CONTINUE  
}

// SET NIGHT VISION ================================================================================

public vision_switch(id)
{
    if(
g_item[id] || !is_user_alive(id))
    {
    
        if(!
g_active[id])
        {
            
set_vision_color(id)
        }
        
        else
        {
            
set_vision_off(id)
        }
    }
}

public 
set_vision_spec(id)
{
    if(!
is_user_alive(id))
    {
    
        
set_vision_color(id)
    }
}

public 
set_vision_color(id)
{
    if(
zp_core_is_zombie(id))
    {
        if(
zp_class_nemesis_get(id))
        {
            
set_vision_on(idget_pcvar_num(cvar_vcolor_nemesis_r), get_pcvar_num(cvar_vcolor_nemesis_g), get_pcvar_num(cvar_vcolor_nemesis_b))
        }
        else if(
zp_class_assassin_get(id))
        {
                
            
set_vision_on(idget_pcvar_num(cvar_vcolor_assassin_r), get_pcvar_num(cvar_vcolor_assassin_g), get_pcvar_num(cvar_vcolor_assassin_b))
        }
        else
        {
            
set_vision_on(idget_pcvar_num(cvar_vcolor_zombie_r), get_pcvar_num(cvar_vcolor_zombie_g), get_pcvar_num(cvar_vcolor_zombie_b))
        }
        
    }
    else
    {
        if(
zp_class_survivor_get(id))
        {
            
set_vision_on(idget_pcvar_num(cvar_vcolor_survivor_r), get_pcvar_num(cvar_vcolor_survivor_g), get_pcvar_num(cvar_vcolor_survivor_b))
        }
        else if(
zp_class_sniper_get(id))
        {
            
set_vision_on(idget_pcvar_num(cvar_vcolor_sniper_r), get_pcvar_num(cvar_vcolor_sniper_g), get_pcvar_num(cvar_vcolor_sniper_b))
        }
        else
        {
            
set_vision_on(idget_pcvar_num(cvar_vcolor_human_r), get_pcvar_num(cvar_vcolor_human_g), get_pcvar_num(cvar_vcolor_human_b))
        }
    }
}

// EXECUTE TASK ====================================================================================

public set_vision_on(idRGB)
{
    if(
is_user_connected(id))
    {
    
        new 
vlighting[2]
        
get_pcvar_string(cvar_vlightingvlightingcharsmax(vlighting))
        
        
message_begin(MSG_ONE_UNRELIABLEg_msgScreenFade_id)
        
write_short((1<<12))
        
write_short(0)
        
write_short(0x0004)
        
write_byte(R)
        
write_byte(G)
        
write_byte(B)
        
write_byte(50)
        
message_end()
        
        
set_player_light(idvlighting)
        
g_active[id] = true
        
    
}
    
}
    
public 
set_vision_off(id)
{
    if(
is_user_connected(id))
    {
    
        new 
lighting[2]
        
get_pcvar_string(cvar_lightinglightingcharsmax(lighting))
        
        
message_begin(MSG_ONE_UNRELIABLEg_msgScreenFade_id)
        
write_short((1<<12))
        
write_short(0)
        
write_short(0x0004)
        
write_byte(0)
        
write_byte(0)
        
write_byte(0)
        
write_byte(0)
        
message_end()
        
        
set_player_light(idlighting)
        
        
g_active[id] = false
        
        
    
}
    
}    
    
public 
set_player_light(id, const LightStyle[])
{
    if(
is_user_connected(id))
    {

        
message_begin(MSG_ONE_UNRELIABLESVC_LIGHTSTYLE_id)
        
write_byte(0)
        
write_string(LightStyle)
        
message_end()
    }
    


Last edited by Depresie; 07-11-2015 at 22:28.
Depresie is offline
Linkin Hisoka
Senior Member
Join Date: Sep 2014
Location: Morocco, Marrakesh
Old 07-16-2015 , 18:39   Re: [ZP 5.0] New Night Vision / Lighting System [No Lag]
Reply With Quote #2

+karma
i will use it in my server
__________________
Moroccan and proud
Linkin Hisoka is offline
Salmon12
Junior Member
Join Date: Aug 2022
Old 09-26-2022 , 21:35   Re: [ZP 5.0] New Night Vision / Lighting System [No Lag]
Reply With Quote #3

Why don't you put the Nightvision Screen Fade for Dragon, Nightcrawler, Plasma, Knifer?
Salmon12 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode