AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problems with Random player (https://forums.alliedmods.net/showthread.php?t=127448)

eNz0 05-21-2010 10:11

Problems with Random player
 
Hi. When i use random player code (from tutorial && testing with PodBot)
And any other code (in this example giving weapon)
It always gives weapon not for 1 player, but for all.

Code:

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


public plugin_init()
{
    register_plugin("Random Player", "0.1", "padilha007")
    RegisterHam(Ham_Spawn, "player", "bacon_spawn", 1);
}

public bacon_spawn()
{
    new player = GetRandomPlayer("a");
    give_item(player, "weapon_m4a1")
}

GetRandomPlayer(const flags[]="", const teamORname[]="")
{
    new players[32], pnum;
    get_players(players, pnum, flags, teamORname);
   
    return (pnum > 0) ? players[random(pnum)] : 0;
}


fezh 05-21-2010 10:18

Re: Problems with Random player
 
I'm lazy to read all of your code but remember to not using stocks to give items to players. Use give_item( ) from Fun module instead.

eNz0 05-21-2010 10:30

Re: Problems with Random player
 
Ok, changed code. (same random player problem)

DruGzOG 05-21-2010 10:42

Re: Problems with Random player
 
maybe checking if the user is alive.

Hx7r 05-21-2010 10:48

Re: Problems with Random player
 
https://forums.alliedmods.net/showthread.php?t=92049

eNz0 05-21-2010 10:53

Re: Problems with Random player
 
Quote:

Originally Posted by Hx7r (Post 1186831)

Same problem with this (tryed 1h ago)

xPaw 05-21-2010 12:13

Re: Problems with Random player
 
Why you give a weapon to random player whenever any player spawns..

mysticssjgoku4 05-21-2010 14:12

Re: Problems with Random player
 
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; }

eNz0 05-21-2010 14:39

Re: Problems with Random player
 
Thanks guys, with your help, i made it work
Here is my final code (wepon giving is only example)

Code:

#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fun>
#include <hamsandwich>

new bool: g_random[33]
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)
    {
    g_random[player] = true
    set_task(0.0, "give_weapon")   
    }
}

public give_weapon(id)
{
    if(g_random[id])
    {
        give_item(id, "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;
}


mysticssjgoku4 05-21-2010 14:45

Re: Problems with Random player
 
You are welcome, but I don't even see how that code would work :S. you are setting a task, which is, I am assuming, passing 0 to the id of give_weapon. Weird


All times are GMT -4. The time now is 03:38.

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