AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Any idea why this code doesn't work? (https://forums.alliedmods.net/showthread.php?t=206445)

DeLiriuM 01-22-2013 11:59

Any idea why this code doesn't work?
 
PHP Code:

public fw_player_killed(victimattackershouldgibid)
{
    if(
get_user_team(attacker) == 1)
    {
        
g_jbpacks[attacker] += get_pcvar_num(g_killjp
        
        if(
get_pdata_int(victim75) == HIT_HEAD)
        {
            
g_jbpacks[attacker] += get_pcvar_num(g_killhsjp)
        }
    }
    
    else if (
get_user_team(attacker) == && !(get_user_flags(id) & ADMIN_LEVEL_H))
    {
        
g_jbpacks[attacker] += get_pcvar_num(g_killjpvip
        
        if(
get_pdata_int(victim75) == HIT_HEAD)
        {
            
g_jbpacks[attacker] += get_pcvar_num(g_killhsjp)
        }
    }



fysiks 01-22-2013 12:47

Re: Any idea why this code doesn't work?
 
What doesn't work? You need to find which part doesn't work specifically. Is the function being called? What part of the code does and does not execute?

Also, your elseif will never be executed. You should combine the two and only change the part where the two codes differ.

DeLiriuM 01-22-2013 13:40

Re: Any idea why this code doesn't work?
 
Normal users should recieve X amount of jbpacks + Z amount (if killed with HS), VIP users (ADMIN_LEVEL_H) should recieve Y amount of jbpacks + Z amount (if killed with HS), but they don't.
Would you give me an example?

Jhob94 01-22-2013 15:29

Re: Any idea why this code doesn't work?
 
Try:
Code:

public fw_player_killed(victim, attacker, shouldgib, id)
{
    if(get_user_team(attacker) == 1 && !(get_user_flags(id) & ADMIN_LEVEL_H))
    {
        g_jbpacks[attacker] += get_pcvar_num(g_killjp)
       
        if(get_pdata_int(victim, 75) == HIT_HEAD)
        {
            g_jbpacks[attacker] += get_pcvar_num(g_killhsjp)
        }
    }
   
    else if (get_user_team(attacker) == 1 && (get_user_flags(id) & ADMIN_LEVEL_H))
    {
        g_jbpacks[attacker] += get_pcvar_num(g_killjpvip)
       
        if(get_pdata_int(victim, 75) == HIT_HEAD)
        {
            g_jbpacks[attacker] += get_pcvar_num(g_killhsjp)
        }
    }
}


fysiks 01-22-2013 20:45

Re: Any idea why this code doesn't work?
 
Quote:

Originally Posted by DeLiriuM (Post 1878133)
Normal users should recieve XX amount of jbpacks + X amount (if killed with HS), VIP users (ADMIN_LEVEL_H) should recieve YY amount of jbpacks + X amount (if killed with HS), but they don't.
Would you give me an example?

Honestly, I don't care what you are trying to do. I'm trying to help you help yourself so that you can either fix this problem (and many others) yourself or get a better idea of what you are actually needing help with.

When something "doesn't work," you should always first check what code is actually being executed. If the whole function is not getting called at all then it doesn't do any good to change your code.

So, you should find out what code is actually being executed. I typically do this by adding in server_print() statements describing what part just got executed (you can also use log_amx).

Code:

function()
{
    server_print("function just got executed")
    if( g_bBoolean )
    {
        server_print("g_bBoolean is true")
    }
    else
    {
        server_print("g_bBoolean is false")
    }
    server_print("function finished executing")
    // etc.
}

The problem may be simpler to solve than this but a process like this will help you figure out where to look. Most likely, you will be able to solve your own problems this way (by knowing what is actually happening step-by-step).

E.g. If you never see anything print then you know that function() is not even being executed and you now know to look into why it's not being executed instead of looking inside the function which at that point would be irrelevant. If don't see what you expect to see from certain parts of the function then you know where to look into.

So, after this process, you should not ever say "it doesn't work" because you should have it narrowed down to what does not work.

TheDS1337 01-23-2013 15:15

Re: Any idea why this code doesn't work?
 
i think Ham_Killed forward have only 3 params and you made it with 4 params :S

Jhob94 01-23-2013 15:17

Re: Any idea why this code doesn't work?
 
He didnt said what happens with him version so we cant help him 100%

But i think i know what him problem. He said he want for vips Y+Z and for who isnt vip X+Z
Y= JBPACKS per kill of vips
Z= JBPACKS per HS Kill
X= JBPACKS per kill of normal user

And i think what he says that is wrong is because he thinks this: g_jbpacks[attacker] += get_pcvar_num(g_killhsjp) is JBPACKS NORMAL/VIP + HS but in fact is just HS JBPACKS so what he should make is:

Code:

public fw_player_killed(victim, attacker, shouldgib, id)
{
    if(get_user_team(attacker) == 1 && !(get_user_flags(id) & ADMIN_LEVEL_H))
    {
        g_jbpacks[attacker] += get_pcvar_num(g_killjp)
       
        if(get_pdata_int(victim, 75) == HIT_HEAD)
        {
            g_jbpacks[attacker] += get_pcvar_num(g_killhsjp)
        }
    }
   
    else if (get_user_team(attacker) == 1 && (get_user_flags(id) & ADMIN_LEVEL_H))
    {
        g_jbpacks[attacker] += get_pcvar_num(g_killjpvip)
       
        if(get_pdata_int(victim, 75) == HIT_HEAD)
        {
            g_jbpacks[attacker] += get_pcvar_num(g_killhsjpvip)
        }
    }
}

So if player isnt VIP will receive:
- Per kill g_killjp
- Per HS g_killhsjp

And if player is VIP will receive:
- Per kill g_killjpvip
- Per HS g_killhsjpvip

So if you want normal jp amount 10, you set g_killjp to 10, and if want hs 15 you set g_killhsjp to 15 and normal user will receive 15 jp per hs. Same thing to vip cvars
Note: dont forget add the cvar g_killhsjpvip because that is wasnt on your code.

And on your code, you had it changed, you had user get vip amount and vip get user amount, so use the version of this post ;)

DeLiriuM 01-25-2013 05:49

Re: Any idea why this code doesn't work?
 
X = Amount of jbpacks for normal users
Y = Amount of jpbacks for VIP users
Z = HS kill amount.
In all cases "Z" is a constant.

@Jhob94 - why do you add "ADMIN_LEVEL_H" in both situations? And no. I didn't have it changed. In both situations players recieved "X" amount of jbpacks.

Jhob94 01-26-2013 06:58

Re: Any idea why this code doesn't work?
 
Listen i didnt add both is both situations, if you see, the first one have "!" before read the admin level, and that means if user isnt admin_level_h. And yes you had it changed because for vip you had normal jb amounts and for users you had vip amounts. Just read my post again and use the code, you will see that will work perfectly

Backstabnoob 01-30-2013 10:34

Re: Any idea why this code doesn't work?
 
Code:
public fw_player_killed( iVictim, iAttacker ) {     if( get_user_team( iAttacker ) == 1 )     {                   new iKillNormal = ( ( get_user_flags( iAttacker ) & ADMIN_LEVEL_H ) ? get_pcvar_num( g_killjpvip ) : get_pcvar_num( g_killjp ) )                 g_jbpacks[ iAttacker ] += ( get_pdata_int( iVictim, 75 ) == HIT_HEAD ) ?  ( iKillNormal + get_pcvar_num( g_killhsjp ) ) : iKillNormal     } }


All times are GMT -4. The time now is 20:39.

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