AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   2 more little problems (https://forums.alliedmods.net/showthread.php?t=155776)

georgik57 04-26-2011 13:22

2 more little problems
 
1 Attachment(s)
so...i have this plugin
i've tried to make it set a cvar's value to 7 on round end and then restore it on round start (variable nvg_radius)
but it doesn't work...it doesn't set the radius back to normal on round start
and the second problem is that sometimes, the hand model doesn't change back on round start either
here's the code...please help
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <zombieplague>

new Hands[33], RandomMaxPlayersChekUserHandsSetNVision

// Normal Models
new const MODELS[3][] =
{
    
"",
    
"models/zombie_plague/zombie_win.mdl",
    
"models/zombie_plague/human_win.mdl"
}

new const 
MODELS2[3][] =
{
    
"",
    
"models/zombie_plague/zombie_win_2.mdl",
    
"models/zombie_plague/human_win_2.mdl"
}

// Fliped Models
new const MODELS_FLIP[3][] =
{
    
"",
    
"models/zombie_plague/zombie_win-f.mdl",
    
"models/zombie_plague/human_win-f.mdl"
}

new const 
MODELS_FLIP2[3][] =
{
    
"",
    
"models/zombie_plague/zombie_win-f_2.mdl",
    
"models/zombie_plague/human_win-f_2.mdl"
}


new 
g_iModelIndex[3], g_iModelIndexFlip[3], g_iModelIndex2[3], g_iModelIndexFlip2[3], g_iWinTeamnvg_radius

public plugin_init()
{
    
register_plugin("[ZP] Sub-Plugin: New Win Messages""1.4""Shidla / xPaw / 93()|29!/<" )
    
register_event("HLTV""EventRoundStart""a""1=0""2=0" )
    
register_event("CurWeapon""EventCurWeapon""be""1=1")

    
MaxPlayers get_maxplayers()

    
register_cvar("Shidla""[ZP] Sub-Plugin: New Win Messages v.1.4"FCVAR_SERVER|FCVAR_SPONLY)
    
register_cvar("zp_new_win_messages""[ZP] Sub-Plugin: New Win Messages v.1.4"FCVAR_SERVER|FCVAR_SPONLY)

    
ChekUserHands register_cvar("zp_new_win_msg_chek" "1")
    
SetNVision register_cvar("zp_new_win_msg_set_nvision" "1")
}

public 
plugin_precache()
{
    for (new 
WIN_ZOMBIES<= WIN_HUMANSi++)
    {
        
// Normal Models
        
precache_model(MODELS[i])
        
g_iModelIndex[i] = engfunc(EngFunc_AllocStringMODELS[i])
        
precache_model(MODELS2[i])
        
g_iModelIndex2[i] = engfunc(EngFunc_AllocStringMODELS2[i])

        
// Fliped Models
        
precache_model(MODELS_FLIP[i])
        
g_iModelIndexFlip[i] = engfunc(EngFunc_AllocStringMODELS_FLIP[i])
        
precache_model(MODELS_FLIP2[i])
        
g_iModelIndexFlip2[i] = engfunc(EngFunc_AllocStringMODELS_FLIP2[i])
    }
}

public 
client_connect(id)
{
    if(!
is_user_bot(id) && get_pcvar_num (ChekUserHands))
        
query_client_cvar(id "cl_righthand" "Hands_CVAR_Value")
}

public 
Hands_CVAR_Value(id, const cvar[], const value[])
{
    if((
<= id <= MaxPlayers) && get_pcvar_num (ChekUserHands))    // Bug Fix & Cheking
        
Hands[id] = str_to_num(value)
}

public 
client_disconnect(id)
{
    if(
get_pcvar_num (ChekUserHands))
        
Hands[id] = 0
}

public 
zp_round_ended(iTeam)
{
    if (
iTeam == WIN_NO_ONE)
        return
    
    
g_iWinTeam iTeam
    
new iPlayers[32], iNum
    get_players
(iPlayersiNum"ch")

    
Random random_num(1)
    for (new 
iiNumi++)
    {
        if(
get_pcvar_num (ChekUserHands))
            
client_cmd(iPlayers[i], "cl_righthand ^"1^"")

        if(
get_pcvar_num(SetNVision))
        {
            
nvg_radius get_cvar_num("zp_nvg_size")
            
set_cvar_num("zp_nvg_size"7)
            
            
zp_set_user_nightvision(iPlayers[i], 1)
        }
        
        switch(
Random)
        {
            case 
0:
            {
                if (
get_user_weapon(iPlayers[i]) != CSW_KNIFE)
                    
set_pev(iPlayers[i], pev_viewmodelg_iModelIndexFlip[iTeam])
                else
                    
set_pev(iPlayers[i], pev_viewmodelg_iModelIndex[iTeam])
            }

            case 
1:
            {
                if (
get_user_weapon(iPlayers[i]) != CSW_KNIFE)
                    
set_pev(iPlayers[i], pev_viewmodelg_iModelIndexFlip2[iTeam])
                else
                    
set_pev(iPlayers[i], pev_viewmodelg_iModelIndex2[iTeam])
            }
        }
    }
}

public 
EventRoundStart()
{
    
g_iWinTeam WIN_NO_ONE
    
    
if (get_cvar_num("zp_nvg_size") != nvg_radius)
        
set_cvar_num("zp_nvg_size"nvg_radius)
    
    if(
get_pcvar_num (ChekUserHands))
    {
        for (new 
1<= MaxPlayersi++)
        {
            if(!
is_user_connected(i))
                continue        
// xPaw fix)))

            
client_cmd(i"cl_righthand ^"%d^""Hands[i])
        }
    }
}

public 
EventCurWeapon(const id)
{
    if (
g_iWinTeam WIN_NO_ONE)
    {
        if (
get_pcvar_num (ChekUserHands))
            
client_cmd(id"cl_righthand ^"1^"")

        switch(
Random)
        {
            case 
0:
            {
                if (
get_user_weapon(id) != CSW_KNIFE)
                    
set_pev(idpev_viewmodelg_iModelIndexFlip[g_iWinTeam])
                else
                    
set_pev(idpev_viewmodelg_iModelIndex[g_iWinTeam])
            }

            case 
1:
            {
                if (
get_user_weapon(id) != CSW_KNIFE)
                    
set_pev(idpev_viewmodelg_iModelIndexFlip2[g_iWinTeam])
                else
                    
set_pev(idpev_viewmodelg_iModelIndex2[g_iWinTeam])
            }
        }
    }



SonicSonedit 04-26-2011 15:08

Re: 2 more little problems
 
About cvar - try this:
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <zombieplague>

new Hands[33], RandomMaxPlayersChekUserHandsSetNVision
new BLAAAAAAAAAAARRRRRRRGGGGGHHHHHH

// Normal Models
new const MODELS[3][] =
{
    
"",
    
"models/zombie_plague/zombie_win.mdl",
    
"models/zombie_plague/human_win.mdl"
}

new const 
MODELS2[3][] =
{
    
"",
    
"models/zombie_plague/zombie_win_2.mdl",
    
"models/zombie_plague/human_win_2.mdl"
}

// Fliped Models
new const MODELS_FLIP[3][] =
{
    
"",
    
"models/zombie_plague/zombie_win-f.mdl",
    
"models/zombie_plague/human_win-f.mdl"
}

new const 
MODELS_FLIP2[3][] =
{
    
"",
    
"models/zombie_plague/zombie_win-f_2.mdl",
    
"models/zombie_plague/human_win-f_2.mdl"
}


new 
g_iModelIndex[3], g_iModelIndexFlip[3], g_iModelIndex2[3], g_iModelIndexFlip2[3], g_iWinTeamnvg_radius

public plugin_init()
{
    
register_plugin("[ZP] Sub-Plugin: New Win Messages""1.4""Shidla / xPaw / 93()|29!/<" )
    
register_event("HLTV""EventRoundStart""a""1=0""2=0" )
    
register_event("CurWeapon""EventCurWeapon""be""1=1")

    
MaxPlayers get_maxplayers()

    
register_cvar("Shidla""[ZP] Sub-Plugin: New Win Messages v.1.4"FCVAR_SERVER|FCVAR_SPONLY)
    
register_cvar("zp_new_win_messages""[ZP] Sub-Plugin: New Win Messages v.1.4"FCVAR_SERVER|FCVAR_SPONLY)

    
ChekUserHands register_cvar("zp_new_win_msg_chek" "1")
    
SetNVision register_cvar("zp_new_win_msg_set_nvision" "1")
    
BLAAAAAAAAAAARRRRRRRGGGGGHHHHHH get_cvar_pointer("zp_nvg_size")
}

public 
plugin_precache()
{
    for (new 
WIN_ZOMBIES<= WIN_HUMANSi++)
    {
        
// Normal Models
        
precache_model(MODELS[i])
        
g_iModelIndex[i] = engfunc(EngFunc_AllocStringMODELS[i])
        
precache_model(MODELS2[i])
        
g_iModelIndex2[i] = engfunc(EngFunc_AllocStringMODELS2[i])

        
// Fliped Models
        
precache_model(MODELS_FLIP[i])
        
g_iModelIndexFlip[i] = engfunc(EngFunc_AllocStringMODELS_FLIP[i])
        
precache_model(MODELS_FLIP2[i])
        
g_iModelIndexFlip2[i] = engfunc(EngFunc_AllocStringMODELS_FLIP2[i])
    }
}

public 
client_connect(id)
{
    if(!
is_user_bot(id) && get_pcvar_num (ChekUserHands))
        
query_client_cvar(id "cl_righthand" "Hands_CVAR_Value")
}

public 
Hands_CVAR_Value(id, const cvar[], const value[])
{
    if((
<= id <= MaxPlayers) && get_pcvar_num (ChekUserHands))    // Bug Fix & Cheking
        
Hands[id] = str_to_num(value)
}

public 
client_disconnect(id)
{
    if(
get_pcvar_num (ChekUserHands))
        
Hands[id] = 0
}

public 
zp_round_ended(iTeam)
{
    if (
iTeam == WIN_NO_ONE)
        return
    
    
g_iWinTeam iTeam
    
new iPlayers[32], iNum
    get_players
(iPlayersiNum"ch")

    
Random random_num(1)
    for (new 
iiNumi++)
    {
        if(
get_pcvar_num (ChekUserHands))
            
client_cmd(iPlayers[i], "cl_righthand ^"1^"")

        if(
get_pcvar_num(SetNVision))
        {
            
nvg_radius get_pcvar_num(BLAAAAAAAAAAARRRRRRRGGGGGHHHHHH)
            
set_pcvar_num(BLAAAAAAAAAAARRRRRRRGGGGGHHHHHH7)
            
            
zp_set_user_nightvision(iPlayers[i], 1)
        }
        
        
client_print(idprint_chat"ZP_ROUND_END - changing hand model")

        switch(
Random)
        {
            case 
0:
            {
                if (
get_user_weapon(iPlayers[i]) != CSW_KNIFE)
                    
set_pev(iPlayers[i], pev_viewmodelg_iModelIndexFlip[iTeam])
                else
                    
set_pev(iPlayers[i], pev_viewmodelg_iModelIndex[iTeam])
            }

            case 
1:
            {
                if (
get_user_weapon(iPlayers[i]) != CSW_KNIFE)
                    
set_pev(iPlayers[i], pev_viewmodelg_iModelIndexFlip2[iTeam])
                else
                    
set_pev(iPlayers[i], pev_viewmodelg_iModelIndex2[iTeam])
            }
        }
    }
}

public 
EventRoundStart()
{
    
g_iWinTeam WIN_NO_ONE
    set_pcvar_num
(BLAAAAAAAAAAARRRRRRRGGGGGHHHHHHnvg_radius)
    
    if(
get_pcvar_num (ChekUserHands))
    {
        for (new 
1<= MaxPlayersi++)
        {
            if(!
is_user_connected(i))
                continue        
// xPaw fix)))

            
client_cmd(i"cl_righthand ^"%d^""Hands[i])
        }
    }
}

public 
EventCurWeapon(const id)
{
    if (
g_iWinTeam WIN_NO_ONE)
    {
        
client_print(idprint_chat"curweapon - changing hand model...")
    
        if (
get_pcvar_num (ChekUserHands))
            
client_cmd(id"cl_righthand ^"1^"")

        switch(
Random)
        {
            case 
0:
            {
                if (
get_user_weapon(id) != CSW_KNIFE)
                    
set_pev(idpev_viewmodelg_iModelIndexFlip[g_iWinTeam])
                else
                    
set_pev(idpev_viewmodelg_iModelIndex[g_iWinTeam])
            }

            case 
1:
            {
                if (
get_user_weapon(id) != CSW_KNIFE)
                    
set_pev(idpev_viewmodelg_iModelIndexFlip2[g_iWinTeam])
                else
                    
set_pev(idpev_viewmodelg_iModelIndex2[g_iWinTeam])
            }
        }
    }


About model - I added some messages. Check if this message still appears if no model change needed - if it does, re-check your if conditions.
...
In fact, I don't see any code that changes model back on round start.

georgik57 04-26-2011 17:54

Re: 2 more little problems
 
Quote:

Originally Posted by SonicSonedit (Post 1458432)
About cvar - try this:
About model - I added some messages. Check if this message still appears if no model change needed - if it does, re-check your if conditions.
...
In fact, I don't see any code that changes model back on round start.

hmm
why cvar_pointer and not cvar_num?
and how can i change the model back to normal one on round start?

SonicSonedit 04-26-2011 18:03

Re: 2 more little problems
 
georgik57
Quote:

and how can i change the model back to normal one on round start?
Save original model name in some string by using pev(iPlayers[i], pev_viewmodel, some_string, charsmax(some_string)) and then restore it in public EventRoundStart()

georgik57 04-26-2011 18:07

Re: 2 more little problems
 
Quote:

Originally Posted by SonicSonedit (Post 1458540)
Save original model name in some string by using pev(iPlayers[i], pev_viewmodel, some_string, charsmax(some_string)) and then restore it in public EventRoundStart()

makes sense
what about this:
Quote:

Originally Posted by georgik57 (Post 1458534)
hmm
why cvar_pointer and not cvar_num?

?

SonicSonedit 04-26-2011 18:08

Re: 2 more little problems
 
http://forums.alliedmods.net/showpos...54&postcount=3

georgik57 04-26-2011 18:41

Re: 2 more little problems
 
Quote:

Originally Posted by georgik57 (Post 1458545)
Quote:

Originally Posted by SonicSonedit (Post 1458543)

okay got it
will remember that
thank you

if that's true then what is get_cvar_num used for?

fysiks 04-26-2011 18:44

Re: 2 more little problems
 
Quote:

Originally Posted by georgik57 (Post 1458572)
if that's true then what is get_cvar_num used for?

You need to learn about how cvar pointers are used and then you should be able to answer your own question.

georgik57 04-26-2011 18:45

Re: 2 more little problems
 
Quote:

Originally Posted by fysiks (Post 1458578)
You need to learn about how cvar pointers are used and then you should be able to answer your own question.

i know how to use them
but why to use them and not use cvar_num?
what's the difference?

fysiks 04-26-2011 18:56

Re: 2 more little problems
 
http://forums.alliedmods.net/showpos...26&postcount=5

and

Quote:

Originally Posted by joaquimandrade (Post 795652)
If you say: "daddy please bring me the beer that is in the fridge", your daddy will take more time to find it than if you say "daddy please bring me the beer that is in the second shelf of the fridge, next to the milk". But, don't fool your daddy. Otherwise you can have to drink the milk instead.

The latter is an analogy for cvar pointers. They are more efficient.


All times are GMT -4. The time now is 04:18.

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