AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How can I do only 1 Terrorist? (https://forums.alliedmods.net/showthread.php?t=312333)

MihaiGamerXD 11-27-2018 03:31

How can I do only 1 Terrorist?
 
Hello again. I want to know how can I do just one terrorist? Example, when the random player has been choosed, the other players except the random player will change the team to CT, like on ZP.

I tried this code:

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>

public plugin_init() {
    
register_plugin("Red's War Zombie Mode""1.0""MihaiGamerXD")
    
register_event("HLTV","onNewRound","a","1=0","2=0")
}

public 
onNewRound() {
    
set_task(1.0,"ZombieTime",0,"",0,"a",1)
}

public 
ZombieTime() {
    new 
iPlayers[32], iNum
    get_players
(iPlayers,iNum,"a")
    for (new 
0iNumi++) {
        new 
target iPlayers[random(i)]
        if (
is_user_alive(iPlayers[i])) {
            if (
iPlayers[i] != target) {
                
cs_set_user_team(iPlayers[i],CS_TEAM_CT)
            }
        }
    }


And it doesn't work! Any ideas?

shauli 11-27-2018 05:21

Re: How can I do only 1 Terrorist?
 
Move this line:
PHP Code:

new target iPlayers[random(i)] 

to before the for loop starts, because you want to get the random player only 1 time. Also change random(i) to random(iNum).

The is_user_alive condition is useless in this case because you already have flag "a" in get_players, so every player in the array is guaranteed to be alive.

In your set_task you have the flag "a", which means "repeat X amount of time" and 1 as the amount of times to repeat, which is already the default scenario with set_task, and since all your other parameters are empty you can just write it like this:
PHP Code:

set_task(1.0,"ZombieTime"


MihaiGamerXD 11-27-2018 10:05

Re: How can I do only 1 Terrorist?
 
I'm sorry, but I tried this code and it worked:
PHP Code:

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

public plugin_init() {
    
register_plugin("Red's War Zombie Mode""1.0""MihaiGamerXD")
    
register_event("HLTV","onNewRound","a","1=0","2=0")
    
register_logevent("onRoundEnd",2,"1=Round_End")
    
RegisterHam(Ham_TakeDamage,"player","onDamage",1)
}

public 
onNewRound() {
    
set_task(0.1,"ZombieTime",0,"",0,"a",1)
}

public 
ZombieTime() {
    new 
target get_random_player("a")
    
cs_set_user_team(target,CS_TEAM_T)
    
strip_user_weapons(target)
    
give_item(target,"weapon_knife")
    new 
iPlayers[32], iNumiPlayer
    get_players
(iPlayers,iNum,"a")
    for (new 
0iNumi++) {
        
iPlayer iPlayers[i]
        if (
iPlayer != target) {
            
cs_set_user_team(iPlayer,CS_TEAM_CT)
        }
    }
}

stock get_random_player(const flags[]="", const team[]="")
{
    new 
players[32], pnum;
    
get_players(playerspnumflagsteam);

    return (
pnum 0) ? players[random(pnum)] : -1;


I did this for myself! :wink:
So thank you for helping me!


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

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