Raised This Month: $ Target: $400
 0% 

[HELP] Get player/bot id and randomize?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-27-2015 , 10:20   [HELP] Get player/bot id and randomize?
Reply With Quote #1

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]);
    }

__________________









Last edited by CrazY.; 09-27-2015 at 10:21.
CrazY. is offline
Hartmann
Senior Member
Join Date: Nov 2014
Old 09-27-2015 , 11:19   Re: [HELP] Get player/bot id and randomize?
Reply With Quote #2

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]);
    }

__________________

RETAKES v1.0
github.com/alghtryer/retakes

Contact : [email protected]

BTC Donate: 1QAh1NLmeHy81LF9r8PaeGjYqHL2BBcJTx

Hartmann is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-27-2015 , 11:37   Re: [HELP] Get player/bot id and randomize?
Reply With Quote #3

PHP Code:
if(is_user_alive(player)){ 
Unneeded check.
__________________

Last edited by HamletEagle; 09-27-2015 at 11:38.
HamletEagle is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-27-2015 , 12:12   Re: [HELP] Get player/bot id and randomize?
Reply With Quote #4

if this code of a random weapon for a random player, that's what I did.
__________________








CrazY. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-27-2015 , 14:43   Re: [HELP] Get player/bot id and randomize?
Reply With Quote #5

You need to start trying a little harder. There are threads that talk about getting a random player.
__________________
fysiks is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-27-2015 , 15:23   Re: [HELP] Get player/bot id and randomize?
Reply With Quote #6

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

__________________









Last edited by CrazY.; 09-27-2015 at 20:36.
CrazY. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-27-2015 , 16:15   Re: [HELP] Get player/bot id and randomize?
Reply With Quote #7

You can answer that for yourself by testing it.
__________________
fysiks is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 11-12-2015 , 12:12   Re: [HELP] Get player/bot id and randomize?
Reply With Quote #8

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);
        }
    }

__________________









Last edited by CrazY.; 11-12-2015 at 12:21.
CrazY. 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 22:04.


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