Raised This Month: $ Target: $400
 0% 

[HELP]Save Group Damage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-18-2015 , 08:01   Re: [HELP]Save Group Damage
Reply With Quote #1

Everything works perfectly except for when a new member is added to the group? Could you just set g_PartyData[id][Damage_In_Party] to the party damage?
__________________
Bugsy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 10-18-2015 , 08:15   Re: [HELP]Save Group Damage
Reply With Quote #2

The way i got it partialy working was using an Array like this , with the multi dimensional array i couldn't get anything done...

PHP Code:
new g_PartyDamage[33
Then i made a loop inside take damage and i store all the damage into g_PartyDamage[33] like this

PHP Code:
new Players[32], user
        get_party_index
(attackerPlayers)
        for(new 
ig_PartyData[attacker][Amount_In_Party]; i++)
        {
            
user Players[i]
            if(
is_user_alive(attacker) && !zp_get_user_zombie(attacker))
            {
                
g_PartyDamage[user] += floatround(damage)
           
                if(
g_PartyDamage[user] >= get_pcvar_num(cvar_damage_reward))
                {
                    
zp_set_user_ammo_packs(userzp_get_user_ammo_packs(user) + get_pcvar_num(cvar_ammo_reward))
                    
g_PartyDamage[user] -= g_PartyDamage[user]
                    
                }
            }
        } 
Everything worked fine, the damage of the players within the group was stored togheter inside g_PartyDamage[33]

But when a new player joined, for him the PartyDamage displayed on the hud was 0 ...

I tried multi dimensional arrays, normal arrays, anything i could of seen and think off for 3-4 days... then i felt like i wanted to kill myself and came here...

Last edited by Depresie; 10-18-2015 at 08:19.
Depresie is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-18-2015 , 08:25   Re: [HELP]Save Group Damage
Reply With Quote #3

But as I said above, just assign the party damage to that players array index.

PHP Code:
new PartyDamage g_PartyDataa player who is already a member ][Damage_In_Party]
g_PartyData[id][Damage_In_Party] = PartyDamage 
__________________
Bugsy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 10-18-2015 , 10:01   Re: [HELP]Save Group Damage
Reply With Quote #4

do i still need the loop at take damage?

btw i remember i tried like that, and didnt work, i dont remember how it behaved exactly, since im about 3 days trying to figure out the right way and i tried many things >.> ...

Last edited by Depresie; 10-18-2015 at 10:05.
Depresie is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-18-2015 , 11:52   Re: [HELP]Save Group Damage
Reply With Quote #5

Here's something you can work with. This needs more work, but it's a good starting point for what I think you are trying to do:

Edit: Made minor fixes and added full commenting.
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>

new const Version[] = "0.1b";

const 
MAX_TEAMS 10;     //The most teams the plugin can support.
const UNASSIGNED = -1;     //This indicates that the player is not on a team.

enum TeamInfo
{
    
TeamName20 ],
    
MemberCount,
    
TotalDamage,
    
TeamCaptain
}
new 
g_TeamsMAX_TEAMS ][ TeamInfo ];
new 
g_PlayerTeamMAX_PLAYERS ] = { UNASSIGNED , ... };

public 
plugin_init() 
{
    
register_plugin"Team Example" Version "bugsy" );
    
    
RegisterHamHam_TakeDamage "player" "TakeDamage"  );
    
    
register_concmd"amx_createteam" "CreateTeam" ADMIN_ALL "<team name> - Create a team" );
    
register_concmd"amx_addmember" "AddMember" ADMIN_ALL "<player name> - Add member to your team" );
    
register_concmd"amx_removemember" "RemoveMember" ADMIN_ALL "<player name> - Remove member from your team" );
}

public 
client_disconnectid )
{
    
//Disconnecting player is on a team and the player is a team captain
    
if ( ( g_PlayerTeamid ] != UNASSIGNED ) && ( id == g_Teamsg_PlayerTeamid ] ][ TeamCaptain ] ) )
    {
        
//Tell the team that the captain has disconnected?
        
        //Set team captain to unassigned since player disconnected
        
g_Teamsg_PlayerTeamid ] ][ TeamCaptain ] = UNASSIGNED;
    }

    
//Set disconnecting player team to unassigned
    
g_PlayerTeamid ] = UNASSIGNED;
}
        
public 
CreateTeamid )
{
    new 
iFindEmptySlot szArg32 ];
    
    if ( !
read_argvszArg charsmaxszArg ) ) )
    {
        
console_printid "* You must specify a team name!" );
        return 
