Raised This Month: $ Target: $400
 0% 

Solved [L4D2] Arraylist get value


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kazya3
Member
Join Date: Aug 2019
Location: CN
Old 11-04-2022 , 23:28   [L4D2] Arraylist get value
Reply With Quote #1

Hello, i am trying to write a function about random respawn a dead player. Here's my code
PHP Code:
ArrayList deadPlayerList;
for (new 
1<= MaxClientsi++)
{
    if(
IsClientInGame(i))
    {
        if(
GetClientTeam(i) == && !IsPlayerAlive(i))
        {
            
deadPlayerList.Push(i);
        }
    }
}

if(
deadPlayerList.Length 0){
    new 
index GetRandomInt(0deadPlayerList.Length 1);
    new 
client deadPlayerList.Get(index);//Is the way i get the value of arrarylist correctly??
    //respawn
    
vRoundRespawn(client);
    
vTeleportToSurvivor(client);
    
vRemoveSurvivorDeathModel(client);

I know few about the arrayList
I want to foreach the players and push all the deadplayer client into the arrayList eachtime, then random the index of the arrayList to get client for Respawn. Is the way i get the value of arrarylist correctly?

Last edited by kazya3; 11-05-2022 at 20:08.
kazya3 is offline
LinLinLin
Senior Member
Join Date: Sep 2021
Old 11-05-2022 , 06:17   Re: [L4D2] Arraylist get value
Reply With Quote #2

create a arraylist by
PHP Code:
Arraylist array = new Arraylist(); 
or
PHP Code:
Arraylist array = CreateArray(); 
Just the same.You need to set an enough size of each cell when you create.
Don't forget delete if it is not a globel variable, since AdtArray inherits from Handle.

Last edited by LinLinLin; 11-05-2022 at 06:21.
LinLinLin is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 11-05-2022 , 09:35   Re: [L4D2] Arraylist get value
Reply With Quote #3

Is it possible without ArrayList:
PHP Code:
{
    
int inum;
    
int[] clients = new int[MaxClients];
    while(++
<= MaxClients) if(IsClientInGame(i) && GetClientTeam(i) == && !IsPlayerAlive(i)) clients[num++] = i;

    
clients[GetRandomInt(0num 1)];
    
vRoundRespawn(i);
    
vTeleportToSurvivor(i);
    
vRemoveSurvivorDeathModel(i);

__________________

Last edited by Grey83; 11-05-2022 at 09:37.
Grey83 is offline
kazya3
Member
Join Date: Aug 2019
Location: CN
Old 11-05-2022 , 20:04   Re: [L4D2] Arraylist get value
Reply With Quote #4

Quote:
Originally Posted by LinLinLin View Post
create a arraylist by
PHP Code:
Arraylist array = new Arraylist(); 
or
PHP Code:
Arraylist array = CreateArray(); 
Just the same.You need to set an enough size of each cell when you create.
Don't forget delete if it is not a globel variable, since AdtArray inherits from Handle.
thanks for help!
kazya3 is offline
kazya3
Member
Join Date: Aug 2019
Location: CN
Old 11-05-2022 , 20:08   Re: [L4D2] Arraylist get value
Reply With Quote #5

Quote:
Originally Posted by Grey83 View Post
Is it possible without ArrayList:
PHP Code:
{
    
int inum;
    
int[] clients = new int[MaxClients];
    while(++
<= MaxClients) if(IsClientInGame(i) && GetClientTeam(i) == && !IsPlayerAlive(i)) clients[num++] = i;

    
clients[GetRandomInt(0num 1)];
    
vRoundRespawn(i);
    
vTeleportToSurvivor(i);
    
vRemoveSurvivorDeathModel(i);

Wow,It makes things easier without ArrayList. I never thought about it that way before.Thank you!
kazya3 is offline
Reply



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 12:47.


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