AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Random Player (https://forums.alliedmods.net/showthread.php?t=113994)

Merc3y 01-01-2010 04:20

Random Player
 
What wrong with this ?

I wanted to make 1 random player to be a stalker instead it giving me more than 1

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <amxmisc>

new cvar_delay

new Night_StalkerMaxPlayers

public plugin_init( )
{
    
register_plugin"Night Stalker Mod""1.0""Merc3y" )

    
register_logevent"logevent_round_start"2"1=Round_Start" 
    
register_logevent"logevent_round_end"2"1=Round_End" 
    
    
register_concmd"amx_nightstalker""Toggle"ADMIN_LEVEL_D" < 1 = on | 0 = off >" )
    
register_cvar"nightstalker_toggle""0" )

    
cvar_delay register_cvar"ns_delay""10.0" )

    
MaxPlayers get_maxplayers( )
}

public 
Game_Startid )
{
        new 
players32 ], num
        get_players
playersnum"a" )
        
Night_Stalker playersrandom_num1num ) ]
        
StatsNight_Stalker )
}

public 
Statsid )
{
        
fm_set_user_healthNight_Stalker250 )
        
fm_set_user_gravityNight_Stalker0.7 )


public 
Toggleidlevelcid )
{
    if ( !
cmd_accessidlevelcid) )
    {
        return 
PLUGIN_HANDLED
    
}
    new 
arg132 ]
    
read_argv1arg131 )
    if ( 
str_to_numarg1 ) )
    {
            
set_cvar_num"nightstalker_toggle")
            
server_cmd"sv_restartround 10" )
    } 

    else
    {
            
set_cvar_num"nightstalker_toggle")
            
server_cmd"sv_restartround 10" )
    }       
    return 
PLUGIN_HANDLED
}

public 
logevent_round_start( )
{
    for ( new 
1<= MaxPlayersi++ )
    {
        if ( 
get_cvar_num"nightstalker_toggle" ) == )
        {
            
set_taskget_pcvar_floatcvar_delay ), "Game_Start" )
        }

        else if ( 
get_cvar_num"nightstalker_toggle" ) == )
        {
            
remove_task)
        }
    }
}

public 
logevent_round_end( )
{
    for ( new 
1<= MaxPlayersi++ )
    {
        
remove_task)
    }


Help needed.

wyrda 01-01-2010 11:30

Re: Random Player
 
If you want only one player to have his health and gravity changed after that delay this is the code:
PHP Code:

#include <amxmodx>
#include <fun>
#include <amxmisc>

new cvar_delay

new Night_Stalker

public plugin_init( )
{
    
register_plugin"Night Stalker Mod""1.0""Merc3y" )

    
register_logevent"logevent_round_start"2"1=Round_Start" 
    
register_logevent"logevent_round_end"2"1=Round_End" 
    
    
register_concmd"amx_nightstalker""Toggle"ADMIN_LEVEL_D" < 1 = on | 0 = off >" )
    
register_cvar"nightstalker_toggle""0" )

    
cvar_delay register_cvar"ns_delay""10.0" )

    
}

public 
Game_Startid )
{
    new 
players32 ], num
    get_players
playersnum"a" )
    
Night_Stalker playersrandom_num0num-) ]
    if(
is_user_alive(Night_Stalker))
        
StatsNight_Stalker )
}

public 
Statsid )
{
    
set_user_healthNight_Stalker250 )
    
set_user_gravityNight_Stalker0.7 )


public 
Toggleidlevelcid )
{
    if ( !
cmd_accessidlevelcid) )
    {
        return 
PLUGIN_HANDLED
    
}
    new 
arg132 ]
    
read_argv1arg131 )
    if ( 
str_to_numarg1 ) )
    {
            
set_cvar_num"nightstalker_toggle")
            
server_cmd"sv_restartround 10" )
    } 

    else
    {
            
set_cvar_num"nightstalker_toggle")
            
server_cmd"sv_restartround 10" )
    }       
    return 
PLUGIN_HANDLED
}

public 
logevent_round_start( )
{    
        if ( 
get_cvar_num"nightstalker_toggle" ) == )
        {
            
set_taskget_pcvar_floatcvar_delay ), "Game_Start" )
        }   
}

public 
logevent_round_end( )
{
   public 
logevent_round_end( )
{
    
is_user_connected(Night_Stalker)
    {
        if(
is_user_alive(Night_Stalker))
            
set_user_healthNight_Stalker100 )
        
set_user_gravityNight_Stalker1.0 )
    }
}


also at the end of the round if he is alive his life will be restored to 100(even I think that this is not necessary)

Merc3y 01-01-2010 12:15

Re: Random Player
 
Quote:

Originally Posted by wyrda (Post 1038973)
If you want only one player to have his health and gravity changed after that delay this is the code:
PHP Code:

#include <amxmodx>
#include <fun>
#include <amxmisc>
 
new cvar_delay
 
new Night_Stalker
 
public plugin_init( )
{
    
register_plugin"Night Stalker Mod""1.0""Merc3y" )
 
    
register_logevent"logevent_round_start"2"1=Round_Start" 
    
register_logevent"logevent_round_end"2"1=Round_End" 
 
    
register_concmd"amx_nightstalker""Toggle"ADMIN_LEVEL_D" < 1 = on | 0 = off >" )
    
register_cvar"nightstalker_toggle""0" )
 
    
cvar_delay register_cvar"ns_delay""10.0" )
 
 
}
 
public 
Game_Startid )
{
    new 
players32 ], num
    get_players
playersnum"a" )
    
Night_Stalker playersrandom_num0num-) ]
    if(
is_user_alive(Night_Stalker))
        
StatsNight_Stalker )
}
 
public 
Statsid )
{
    
set_user_healthNight_Stalker250 )
    
