AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Xp problem (https://forums.alliedmods.net/showthread.php?t=335974)

kiarronis 01-18-2022 00:35

Xp problem
 
I need a code that when I kill someone of a higher level, they give me more experience.

fysiks 01-18-2022 02:31

Re: Xp problem
 
This is the Scripting Help section where you're writing the code yourself and if you don't provide the XP plugin that you're using, we have no way to help you.

kiarronis 01-18-2022 16:07

Re: Xp problem
 
1 Attachment(s)
Quote:

Originally Posted by fysiks (Post 2768706)
This is the Scripting Help section where you're writing the code yourself and if you don't provide the XP plugin that you're using, we have no way to help you.

Sorry, im newbie. Here is the code

kiarronis 01-18-2022 16:24

Re: Xp problem
 
Quote:

Originally Posted by kiarronis (Post 2768767)
Sorry, im newbie. Here is the code

This is the part of xp kill.

Code:

//This function is the ONLY way this plugin should add/subtract XP to a player
//There are checks to prevent overflowing
//To take XP away just send the function a negative (-) number
localAddXP(id, xp)
{
        new playerXP = gPlayerXP[id]
        new newTotal = playerXP + xp
   
        if ( xp > 0 && newTotal < playerXP ) {
                // Max possible signed 32bit int
                gPlayerXP[id] = 2147483647
        }
        else if ( xp < 0 && (newTotal < -1000000 || newTotal > playerXP) ) {
                gPlayerXP[id] = -1000000
        }
        else {
            gPlayerXP[id] = newTotal
        }
}

//----------------------------------------------------------------------------------------------
//native sh_add_kill_xp(id, victim, Float:multiplier = 1.0)
public _sh_add_kill_xp()
{
        new id = get_param(1)
        new victim = get_param(2)

        // Stupid check - but checking prevents crashes
        if ( id < 1 || id > gServersMaxPlayers || victim < 1 || victim > gServersMaxPlayers ) return

        //new Float:mult = get_param_f(3)
        localAddXP(id,floatround(get_param_f(3) * gXPGiven[gPlayerLevel[victim]]))
        displayPowers(id, false)
}


bigdaddy424 01-18-2022 19:07

Re: Xp problem
 
Code:
new float: multiplier = str_to_float(fmt("%d.%02d", (gPlayerLevel[id] / 100) + 1, gPlayerLevel[id] % 100))
Spoiler

kiarronis 01-18-2022 21:18

Re: Xp problem
 
Quote:

Originally Posted by kiarronis (Post 2768767)
Sorry, im newbie. Here is the code

Quote:

Originally Posted by bigdaddy424 (Post 2768779)
Code:
new float: multiplier = str_to_float(fmt("%d.%02d", (gPlayerLevel[id] / 100) + 1, gPlayerLevel[id] % 100))
Spoiler

Can u tell me where to put this?

bigdaddy424 01-18-2022 21:43

Re: Xp problem
 
Code:
//---------------------------------------------------------------------------------------------- //native sh_add_kill_xp(id, victim) public _sh_add_kill_xp() {     new id = get_param(1)     new victim = get_param(2)     // Stupid check - but checking prevents crashes     if ( id < 1 || id > gServersMaxPlayers || victim < 1 || victim > gServersMaxPlayers ) return     new float: multiplier = str_to_float(fmt("%d.%02d", (gPlayerLevel[id] / 100) + 1, gPlayerLevel[id] % 100))     localAddXP(id,floatround(multiplier * gXPGiven[gPlayerLevel[victim]]))     displayPowers(id, false) }

kiarronis 01-18-2022 22:14

Re: Xp problem
 
Quote:

Originally Posted by bigdaddy424 (Post 2768789)
Code:
//---------------------------------------------------------------------------------------------- //native sh_add_kill_xp(id, victim) public _sh_add_kill_xp() {     new id = get_param(1)     new victim = get_param(2)     // Stupid check - but checking prevents crashes     if ( id < 1 || id > gServersMaxPlayers || victim < 1 || victim > gServersMaxPlayers ) return     new float: multiplier = str_to_float(fmt("%d.%02d", (gPlayerLevel[id] / 100) + 1, gPlayerLevel[id] % 100))     localAddXP(id,floatround(multiplier * gXPGiven[gPlayerLevel[victim]]))     displayPowers(id, false) }

And the another code? Because doesn't work

fysiks 01-18-2022 23:32

Re: Xp problem
 
Quote:

Originally Posted by bigdaddy424 (Post 2768779)
Code:
new float: multiplier = str_to_float(fmt("%d.%02d", (gPlayerLevel[id] / 100) + 1, gPlayerLevel[id] % 100))

No need to build a string to achieve a floating point value. Simply float the variable and divide by 100.0 and add 1.0 (to achieve this same calculation).

When I first saw the request, I thought he was requesting something more related to the relative XP between the killer and the victim but the OP didn't clearly state how he wanted it to work. There are many different algorithms that could be use and this one should work well enough, IMO.

However, you're now completely ignoring the third parameter of the native which could be a big confusing in the long run. I think that maybe this type of modification should really go in the plugin that is calling these functions and passing the multiplier value into the function like normal.

kiarronis 01-19-2022 17:45

Re: Xp problem
 
Quote:

Originally Posted by fysiks (Post 2768795)
No need to build a string to achieve a floating point value. Simply float the variable and divide by 100.0 and add 1.0 (to achieve this same calculation).

When I first saw the request, I thought he was requesting something more related to the relative XP between the killer and the victim but the OP didn't clearly state how he wanted it to work. There are many different algorithms that could be use and this one should work well enough, IMO.

However, you're now completely ignoring the third parameter of the native which could be a big confusing in the long run. I think that maybe this type of modification should really go in the plugin that is calling these functions and passing the multiplier value into the function like normal.

Yes, i'm requesting about the relative XP between the killer and the victim. Thank's bigdaddy for the code but i tried it and it didn't work, able i put it wrong. I need to get more xp when i kill somebody higher lvl than me. Sorry for my english, i'm argentinian and i'm newbie in the programming


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

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