Raised This Month: $51 Target: $400
 12% 

[L4D] Checking if any clients are tank


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-13-2009 , 11:18   [L4D] Checking if any clients are tank
Reply With Quote #1

Ok, so in the tank death event I need to check if any other clients ingame are currently a tank (to support multi-tank plugins).

I know I'll use a for loop to loop through all of the clients, but what do I check for? Details please lol.
Dragonshadow is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-13-2009 , 12:02   Re: [L4D] Checking if any clients are tank
Reply With Quote #2

Nevermind, I think this works:

PHP Code:
{
//  A Tank just died, check if any are still alive
//  LOOP TIEM LOL
    
for (new i=1i<=MaxClientsi++)
    {        
    
//  Are the clients on infected?
        
if (GetClientTeam(i) == 3)
        {
        
//  Yup, now check the model
            
new String:class[100];
            
GetClientModel(i, class, sizeof(class));
        
//  Is it the tank model?
            
if (StrContains(class, "tank"false) != -1)
            {
            
//  Yes, are they alive?
                
if (IsPlayerAlive(i))
                {
                
//  Yep, still alive
                    
tanklive 1;
                }
                else if (!
IsPlayerAlive(i))
                {
                
//  Nope, they're all dead
                    
tanklive 0;
                }
            }
        }
    }

Though I'm pretty sure there is a less-hacky way of checking rather than checking the model.
Dragonshadow is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-13-2009 , 12:52   Re: [L4D] Checking if any clients are tank
Reply With Quote #3

On Whatever Spawn event, take note of their HP, if it's the Tank style HP, store to an array saying it's the tank?

Heck, wouldn't use a for loop; limit it to known infected players (or just limit it to the spawn event of an infected - so much easier).

So in short;

Code:
//pseudo design code

On Spawn Of Infected
Check Tank Model
If Tank, Store to TankArray

On Death (of an infected?)
Check Array, If Tank, Remove (they died)

On Disconnect
Check Array, If Tank, Remove (they left)
No need for any resource hogging for loop.

Last edited by Flynn; 09-13-2009 at 12:54.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Flynn
Senior Member
Join Date: Sep 2009
Old 09-13-2009 , 13:55   Re: [L4D] Checking if any clients are tank
Reply With Quote #4

Or even simplier...

tank_spawn

Hook that event, store the ID and you're away. Done.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-13-2009 , 13:55   Re: [L4D] Checking if any clients are tank
Reply With Quote #5

My plugin modifies tank hp, and there is a tank spawn event.

I'm doing this so that the plugin will still work when you have multiple tanks alive at once.

Besides this loop only fires when the tank dies, and its not resource hogging.

Storing the id of the player who got tank to start with wont work as tank control can switch...
Dragonshadow is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-13-2009 , 14:01   Re: [L4D] Checking if any clients are tank
Reply With Quote #6

I thought about something with an entity index but I'm not quite sure how to get/mess with those.
Dragonshadow is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-13-2009 , 14:03   Re: [L4D] Checking if any clients are tank
Reply With Quote #7

Quote:
Originally Posted by Dragonshadow View Post
Storing the id of the player who got tank to start with wont work as tank control can switch...
If you know what event causes the switch (or what condition), or you can intercept it, then you can update it.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-13-2009 , 15:23   Re: [L4D] Checking if any clients are tank
Reply With Quote #8

I'm not sure but I don't think an event fires when the switch happens.

What I could do is get the entity index of the actual tank and store it, I just don't know how to get an ent index, nor do I know what I'd do after I store it. The idea is to support multiple tanks, storing one id to check isn't going to do anything, and I can't store multiples without hardcoding a limit.
Dragonshadow is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 09-13-2009 , 16:36   Re: [L4D] Checking if any clients are tank
Reply With Quote #9

Don't use tank_spawn. It fires way too often to be reliable - on a spawned bot tank, on the human who gets control, on whoever gets it if a tank gets frustrated...

Use player_spawn instead and check for the tank model. You could use Entprop m_zombieclass to check for being tank but i dont know which value a tank would have, you'd have to find that out yourself.

Also, i dont think a model check loop is too intensive.
AtomicStryker is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-13-2009 , 16:46   Re: [L4D] Checking if any clients are tank
Reply With Quote #10

Quote:
Originally Posted by AtomicStryker View Post
Don't use tank_spawn. It fires way too often to be reliable - on a spawned bot tank, on the human who gets control, on whoever gets it if a tank gets frustrated...
Ahh ok

tank_death only fires when a tank actually dies right?
Dragonshadow 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 17:18.


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