I too question why you give random players weapons only when a person spawns.
Your code was giving an m4 to id0, which would not work anyhow, but to be safe I threw a check in there. I also threw a check in there to make sure the person is alive. Test this code, but honestly not sure if it will work, been years since I coded something like this in pawn.
Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fun>
#include <hamsandwich>
public plugin_init()
{
register_plugin("Random Player", "0.1", "padilha007")
RegisterHam(Ham_Spawn, "player", "bacon_spawn", 1);
}
public bacon_spawn()
{
new player;
if((player = GetRandomPlayer("a")) > 0)
{
give_item(player, "weapon_m4a1");
}
}
GetRandomPlayer(const flags[]="", const teamORname[]="")
{
new players[32], pnum;
get_players(players, pnum, flags, teamORname);
new selected = 0;
while( is_user_alive((players[(selected = random(pnum))])))
{
return players[selected];
}
return 0;
}
__________________