Raised This Month: $32 Target: $400
 8% 

Storing temporary data


Post New Thread Reply   
 
Thread Tools Display Modes
addemod
Junior Member
Join Date: Feb 2016
Old 02-10-2016 , 16:36   Re: Storing temporary data
Reply With Quote #11

Quote:
Originally Posted by Mitchell View Post
What... If you are wanting to store how much damage a player has done through-out the round you're going to need a global array.
You would need to reset the array with the client in it when ever the round starts and you can display it on round end.
Yes, but I really do not understand how the ArrayLists work in SourcePawn..
An example where I insert like
Code:
//Client ID        //Damage value
"some_client_id" = "0",
"some_other_client_id" = "32",
and so on

Last edited by addemod; 02-10-2016 at 16:36.
addemod is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 02-10-2016 , 16:40   Re: Storing temporary data
Reply With Quote #12

That is not an ArrayList.

Client indexes are always in the range of 1 thru MAXPLAYERS, with the client's assigned index representing what actual server player slot they are connected to. This means that client indexes are reused. You shouldn't need a dynamic array for most things like this. Just use a regular array of regular variables.



int someArray[MAXPLAYERS+1];

someArray[someClient] = 0;
someArray[someOtherClient] = 32;

Now, when you say "client ID" are you referring to a Steam ID? The unique identifier that is linked to a given Steam account?
__________________

Last edited by ddhoward; 02-10-2016 at 16:42.
ddhoward is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 02-10-2016 , 16:54   Re: Storing temporary data
Reply With Quote #13

heres some example code that will store and then print the damage dealt at the end of the round.
code inside
Mitchell is offline
addemod
Junior Member
Join Date: Feb 2016
Old 02-11-2016 , 02:40   Re: Storing temporary data
Reply With Quote #14

Quote:
Originally Posted by Mitchell View Post
heres some example code that will store and then print the damage dealt at the end of the round.
code inside
Okay, thanks. I understand the usage of this now.

But what about saving damage dealth on each user for one client?
I mean, what if I want to print the damage the client dealt to each user on the server? I guess this is where ArrayLists come in.

Last edited by addemod; 02-11-2016 at 02:40.
addemod is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 02-11-2016 , 03:09   Re: Storing temporary data
Reply With Quote #15

No. Just make a two-dimensional array. An ArrayList is only useful if you don't know how many values you are going to need. Here, you need MAXPLAYERS+1 * MAXPLAYERS+1. There is no use for an ArrayList here, nor would an ArrayList be easy to use, as the client indexes wouldn't necessarily correspond to the ArrayList indexes.

An ArrayList is only useful over a standard array if you require a array that can change size. That's it.

PHP Code:
#pragma semicolon 1
#include <sdkhooks>
#pragma newdecls required

float gDamageTaken[MAXPLAYERS+1][MAXPLAYERS+1]; //first dimension is the attacker, second is victim

public void OnPluginStart() {
    
HookEvent("round_end"Event_RoundEnd);
}

public 
void OnClientPutInServer(int client) {
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat damageForce[3], float damagePosition[3]) {
    if(
victim && attacker && victim <= MaxClients && attacker <= MaxClients) {
        if(
IsClientInGame(victim) &&  IsClientInGame(attacker)) {
            
gDamageTaken[attacker][victim] += damage;
        }
    }
    return 
Plugin_Continue;
}


//remove damage info relating to a user who is disconnecting
public void OnClientDisconnect(int client) {
    for (
int i 1<= MaxClientsi++) {
        
gDamageTaken[client][i] = 0.0;
        
gDamageTaken[i][client] = 0.0;
    }
}


public 
Action Event_RoundEnd(Event eventchar[] namebool dontBroadcast) {
    for(
int i 1<= MaxClientsi++) {
        if(
IsClientInGame(i)) {
            for (
int x i<= MaxClientsx++) {
                if (
!= && gDamageTaken[i][x] > 0.0) {
                    
PrintToChat(client"You dealt %f damage to %N!"gDamageTaken[i][x], x);
                }
            }
        }
    }

__________________

Last edited by ddhoward; 02-11-2016 at 03:12.
ddhoward is offline
addemod
Junior Member
Join Date: Feb 2016
Old 02-11-2016 , 07:42   Re: Storing temporary data
Reply With Quote #16

Quote:
Originally Posted by ddhoward View Post
No. Just make a two-dimensional array. An ArrayList is only useful if you don't know how many values you are going to need. Here, you need MAXPLAYERS+1 * MAXPLAYERS+1. There is no use for an ArrayList here, nor would an ArrayList be easy to use, as the client indexes wouldn't necessarily correspond to the ArrayList indexes.

An ArrayList is only useful over a standard array if you require a array that can change size. That's it.

PHP Code:
#pragma semicolon 1
#include <sdkhooks>
#pragma newdecls required

float gDamageTaken[MAXPLAYERS+1][MAXPLAYERS+1]; //first dimension is the attacker, second is victim

public void OnPluginStart() {
    
HookEvent("round_end"Event_RoundEnd);
}

public 
void OnClientPutInServer(int client) {
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat damageForce[3], float damagePosition[3]) {
    if(
victim && attacker && victim <= MaxClients && attacker <= MaxClients) {
        if(
IsClientInGame(victim) &&  IsClientInGame(attacker)) {
            
gDamageTaken[attacker][victim] += damage;
        }
    }
    return 
Plugin_Continue;
}


//remove damage info relating to a user who is disconnecting
public void OnClientDisconnect(int client) {
    for (
int i 1<= MaxClientsi++) {
        
gDamageTaken[client][i] = 0.0;
        
gDamageTaken[i][client] = 0.0;
    }
}


public 
Action Event_RoundEnd(Event eventchar[] namebool dontBroadcast) {
    for(
int i 1<= MaxClientsi++) {
        if(
IsClientInGame(i)) {
            for (
int x i<= MaxClientsx++) {
                if (
!= && gDamageTaken[i][x] > 0.0) {
                    
PrintToChat(client"You dealt %f damage to %N!"gDamageTaken[i][x], x);
                }
            }
        }
    }

Thanks, this helped me really much.
I guess I am too influenced by PHP and Java Array defining
addemod 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 19:28.


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