AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Get player/bot id and randomize? (https://forums.alliedmods.net/showthread.php?t=272290)

CrazY. 09-27-2015 10:20

[HELP] Get player/bot id and randomize?
 
Hi, i'm doing a little test to give weapons to a random player, but it does not know how to do, can you help me?

PHP Code:

#include < amxmodx >
#include < fun >
#include < hamsandwich >

new weapons_test[][] = 
{
    
"weapon_m4a1",
    
"weapon_ak47",
    
"weapon_sg552"
}

public 
plugin_init() 
{
    
RegisterHam(Ham_Spawn"player""fw_HamPlayerSpawnPost"1);
}

public 
fw_HamPlayerSpawnPost(id)
{
    if(
is_user_alive(id))
    {
        new 
size_weapons random(sizeof weapons_test);
        
give_item(idweapons_test[size_weapons]);
    }



Hartmann 09-27-2015 11:19

Re: [HELP] Get player/bot id and randomize?
 
Try, if that is what you want:

PHP Code:

#include <amxmodx>
#include <fun>
#include <hamsandwich>

new weapons_test[][] = {
    
"weapon_m4a1",
    
"weapon_ak47",
    
"weapon_sg552"
}

public 
plugin_init() {
    
    
register_logevent("logevent_round_start"2"1=Round_Start"
}
public 
logevent_round_start() {
    new 
players[32], iPnumsName[32];
    new 
player;
    
get_players(playersiPnum"a");
        if(
iPnum)
        
player players[random(iPnum)];
    if(
is_user_alive(player)){
        
get_user_name(playersName31);
        
client_print(0print_chat"Random player will be %s."sName);
        new 
size_weapons random(sizeof weapons_test);
        
give_item(playerweapons_test[size_weapons]);
    }



HamletEagle 09-27-2015 11:37

Re: [HELP] Get player/bot id and randomize?
 
PHP Code:

if(is_user_alive(player)){ 

Unneeded check.

CrazY. 09-27-2015 12:12

Re: [HELP] Get player/bot id and randomize?
 
if this code of a random weapon for a random player, that's what I did.

fysiks 09-27-2015 14:43

Re: [HELP] Get player/bot id and randomize?
 
You need to start trying a little harder. There are threads that talk about getting a random player.

CrazY. 09-27-2015 15:23

Re: [HELP] Get player/bot id and randomize?
 
This is valid?

PHP Code:

#include < amxmodx >
#include < fun >
#include < cstrike >
#Include < hamsandwich >

new random_weapons[][] =
{
    
"weapon_awp",
    
"weapon_m249"
}

public 
plugin_init()
{
    
RegisterHam(Ham_Spawn"player""fw_PlayerSpawn"1);
}

public 
client_disconnect(id)
{
    if( 
g_iLastChoosenPlayer == id )
    {
        
g_iLastChoosenPlayer 0
    
}
}

public 
fw_PlayerSpawn(id)
{
    
random_player();
    new 
sizeof_weapons random(sizeof random_weapons);
    
give_item(idrandom_weapons[sizeof_weapons]);
    
cs_set_user_bpammo(idget_weaponid(random_weapons[sizeof_weapons]), 90);  
}

public 
random_player()
{
    new 
iPlayers[32], iNum
    get_players
(iPlayersiNum"ac")
    if( 
iNum <= )
    {
        return 
iPlayers[0]
    }
    new 
iRandomNum random(iNum)
    new 
iRandomPlayer iPlayersiRandomNum ]
    if( 
iRandomPlayer == g_iLastChoosenPlayer )
    {
        
iPlayersiRandomNum ] = iPlayers[ --iNum ]
        
iRandomPlayer iPlayersrandom(iNum) ]
    }
    
g_iLastChoosenPlayer  iRandomPlayer
    
return iRandomPlayer



fysiks 09-27-2015 16:15

Re: [HELP] Get player/bot id and randomize?
 
You can answer that for yourself by testing it.

CrazY. 11-12-2015 12:12

Re: [HELP] Get player/bot id and randomize?
 
Hartmann, your code worked but i have one bug.
Sometimes give a extra item after 20, 30, 40 seconds, how to fix?

PHP Code:

#include < amxmodx >
#include < zombieplague >

#define PRIMARY_WEAPONS_BIT_SUM ((1<<CSW_SCOUT) | (1<<CSW_XM1014) | (1<<CSW_MAC10) | (1<<CSW_AUG) | (1<<CSW_UMP45) | (1<<CSW_SG550) | (1<<CSW_GALIL) | (1<<CSW_FAMAS) | (1<<CSW_AWP) | (1<<CSW_MP5NAVY) | (1<<CSW_M249) | (1<<CSW_M3) | (1<<CSW_M4A1) | (1<<CSW_TMP) | (1<<CSW_G3SG1) | (1<<CSW_SG552) | (1<<CSW_AK47) | (1<<CSW_P90))

new const VERSION[] = "0.1";

new 
g_has_extra[33];
new 
human_extraid[][] =
{
    
"Rock Guitar",
    
"AKM 12",
    
"[Balrog] Ethereal"
}

public 
plugin_init()
{
    
register_plugin("[ZP] Bot Addon: Auto Buy Extras"VERSION"CrazY");
    
set_task(10.0"buy_extra", .flags="b");
}

public 
buy_extra()
{
    new 
sizeof_extras random(sizeof human_extraid);
    new 
players[32], iPnum sName[32];
    
get_players(playersiPnum"a");
    new 
player;

    if(
iPnumplayer players[random(iPnum)];

    if(
is_user_bot(player) && !g_has_extra[player] && !zp_get_user_zombie(id))
    {
        
get_user_name(playersName31);
        
drop_primary(player);
        
g_has_extra[player] = true;
        
zp_force_buy_extra_item(playerzp_get_extra_item_id(human_extraid[sizeof_extras]), 1);
        
set_hudmessage(random(255), random(255), random(255), -1.00.702.04.01.01.0);
        
show_hudmessage(0"O bot %s ganhou uma %s."sNamehuman_extraid[sizeof_extras]);
    }
}

stock drop_primary(id)
{
    new 
weapons[32], num;
    
get_user_weapons(idweaponsnum);
    for (new 
0numi++)
    {
        if (
PRIMARY_WEAPONS_BIT_SUM & (1<<weapons[i]))
        {
            static 
wname[32];
            
get_weaponname(weapons[i], wnamesizeof wname 1);
            
engclient_cmd(id"drop"wname);
        }
    }




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

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