AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Save/Get multiple different values in the same variable per player (https://forums.alliedmods.net/showthread.php?t=336401)

sursista 02-17-2022 08:28

Save/Get multiple different values in the same variable per player
 
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)

OciXCrom 02-17-2022 14:19

Re: Save/Get multiple different values in the same variable per player
 
I don't see a problem there.

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

CrazY. 02-17-2022 14:44

Re: Save/Get multiple different values in the same variable per player
 
Player index starts from 1, not from 0.

https://i.imgur.com/VheLOgu.png

OciXCrom 02-17-2022 14:52

Re: Save/Get multiple different values in the same variable per player
 
Nevermind, I didn't notice he's looping through all indexes instead of only connected players.

sursista 02-17-2022 14:58

Re: Save/Get multiple different values in the same variable per player
 
Quote:

Originally Posted by OciXCrom (Post 2771744)
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;



zXCaptainXz 02-17-2022 18:59

Re: Save/Get multiple different values in the same variable per player
 
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.

fysiks 02-17-2022 22:27

Re: Save/Get multiple different values in the same variable per player
 
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.

sursista 02-18-2022 05:36

Re: Save/Get multiple different values in the same variable per player
 
Quote:

Originally Posted by zXCaptainXz (Post 2771768)
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)

sursista 02-18-2022 05:43

Re: Save/Get multiple different values in the same variable per player
 
Quote:

Originally Posted by fysiks (Post 2771785)
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

zXCaptainXz 02-18-2022 06:59

Re: Save/Get multiple different values in the same variable per player
 
1 Attachment(s)
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.


All times are GMT -4. The time now is 11:43.

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