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

Alongub, does this look correct to you? (TF2 Event question)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
404UserNotFound
BANNED
Join Date: Dec 2011
Old 03-12-2013 , 21:50   Alongub, does this look correct to you? (TF2 Event question)
Reply With Quote #1

(I'm currently out driving around town, but I'll be back in a short while!)

So I've recently gotten into the teamplay_point_capture event, and getting it set up to work properly. Here's what I've got going on in the code below:

To begin, if the "team bonus credits" CVAR is enabled, when the point is captured, the entire team gets a credit bonus, the amount of which is determined by the team bonus credits CVAR.

If that CVAR isn't enabled, we continue on anyway, and check to see how many players had just captured the point, then we give those players an amount of credits, determined by the respective CVAR.


The only reason I'm having trouble with this in particular is that i<x stuff, and the way it's set up. By using "client" in the latter part of the code, will that just make the plugin give ONE player credits? The way I'm 'reading' the code, I think in the end, "client" actually ends up "=" that "x" thing.

Does this look correct? I *think* it looks correct, I'm just not 100% sure. This is by far the most advanced thing I've ever coded

PHP Code:
public Event_CapturedPoint(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (
g_bIsCreditsActive && g_bIsCreditsEnabled)
    {
        if (
g_bTeamPointCapBonus)
        {
            new 
team GetEventInt(event"team");
            new 
String:teamname[MAX_LINE_WIDTH];
            
GetTeamName(teamteamnamesizeof(teamname));
            
            for (new 
i=1i<=MaxClientsi++)
            {
                if (
IsClientInGame[i] == true)
                {
                    new 
teamcredits GetConVarInt(Credits_CapturePointTeam);
                    
Store_GiveCreditsToUsers(Store_GetClientAccountID(i), teamcredits);
            
                    if (
GetConVarInt(Credits_CapturePointTeam) > 1)
                    {
                        
PrintToChat(i"%s%t"STORE_PREFIX"Capture  Point Team Bonus"teamnameteamcreditsg_strCurrencyName);
                    }
                }
            }
        }
        
        
decl String:g_strPointCappers[MAXPLAYERS+1] = "";
        
GetEventString(event"cappers"g_strPointCappersMAXPLAYERS);
        new 
strlen(g_strPointCappers);
        
//PrintToChatAll("Point capped by %i total players!", x);

        
for(new i=0i<xi++)
        {
            new 
client g_strPointCappers{i}; //Is the "i" supposed to be in brackets, or parenthesis?
            
if (IsClientInGame[client] == true)
            {
                new 
credits GetConVarInt(Credits_CapturePointPlayer);
                
Store_GiveCreditsToUsers(Store_GetClientAccountID(client), credits);
                
                if (
GetConVarInt(Credits_CapturePointPlayer) > 1)
                {
                    
PrintToChat(client"%s%t"STORE_PREFIX"Capture Point Player"creditsg_strCurrencyName);
                }
            }
        }
    }


Last edited by 404UserNotFound; 03-12-2013 at 21:52.
404UserNotFound is offline
eXemplar
Member
Join Date: Feb 2013
Old 03-12-2013 , 23:20   Re: Alongub, does this look correct to you? (TF2 Event question)
Reply With Quote #2

Something similar to this might be better
Code:
new team = GetEventInt(event, "team");
new accountIds[MaxClients];
new count = 0;
for (new client = 1; client <= MaxClients; client++) 
{
	if (GetClientTeam(client) == team && IsClientInGame(client) && !IsFakeClient(client) && !IsClientObserver(client))
	{
		accountIds[count] = Store_GetClientAccountID(client);
		count++;
	}
}
Store_GiveCreditsToUsers(accountIds, count, GetConVarInt(Credits_CapturePointTeam));

count = 0;
decl String:cappers[MAXPLAYERS+1];
if (GetEventString(event, "cappers", cappers, MAXPLAYERS) > 0)
{
	new len = strlen(cappers);
	for(new i = 0; i < len; i++)
	{
		new client = cappers{i};
		if (IsClientInGame(client) && !IsFakeClient(client) && !IsClientObserver(client))
		{
			accountIds[count] = Store_GetClientAccountID(client);
			count++;
		}
	}
	Store_GiveCreditsToUsers(accountIds, count, GetConVarInt(Credits_CapturePointPlayer));
}

Last edited by eXemplar; 03-12-2013 at 23:23.
eXemplar is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 03-13-2013 , 00:35   Re: Alongub, does this look correct to you? (TF2 Event question)
Reply With Quote #3

Quote:
Originally Posted by eXemplar View Post
Something similar to this might be better
Code:
new team = GetEventInt(event, "team");
new accountIds[MaxClients];
new count = 0;
for (new client = 1; client <= MaxClients; client++) 
{
    if (GetClientTeam(client) == team && IsClientInGame(client) && !IsFakeClient(client) && !IsClientObserver(client))
    {
        accountIds[count] = Store_GetClientAccountID(client);
        count++;
    }
}
Store_GiveCreditsToUsers(accountIds, count, GetConVarInt(Credits_CapturePointTeam));

count = 0;
decl String:cappers[MAXPLAYERS+1];
if (GetEventString(event, "cappers", cappers, MAXPLAYERS) > 0)
{
    new len = strlen(cappers);
    for(new i = 0; i < len; i++)
    {
        new client = cappers{i};
        if (IsClientInGame(client) && !IsFakeClient(client) && !IsClientObserver(client))
        {
            accountIds[count] = Store_GetClientAccountID(client);
            count++;
        }
    }
    Store_GiveCreditsToUsers(accountIds, count, GetConVarInt(Credits_CapturePointPlayer));
}
Beautiful. This shall be added right away. Thank you

I think I'lll modify the "if (IsClientInGame(client) && !IsFakeClient(client) && !IsClientObserver(client))" line because I've got that "new IsClientInGame[client]" thing that I'm using...either that, or I'll just remove my method, and switch every instance of my "IsClientInGame" over to the one you've put.
404UserNotFound is offline
eXemplar
Member
Join Date: Feb 2013
Old 03-13-2013 , 00:41   Re: Alongub, does this look correct to you? (TF2 Event question)
Reply With Quote #4

If you have a few instances of where you check for the same stuff you could try something along the lines of,
Code:
bool:IsValidClient(client)
{
	return IsClientInGame(client) && !IsFakeClient(client) && !IsClientObserver(client);
}
eXemplar is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 03-13-2013 , 01:10   Re: Alongub, does this look correct to you? (TF2 Event question)
Reply With Quote #5

Quote:
Originally Posted by eXemplar View Post
If you have a few instances of where you check for the same stuff you could try something along the lines of,
Code:
bool:IsValidClient(client)
{
    return IsClientInGame(client) && !IsFakeClient(client) && !IsClientObserver(client);
}
Ooh, I'll definitely use that. I'm surprised I didn't think of that o_o

I've got like 20 different iterations of IsValidClient saved in a text file. Here's a good example that checks for things like if a player is coaching, or if they are the Replay thing, or if they are a Source TV client.

PHP Code:
stock bool:IsValidClient(ibool:replay true)
{
    if (
<= || MaxClients || !IsClientInGame(i) || GetEntProp(iProp_Send"m_bIsCoaching"))
    {
        return 
false;
    }
    if (
replay && (IsClientSourceTV(i) || IsClientReplay(i)))
    {
        return 
false;
    }
    return 
true;


Last edited by 404UserNotFound; 03-13-2013 at 01:10.
404UserNotFound is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 03-15-2013 , 18:48   Re: Alongub, does this look correct to you? (TF2 Event question)
Reply With Quote #6

So I just ran a test compile to make sure everything I've done so far doesn't cause any issues, and to make sure I've not made any typos.

I got everything fixed up except for this one tricky little S.O.B. of an error that I can't fix.

In the code below, I've gotten 3 errors about this: "Local variable "client" shadows a variable at a preceding level". I've marked them with comments. I have no clue how to fix this and I've been googling around now for awhile and could not find any results.
PHP Code:
public Event_CapturedPoint(Handle:event, const String:name[], bool:dontBroadcast)
{    
    if (
g_bIsCreditsActive && g_bIsCreditsEnabled)
    {
        new 
client GetEventInt(event"player");
        new 
team GetEventInt(event"team");
        new 
String:teamname[MAX_LINE_WIDTH];
        
GetTeamName(teamteamnamesizeof(teamname));
        new 
accountIds[MaxClients];
        new 
count 0;
        new 
credits_player GetConVarInt(Credits_CapturePointPlayer);
        new 
credits_team GetConVarInt(Credits_CapturePointTeam);
        new 
displaymsg GetConVarInt(Credits_DisplayMessages);
        
        if (
credits_team 1)
        {
            for (new 
client 1client <= MaxClientsclient++) // Foreshadows here.
            
{
                if (
GetClientTeam(client) == team && IsValidClient(client))
                {
                    
accountIds[count] = Store_GetClientAccountID(client);
                    
count++;
                }
            }
            
Store_GiveCreditsToUsers(accountIdscountcredits_team);
            
            if (
displaymsg == 1)
            {
                
PrintToChat(team"%s%t"STORE_PREFIX"Capture Point Team Bonus"teamnamecredits_teamg_strCurrencyName);
            }
        }

        if (
credits_player 1)
        {
            
count 0;
            
decl String:cappers[MAXPLAYERS+1];
            if (
GetEventString(event"cappers"cappersMAXPLAYERS) > 0)
            {
                new 
len strlen(cappers);
                for(new 
0leni++)
                {
                    new 
client cappers{i}; // Foreshadows here.
                
                    
if (IsValidClient(client))
                    {
                        
accountIds[count] = Store_GetClientAccountID(client);
                        
count++;
                    }
                }
                
Store_GiveCreditsToUsers(accountIdscountcredits_player);
                
                if (
displaymsg == 1)
                {
                    
PrintToChat(client"%s%t"STORE_PREFIX"Capture Point Player"credits_playerg_strCurrencyName);
                }
            }
        }
    }
}


public 
Event_CapturedFlag(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (
g_bIsCreditsActive && g_bIsCreditsEnabled)
    {
        new 
client GetEventInt(event"player");
        new 
carrier GetEventInt(event"carrier");
        new 
team GetEventInt(event"team");
        new 
carrierid GetClientOfUserId(carrier);
        new 
String:carriername[MAX_LINE_WIDTH];
        new 
String:teamname[MAX_LINE_WIDTH];
        
GetClientName(carrieridcarriernamesizeof(carriername));
        
GetTeamName(teamteamnamesizeof(teamname));

        new 
count 0;
        new 
accountIds[MaxClients];
        
        new 
credits_grabbed GetConVarInt(Credits_FlagGrabbed);
        new 
credits_defended GetConVarInt(Credits_FlagDefended);
        new 
credits_player GetConVarInt(Credits_FlagCapturedPlayer);
        new 
credits_team GetConVarInt(Credits_FlagCapturedTeam);
        new 
displaymsg GetConVarInt(Credits_DisplayMessages);
        new 
displaynames GetConVarInt(Credits_DisplayNames);
        
        switch(
GetEventInt(event"eventtype"))
        {
            case 
1:
            {
                if (
credits_grabbed 1)
                {
                    if (
IsValidClient(client))
                    {
                        
Store_GiveCredits(Store_GetClientAccountID(client), credits_grabbed);
                        
                        if (
displaymsg == 1)
                        {
                            
PrintToChat(client"%s%t"STORE_PREFIX"Flag Grabbed"credits_grabbedg_strCurrencyName);
                        }
                    }
                }
            }
            case 
2:
            {
                if (
credits_player 1)
                {
                    
Store_GiveCredits(Store_GetClientAccountID(client), credits_player);
                    
                    if (
displaymsg == 1)
                    {
                        
PrintToChat(client"%s%t"STORE_PREFIX"Flag Captured Player"credits_playerg_strCurrencyName);
                    }
                }
                
                if (
credits_team 1)
                {
                    for (new 
client 1client <= MaxClientsclient++) // Foreshadows here.
                    
{
                        if (
GetClientTeam(client) == team && IsValidClient(client))
                        {
                            
accountIds[count] = Store_GetClientAccountID(client);
                            
count++;
                        }
                    }
                    
Store_GiveCreditsToUsers(accountIdscountGetConVarInt(Credits_CapturePointTeam));
                    
                    if (
displaymsg == 1)
                    {
                        
PrintToChat(team"%s%t"STORE_PREFIX"Flag Captured Team Bonus"teamnamecredits_teamg_strCurrencyName);
                    }
                }
            }
            case 
3:
            {
                if (
credits_defended 1)
                {
                    
Store_GiveCredits(Store_GetClientAccountID(client), credits_defended);
                    
                    if (
displaymsg == 1)
                    {
                        if (
displaynames == 1)
                        {
                            
PrintToChat(client"%s%t"STORE_PREFIX"Flag Defended Named"credits_grabbedg_strCurrencyNamecarriername);
                        }
                        else
                        {
                            
PrintToChat(client"%s%t"STORE_PREFIX"Flag Defended"credits_grabbedg_strCurrencyName);
                        }
                    }
                }
            }
        }
    }
    return;

404UserNotFound is offline
eXemplar
Member
Join Date: Feb 2013
Old 03-15-2013 , 20:52   Re: Alongub, does this look correct to you? (TF2 Event question)
Reply With Quote #7

You shouldn't use two variables named "client" in the same scope.
new client = GetEventInt(event, "player");
for (new client = 1; client <= MaxClients; client++) // Foreshadows here.
Make the for loop client variable i or something

Last edited by eXemplar; 03-15-2013 at 20:53.
eXemplar is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 03-15-2013 , 21:45   Re: Alongub, does this look correct to you? (TF2 Event question)
Reply With Quote #8

Quote:
Originally Posted by eXemplar View Post
You shouldn't use two variables named "client" in the same scope.
new client = GetEventInt(event, "player");
for (new client = 1; client <= MaxClients; client++) // Foreshadows here.
Make the for loop client variable i or something
Good idea!
404UserNotFound 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 14:58.


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