AlliedModders

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

vtsoxluvr 04-15-2007 20:05

Random Player event
 
So i am trying to make an improved version of DoD Ninja for a server that i play on but the feature that they wanted the most i cant seem to get to work, i am trying to get it so that a ninja is chosen every like 35 seconds but i cant seem to get it to work, when i enable the random niinja mode at first it gives me an error: ninjamod.sma::random_event (line 245)
PHP Code:

public random_event(){
    
player_count get_playersnum();
    new 
maxpl get_maxplayers()
    new 
Player random_num(1maxpl)
    if (
player_count 1) {
        
//time_remaining = Float:get_systime()
        
random_event()
        return;
    }
    else if( 
player_count >= && is_user_connected(Player) == ){
**           
random_event()
        return 
PLUGIN_CONTINUE
    
}
    else if( 
player_count >= && is_user_connected(Player) == ){
        if ( 
g_status[Player] == true ){
            
random_event()
            return 
PLUGIN_CONTINUE
        
}
        else if( 
g_status[Player] == false ){
            
set_task(35.0"give_ninja"Player"b")
            
random_event()
            return 
PLUGIN_CONTINUE
        
}
    }


which is the line with the stars at the begining of it, then it assigns ninja nonstop for like 10 seconds, im not sure exactly why, if you need me to post all my code i will be happy to but ill warn you it isn't very clean

thanx for any help i receive

Nican 04-15-2007 20:16

Re: Random Player event
 
Did you notice that function is a infinite loop?

Anything that happens you call "random_event()" over and over again

And can you give the full error?

vtsoxluvr 04-15-2007 20:19

Re: Random Player event
 
i want it to be an infinite loop, i want it to pick a new ninja every 30 seconds then start over again but im not really sure where i went wrong in this section, the rest of my plugin works as i wanted it to, but this part i just dont get, i think it has something to do with the way i am using set_task()

Nican 04-15-2007 20:26

Re: Random Player event
 
You want a new ninja every 30 seconds, do something like in plugin_init:

//Call findnewninja() funtion every 30 seconds
set_task(30.0,"findnewninja",5132,"",0,"b")


the way you did for infinite loop is too unstable...

vtsoxluvr 04-15-2007 20:29

Re: Random Player event
 
what does the 5132 stand for, isnt that usually where the target for the function goes

Nican 04-15-2007 20:38

Re: Random Player event
 
just put random numbers, it is the ID of the task

vtsoxluvr 04-15-2007 21:26

Re: Random Player event
 
so i did what you said but now i dont get ninja at all, but there are also no errors so this is probably a step forward

here are the parts of code that you will probably need

PHP Code:

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_concmd("ninja_mode","admin_ninja",ADMIN_RCON,"[Ninja Modes] 0 = OFF || 1 = All || 2 = Random")
    
register_concmd("amx_ninja""cmd_ninja"ADMIN_RCON"<authid, nick or #userid> - Turn player into a Ninja")
    
register_concmd("ninja_client""client_allow"ADMIN_RCON"[Allow Players to Ninja Themeselves by saying /ninjame] 0 to Disallow || 1 to Allow")
    
register_clcmd("say /ninjame","cl_ninja_me",-1,"Ninja Yourself")
    
register_event("ResetHUD","respawn","be")
    
register_event("CurWeapon","check_weapon","b","1=1")
    
register_cvar("ninja_health""600")
    
register_cvar("ninja_visibility""50")
    
register_cvar("allow_client","0")
    
set_cvar_num("allow_client",0)
    
register_forward(FM_AlertMessage,"blocksuicide")
    
set_task(30.0,"random_event",5132,"",0,"b")


PHP Code:

public random_event(){
    if( 
mode == ){        
        
player_count get_playersnum();
        new 
maxpl get_maxplayers()
        new 
Player random_num(1maxpl)
        new 
id Player
        
if (player_count 1) {
            return 
PLUGIN_CONTINUE
        
}
        else if( 
player_count >= && is_user_connected(Player) == ){
            return 
PLUGIN_CONTINUE
        
}
        else if( 
player_count >= && is_user_connected(Player) == ){
            if ( 
g_status[Player] == true ){
                return 
PLUGIN_CONTINUE
            
}
            else if( 
g_status[Player] == false ){
                
ninja_me(id)
                return 
PLUGIN_CONTINUE
            
}
        }
    }
    else if( 
mode != 2){
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED


and
PHP Code:

public ninja_me(id){
    
g_status[id] = true
    set_user_health
(id,get_cvar_num("ninja_health"))
    
set_user_maxspeed(id,999.0
    
set_user_footsteps(id,1
    
set_user_gravity(id,0.2
    
dod_set_stamina(id,STAMINA_SET,100,100)
    
set_user_rendering(idkRenderFxGlowShell000kRenderTransAlphaget_cvar_num("ninja_visibility"))
    
    { 
        
strip_user_weapons(id
        if(
get_user_team(id) == 2){ 
            
give_item(id,"weapon_spade")
        } 
        else if(
get_user_team(id) == 1){ 
            
give_item(id,"weapon_spade")
        } 
        
        new 
name[32
        
get_user_name(id,name,31
        
client_print(0,print_chat,"[AMXX] %s is now a Ninja",name)            
        
    }
    return 
PLUGIN_HANDLED



pRED* 04-15-2007 22:29

Re: Random Player event
 
Code:
public random_event() {     if(mode!=2)         return PLUGIN_HANDLED;             new players[32],num;     get_players(players,num,"a")     new random = random_num(0, num-1)     new id = players[random]             ninja_me(id)         return PLUGIN_HANDLED }

Also you might want to add a variable to remember who the current ninja is, so you can remove their ninja powers once a new one has been selected?

And what's the point in checking what team the person is on if you do the same thing either way?...

vtsoxluvr 04-15-2007 22:50

Re: Random Player event
 
Thank you to both of you +karma

One comment for you pRED, you cant use random as a variable, so i just took out the o

that worked like a charm, hopefully Hell Pheonix will allow me to Rerelease it with my new game modes that i made for a server i play on


All times are GMT -4. The time now is 06:40.

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