PLUGIN_HANDLED;
    }
    
    
//Loop through all team slots and see if any are available for use. To do this we are checking
    //the first character of the name string, if it is EOS (end of string constant) then it is 
    //available. When this is found, the loop is exited and iFindEmptySlot is the index of the slot.
    
for ( iFindEmptySlot iFindEmptySlot MAX_TEAMS iFindEmptySlot++ )
    {
        
//Check if first character of name string is blank
        
if ( g_TeamsiFindEmptySlot ][ TeamName ][ ] == EOS )
            break;
    }
    
    
//This means the loop cycled eveyr slot and no expty slots are available
    
if ( iFindEmptySlot == ( MAX_TEAMS ) )
    {
        
console_printid "* Sorry, no more teams can be created." );
        return 
PLUGIN_HANDLED;
    }
    
    
//Team can be created. Copy the string that the user typed into the teams array slot in the 
    //TeamName field.
    
copyg_TeamsiFindEmptySlot ][ TeamName ] , charsmaxg_Teams[][ TeamName ] ) ,  szArg );
    
    
console_printid "* Team [%s] has been created! Please add members." szArg );
    
    
//Team was just created so it only has 1 member which is the creator
    
g_TeamsiFindEmptySlot ][ MemberCount ] = 1;
    
    
//Set team captain to the creator
    
g_TeamsiFindEmptySlot ][ TeamCaptain ] = id;
    
    
//Set players team index to the slot that was just used to create the team
    
g_PlayerTeamid ] = iFindEmptySlot;

    return 
PLUGIN_HANDLED;
}

public 
AddMemberid )
{
    new 
szArg32 ] ,iNewPlayer;
    
    if ( !
read_argvszArg charsmaxszArg ) ) )
    {
        
console_printid "* You must specify a player name!" );
        return 
PLUGIN_HANDLED;
    }
    
    if ( !( 
iNewPlayer cmd_targetid szArg ) ) )
        return 
PLUGIN_HANDLED;
    
    
//Player is trying to add a member to his team but he is not on a team.
    
if ( g_PlayerTeamid ] == UNASSIGNED )
    {
        
console_printid "* You are not on a team." );
        return 
PLUGIN_HANDLED;
    }
    
    
//Player is trying to add a member to his team but he is not the captain.
    
if ( id != g_Teamsg_PlayerTeamid ] ][ TeamCaptain ] )
    {
        
console_printid "* You must be the captain to add members." );
        return 
PLUGIN_HANDLED;
    }
    
    
//The player being added is already on a team.
    
if ( g_PlayerTeamiNewPlayer ] != UNASSIGNED )
    {
        
console_printid "* That player is already on a team, he must leave his team first." );
        return 
PLUGIN_HANDLED;
    }
    
    
//Player successfully added to team
    
get_user_nameiNewPlayer szArg charsmaxszArg ) );
    
console_printid "* %s has joined the [%s] team!" szArg g_Teamsg_PlayerTeamid ] ][ TeamName ] );
    
    
//Set players team index to the same team as the player using this command.
    
g_PlayerTeamiNewPlayer ] = g_PlayerTeamid ];
    
    
//Increase the team count by 1.
    
g_Teamsg_PlayerTeamid ] ][ MemberCount ]++;
    
    return 
PLUGIN_HANDLED;
}

public 
RemoveMemberid )
{
    new 
szArg32 ] , iPlayer;
    
    if ( !
read_argvszArg charsmaxszArg ) ) )
    {
        
console_printid "* You must specify a player name!" );
        return 
PLUGIN_HANDLED;
    }
    
    if ( !( 
iPlayer cmd_targetid szArg ) ) )
        return 
PLUGIN_HANDLED;
    
    
//To remove a team member the player must be either the captain or the player who wants to leave the team.
    
if ( ( id != g_Teamsg_PlayerTeamid ] ][ TeamCaptain ] ) && ( id != iPlayer ) )
    {
        
console_printid "* You must be the leaving member or the team captain to remove members." );
        
        return 
PLUGIN_HANDLED;
    }
    
    
//The player being removed is not on a team.
    
if ( g_PlayerTeamiPlayer ] == UNASSIGNED 
    {
        
console_printid "* That player is not on a team" );
        
        return 
PLUGIN_HANDLED;    
    }
    
    
get_user_nameiPlayer szArg charsmaxszArg ) );
    
    
//If the captain is online, inform him that a player left his team.
    
