Raised This Month: $ Target: $400
 0% 

Solved Save/Get multiple different values in the same variable per player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sursista
Senior Member
Join Date: Jul 2010
Location: Spain
Old 02-17-2022 , 08:28   Save/Get multiple different values in the same variable per player
Reply With Quote #1

Hello, I'm doing an assist system for the ZM mod, the problem occurs when several players get an assist from the same zombie. What happens is that the variable:

PHP Code:
name[victim][attacker] = true 
the attacker is replaced by the new attacker, and I can't save multiple variables for both the victim and the attacker to get the correct player id (when the player go dead). I am currently doing a:

PHP Code:
for(new 1<= 32i++) 
to check how many attackers have gotten an assist when the victim dies. Sometimes it works fine and gives you the name of that player, other times you don't even get assist or you get the name of a different victim (who didn't get assist)

Last edited by sursista; 02-18-2022 at 08:23.
sursista is offline
Send a message via MSN to sursista Send a message via Skype™ to sursista
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-17-2022 , 14:19   Re: Save/Get multiple different values in the same variable per player
Reply With Quote #2

I don't see a problem there.

Other than that, show the full code so we can see how you're using it.
__________________

Last edited by OciXCrom; 02-17-2022 at 14:51.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
sursista
Senior Member
Join Date: Jul 2010
Location: Spain
Old 02-17-2022 , 14:58   Re: Save/Get multiple different values in the same variable per player
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
I don't see a problem there.

Other than that, show the full code so we can see how you're using it.
This is a small example of what I'm trying to do, again it works, but only 70% of the time, the other 30% I either don't get assists or the name of the assist belongs to a different player (which did not get assistance)