set_user_gravityNight_Stalker0.7 )

 
public 
Toggleidlevelcid )
{
    if ( !
cmd_accessidlevelcid) )
    {
        return 
PLUGIN_HANDLED
    
}
    new 
arg132 ]
    
read_argv1arg131 )
    if ( 
str_to_numarg1 ) )
    {
            
set_cvar_num"nightstalker_toggle")
            
server_cmd"sv_restartround 10" )
    } 
 
    else
    {
            
set_cvar_num"nightstalker_toggle")
            
server_cmd"sv_restartround 10" )
    }       
    return 
PLUGIN_HANDLED
}
 
public 
logevent_round_start( )
{    
        if ( 
get_cvar_num"nightstalker_toggle" ) == )
        {
            
set_taskget_pcvar_floatcvar_delay ), "Game_Start" )
        }   
}
 
public 
logevent_round_end( )
{
   public 
logevent_round_end( )
{
    
is_user_connected(Night_Stalker)
    {
        if(
is_user_alive(Night_Stalker))
            
set_user_healthNight_Stalker100 )
        
set_user_gravityNight_Stalker1.0 )
    }
}


also at the end of the round if he is alive his life will be restored to 100(even I think that this is not necessary)

Sorry about the MaxPlayers thing. that was not the full code.

"even I think that this is not necessary" Yeah.

Haven't test the code yet. EDIT: Still instead of 1 it make all player stalker.

wyrda 01-01-2010 15:13

Re: Random Player
 
1 Attachment(s)
I attached the file that I tested on my server. It worked for my well.
I think that you didn't replace the old plugin because your code make all player stalker.
P.S. I changed this register_cvar( "nightstalker_toggle", "0" ) to register_cvar( "nightstalker_toggle", "1" ) :p

Merc3y 01-01-2010 15:26

Re: Random Player
 
Quote:

Originally Posted by wyrda (Post 1039247)
I attached the file that I tested on my server. It worked for my well.
I think that you didn't replace the old plugin because your code make all player stalker.
P.S. I changed this register_cvar( "nightstalker_toggle", "0" ) to register_cvar( "nightstalker_toggle", "1" ) :p

This is my code:

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <amxmisc>
 
new cvar_delay
 
new Night_Stalker
 
public plugin_init( )
{
    
register_plugin"Night Stalker Mod""1.0""Merc3y" )
 
    
register_logevent"logevent_round_start"2"1=Round_Start" 
    
register_logevent"logevent_round_end"2"1=Round_End" )
 
    
register_concmd"amx_nightstalker""Toggle"ADMIN_LEVEL_D" < 1 = on | 0 = off >" )
    
register_cvar"nightstalker_toggle""0" )
    
cvar_delay register_cvar"ns_delay""10.0" )
}
 
public 
Game_Startid )
{
    new 
players32 ], num
    get_players
playersnum"a" )
    
Night_Stalker playersrandom_num0num-) ]
 
    if ( 
is_user_aliveNight_Stalker ) )
    {
        
StatsNight_Stalker )
    }
}
 
public 
Statsid )
{    
    
fm_set_user_healthNight_Stalker200 )
    
fm_set_user_gravityNight_Stalker200 )

 
public 
Toggleidlevelcid )
{
    if ( !
cmd_accessidlevelcid) )
    {
        return 
PLUGIN_HANDLED
    
}
    new 
arg132 ]
    
read_argv1arg131 )
    if ( 
str_to_numarg1 ) )
    {
            
set_cvar_num"nightstalker_toggle")
            
server_cmd"sv_restartround 10" )
    } 
    else
    {
            
set_cvar_num"nightstalker_toggle")
            
server_cmd"sv_restartround 10" )
    }       
    return 
PLUGIN_HANDLED
}
 
public 
logevent_round_start( )
{
        if ( 
get_cvar_num"nightstalker_toggle" ) == )
        {
            
set_taskget_pcvar_floatcvar_delay ), "Game_Start" )
        }
        else if ( 
get_cvar_num"nightstalker_toggle" ) == )
        {
            
remove_task)
        }
}
 
public 
logevent_round_end( )
{
        
remove_task)


And it still giving me more than 1 stalker instead of 1 ?

wyrda 01-01-2010 17:34

Re: Random Player
 
I didn''t test your code because this functions fm_set_user_health,fm_set_user_gravity does not exists(I think that you wrote them or maybe is an older version of amxmodx) and it should work.

Merc3y 01-02-2010 01:42

Re: Random Player
 
Quote:

Originally Posted by wyrda (Post 1039383)
I didn''t test your code because this functions fm_set_user_health,fm_set_user_gravity does not exists(I think that you wrote them or maybe is an older version of amxmodx) and it should work.

Like i say this is not the full code. Just add like this ?

PHP Code:

stock fm_set_user_health(indexhealth) {
 
health set_pev(indexpev_healthfloat(health)) : dllfunc(DLLFunc_ClientKillindex);
 return 
1;
}

stock fm_set_user_gravity(indexFloat:gravity 1.0) {
 
set_pev(indexpev_gravitygravity);
 return 
1;



wyrda 01-02-2010 05:34

Re: Random Player
 
I didn't use set_pev so I can not say what is wrong.Still I don't understand why don't you use set_user_health when I works well.

Merc3y 01-02-2010 08:42

Re: Random Player
 
Quote:

Originally Posted by wyrda (Post 1039848)
I didn't use set_pev so I can not say what is wrong.Still I don't understand why don't you use set_user_health when I works well.

Reduce include.

fysiks 01-02-2010 15:21

Re: Random Player
 
Quote:

Originally Posted by Merc3y (Post 1039969)
Reduce include.

Doesn't make it any better. Use the most efficient function. set_user_health() is more efficient.


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

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