if ( g_Teamsg_PlayerTeamiPlayer ] ][ TeamCaptain ] != UNASSIGNED )
    {
        
console_printg_Teamsg_PlayerTeamiPlayer ] ][ TeamCaptain ] , "* %s has left the [%s] team!" szArg g_Teamsg_PlayerTeamiPlayer ] ][ TeamName ] );
    }

    
console_printiPlayer "* You have left the [%s] team!" g_Teamsg_PlayerTeamiPlayer ] ][ TeamName ] );
    
    
//Reduce team count by 1
    
g_Teamsg_PlayerTeamiPlayer ] ][ MemberCount ]--;
    
    
//Set players team index to unassigned
    
g_PlayerTeamiPlayer ] = UNASSIGNED;

    return 
PLUGIN_HANDLED;
}

public 
TakeDamageiVictim iInflictor iAttacker Float:fDamage DmgBits )
{
    
//We only want to add total damage to players who are on a team
    
if ( g_PlayerTeamiAttacker ] != UNASSIGNED )
    {
        
//This adds damage to the correct team by indexing the teams variable using the
        //players team index variable.
        
        //If the team was created in slot 3 then g_PlayerTeam[ iAttacker ] equals 3
        //You then pass this value into g_Teams[] to get to the correct team slot to then
        //add the damage.
        
g_Teamsg_PlayerTeamiAttacker ] ][ TotalDamage ] += floatroundfDamage );
    
        
TeamDamagePrintiAttacker );
    }
}

public 
TeamDamagePrintiAttacker )
{
    new 
iPlayers32 ] , iNum iPlayer;
    
    
get_playersiPlayers iNum "ch" );
    
    
//Loop through all players and announce damage recorded for players on the same team as the attacker.
    
for ( new iNum i++ )
    {
        
iPlayer iPlayers];
        
        if ( 
g_PlayerTeamiPlayer ] == g_PlayerTeamiAttacker ] )
        {
            
client_printiPlayer print_chat "* Your team [%s] now has %d total damage!" g_Teamsg_PlayerTeamiAttacker ] ][ TeamName ] , g_Teamsg_PlayerTeamiAttacker ] ][ TotalDamage ] );
        }
    }

__________________

Last edited by Bugsy; 10-19-2015 at 19:37. Reason: Minor fixes
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-18-2015 , 12:06   Re: [HELP]Save Group Damage
Reply With Quote #6

I just fixed something so if you've already compiled, update the code and recompile.
__________________
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-18-2015 , 13:03   Re: [HELP]Save Group Damage
Reply With Quote #7

Yeah, we are in pawn so we are talking about pawn. That's what I said, a tag is just a tag. People come here to learn this and not c++(for example) and we have to make things clear.
__________________

Last edited by HamletEagle; 10-18-2015 at 13:04.
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-18-2015 , 14:44   Re: [HELP]Save Group Damage
Reply With Quote #8

Quote:
Originally Posted by HamletEagle View Post
Yeah, we are in pawn so we are talking about pawn. That's what I said, a tag is just a tag. People come here to learn this and not c++(for example) and we have to make things clear.
Yes dude, but I was thinking the bigger picture here. In Pawn it is improper and you should not assign values to something tagged as a bool.

Yes, wickedd's statement was false from strictly a Pawn perspective. But from a general programming standpoint he is correct. I think people should learn things the proper way from the beginning. Yes, AMX-X is under Pawn, but suppose a year from now he is dabbling in something else and attempts to assign values to a bool. I'm sure there are plenty that venture on past Pawn.
__________________

Last edited by Bugsy; 10-18-2015 at 14:58.
Bugsy is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 10-18-2015 , 15:03   Re: [HELP]Save Group Damage
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
Yes dude, but I was thinking the bigger picture here. In Pawn it is improper and you should not assign values to something tagged as a bool.

Yes, wickedd's statement was false from strictly a Pawn perspective. But from a general programming standpoint he is correct. I think people should learn things the proper way from the beginning. Yes, AMX-X is under Pawn, but suppose a year from now he is dabbling in something else and attempts to assign values to a bool. I'm sure there are plenty that venture on past Pawn.
@Bugsy
+1 That's point I was trying to make.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 10-18-2015 , 13:19   Re: [HELP]Save Group Damage
Reply With Quote #10

i will try again tomorow to see if i manage to get it done... thanks

i will first try to see if i can do it in the script i have, after i will try to finish bugsy's code if i cant get it right

Last edited by Depresie; 10-18-2015 at 13:21.
Depresie 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 22:03.


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