PHP Code:
public fw_TakeDamage(victiminflictorattackerFloat:damagedamage_type)
{
    if (
victim == attacker || !is_user_alive(attacker) || !is_user_alive(victim))
        return
        
    if(!
g_hp_victim[victim])
        
g_hp_victim[victim] = get_user_health(victim) / 3
    
    
if(zp_core_is_zombie(attacker
    && !
zp_class_survivor_get(victim))
    {    
        
g_fDamage_Human[victim][attacker] += damage;
        if(
g_fDamage_Human[victim][attacker] >= g_hp_victim[victim] && !g_victim_done[victim][attacker])
        {
            
g_count_victim_human[attacker]++;
            
g_victim_done[victim][attacker] = true;
            
            new 
name[32]
            
get_user_name(victimnamecharsmax(name))
            
            
client_print(idprint_chat"You got a assist of %s"name)
        }
    }
    
    if(!
zp_core_is_zombie(attacker)
    && !
zp_core_is_first_zombie(victim)
    && !
zp_class_nemesis_get(victim))
    {
        
g_fDamage_Zombie[victim][attacker] += damage;
        if(
g_fDamage_Zombie[victim][attacker] >= g_hp_victim[victim] && !g_victim_done[victim][attacker])
        {
            
g_count_victim_zombie[attacker]++;
            
g_victim_done[victim][attacker] = true;
            
            new 
name[32]
            
get_user_name(victimnamecharsmax(name))
            
            
client_print(idprint_chat"You got a assist of %s"name)
        }
    }
}

public 
fw_Killed(victimattackershouldgib)
{
    if (
victim == attacker || !is_user_connected(attacker))
        return
        
    if(
zp_core_is_zombie(attacker
    && 
g_count_victim_human[attacker]
    && !
zp_class_survivor_get(victim))
    {    
        if(
g_count_victim_human[attacker])
            
g_count_victim_human[attacker]--;
        
        
g_fDamage_Human[victim][attacker] = 0.0;
        
g_he_attacker[attacker] = true;
    }
    
    if(!
zp_core_is_zombie(attacker)
    && 
g_count_victim_zombie[attacker]
    && !
zp_core_is_first_zombie(victim)
    && !
zp_class_nemesis_get(victim))
    {    
        if(
g_count_victim_zombie[attacker])
            
g_count_victim_zombie[attacker]--;
        
        
g_fDamage_Zombie[victim][attacker] = 0.0;
        
g_he_attacker[attacker] = true;
    }
    
    for(new 
id 1id <= 32id++)
    {
        if(
is_user_alive(id)
        && 
zp_core_is_zombie(id)
        && !
g_he_attacker[id]
        && 
g_count_victim_human[id]
        && 
g_victim_done[victim][id]
        && !
zp_class_survivor_get(victim))
        {    
            new 
name[32]
            
get_user_name(victimnamecharsmax(name))
                    
            
client_print(idprint_chat"You got a assist of %s"name)
                
            if(
g_count_victim_human[id])
                
g_count_victim_human[id]--;
                
            
g_victim_done[victim][id] = false;
            
g_fDamage_Human[victim][id] = 0.0;
        }
            
        if(
is_user_alive(id)
        && !
zp_core_is_zombie(id)
        && !
g_he_attacker[id]
        && 
g_count_victim_zombie[id]
        && 
g_victim_done[victim][id]
        && !
zp_core_is_first_zombie(victim)
        && !
zp_class_nemesis_get(victim))
        {
            new 
name[32]
            
get_user_name(victimnamecharsmax(name))
                    
            
client_print(idprint_chat"You got a assist of %s"name)
                
            if(
g_count_victim_zombie[id])
                
g_count_victim_zombie[id]--;
                
            
g_victim_done[victim][id] = false;
            
g_fDamage_Zombie[victim][id] = 0.0;
        }
    }
    
    if(
zp_core_is_zombie(victim))
    {
        
g_count_victim_human[victim] = 0;
        
g_fDamage_Human[victim][attacker] = 0.0;
    }
    
    if(!
zp_core_is_zombie(victim))
    {
        
g_count_victim_zombie[victim] = 0;
        
g_fDamage_Zombie[victim][attacker] = 0.0;
    }
    
    
g_victim_done[victim][attacker] = false;
    
g_hp_victim[victim] = 0;
    
g_he_attacker[attacker] = false;


Last edited by sursista; 02-17-2022 at 15:01. Reason: edited code
sursista is offline
Send a message via MSN to sursista Send a message via Skype™ to sursista
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 02-17-2022 , 14:44   Re: Save/Get multiple different values in the same variable per player
Reply With Quote #4

Player index starts from 1, not from 0.

__________________









Last edited by CrazY.; 02-17-2022 at 14:47.
CrazY. is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-17-2022 , 14:52   Re: Save/Get multiple different values in the same variable per player
Reply With Quote #5

Nevermind, I didn't notice he's looping through all indexes instead of only connected players.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
zXCaptainXz
Member
Join Date: May 2017
Old 02-17-2022 , 18:59   Re: Save/Get multiple different values in the same variable per player
Reply With Quote #6

g_he_attacker
g_count_victim_zombie/g_count_victim_human

What is the point of these variables?


Code:
g_fDamage_Human[victim][attacker] >= g_hp_victim[victim]
You are comparing a float to an integer, IDK if that even works in AMXX.

Last edited by zXCaptainXz; 02-17-2022 at 19:32.
zXCaptainXz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-17-2022 , 22:27   Re: Save/Get multiple different values in the same variable per player
Reply With Quote #7

Here are some thoughts:

If the victim dies, I don't see why you shouldn't be setting all 4 variables to zero. Also, having if statements for both "variable" and "not variable" is unnecessary, simply use an else condition, it will be more efficient.
Code:
	if(zp_core_is_zombie(victim))
	{
		g_count_victim_human[victim] = 0;
		g_fDamage_Human[victim][attacker] = 0.0;
	}
	
	if(!zp_core_is_zombie(victim))
	{
		g_count_victim_zombie[victim] = 0;
		g_fDamage_Zombie[victim][attacker] = 0.0;
	}
I'm not sure if you just stripped a whole bunch of code out or not but you have a couple client_print() calls that reference an undefined variable 'id'.

Are you sure it's just an issue with calling client_print() so many times crazy fast? I feel like there have been issues trying to do this in other threads.

Try removing all the ZP craziness to see if your basic logic is done correctly as well as adding debug logging to see what the values of various variables are during execution. Making the code much simpler should make it easier to debug and determine what you might be doing wrong. The zombie vs human part makes things more complex and I've never played ZP so I'm not 100% how that is all done. Then, once you have that working correctly, start adding the ZP stuff back in.

Regarding seeing players that you didn't expect to see, realize that the entity index (1 through 32) are not unique to unique players. I.e. if a player leaves and someone else joins, they might get the same entity index. So, if you don't do proper connect/disconnect cleanup of the variables then you might see the wrong person show up.
__________________
fysiks is offline
sursista
Senior Member
Join Date: Jul 2010
Location: Spain
Old 02-18-2022 , 05:43   Re: Save/Get multiple different values in the same variable per player
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
Here are some thoughts:

If the victim dies, I don't see why you shouldn't be setting all 4 variables to zero. Also, having if statements for both "variable" and "not variable" is unnecessary, simply use an else condition, it will be more efficient.
Code:
	if(zp_core_is_zombie(victim))
	{
		g_count_victim_human[victim] = 0;
		g_fDamage_Human[victim][attacker] = 0.0;
	}
	
	if(!zp_core_is_zombie(victim))
	{
		g_count_victim_zombie[victim] = 0;
		g_fDamage_Zombie[victim][attacker] = 0.0;
	}
Making the code much simpler should make it easier to debug and determine what you might be doing wrong.
I will do a full debug of the plugin, it will take me some time
sursista is offline
Send a message via MSN to sursista Send a message via Skype™ to sursista
sursista
Senior Member
Join Date: Jul 2010
Location: Spain
Old 02-18-2022 , 05:36   Re: Save/Get multiple different values in the same variable per player
Reply With Quote #9

Quote:
Originally Posted by zXCaptainXz View Post
g_he_attacker
g_count_victim_zombie/g_count_victim_human

What is the point of these variables?


Code:
g_fDamage_Human[victim][attacker] >= g_hp_victim[victim]
You are comparing a float to an integer, IDK if that even works in AMXX.

g_count_victim_zombie/g_count_victim_human detects if the attacker has more than one assist, since when resetting the variables I only need to subtract the value to 1 for each dead victim (this way even if the variable is reset, he will still have more assists thanks to this variable)

g_he_attacker makes it so that if the attacker gets an assist and he kills the victim, all of his variables are reset, otherwise they will also be counted as assists (I could have also made a return for this)

Last edited by sursista; 02-18-2022 at 05:46. Reason: edit
sursista is offline
Send a message via MSN to sursista Send a message via Skype™ to sursista
zXCaptainXz
Member
Join Date: May 2017
Old 02-18-2022 , 06:59   Re: Save/Get multiple different values in the same variable per player
Reply With Quote #10

There are many things I don't understand in your code, most importantly why are you giving assists in both Ham_TakeDamage and Ham_Killed forwards. You should either do it in one or the other, either you get an assist immediately after dealing 1/3 the original health of the player or you get an assist after the player gets killed by someone other than you and you dealt more than 1/3 the original health of the player. The latter case makes more sense anyway, assists should be given when the victim dies. I coded a plugin which probably does what you want with way less clutter, if you want you can try it and see if it solves your problem.
Attached Files
File Type: sma Get Plugin or Get Source (zp50_assist.sma - 63 views - 2.7 KB)

Last edited by zXCaptainXz; 02-18-2022 at 06:59.
zXCaptainXz 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 11:43.


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