Raised This Month: $51 Target: $400
 12% 

Xp problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kiarronis
Junior Member
Join Date: Jan 2022
Location: Argentina
Old 01-18-2022 , 00:35   Xp problem
Reply With Quote #1

I need a code that when I kill someone of a higher level, they give me more experience.
kiarronis is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-18-2022 , 02:31   Re: Xp problem
Reply With Quote #2

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.
__________________
fysiks is offline
kiarronis
Junior Member
Join Date: Jan 2022
Location: Argentina
Old 01-18-2022 , 16:07   Re: Xp problem
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
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
Attached Files
File Type: sma Get Plugin or Get Source (superheromod.sma - 34 views - 182.0 KB)
kiarronis is offline
kiarronis
Junior Member
Join Date: Jan 2022
Location: Argentina
Old 01-18-2022 , 16:24   Re: Xp problem
Reply With Quote #4

Quote:
Originally Posted by kiarronis View Post
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)
}

Last edited by kiarronis; 01-18-2022 at 16:24.
kiarronis is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 01-18-2022 , 19:07   Re: Xp problem
Reply With Quote #5

Code:
new float: multiplier = str_to_float(fmt("%d.%02d", (gPlayerLevel[id] / 100) + 1, gPlayerLevel[id] % 100))
Spoiler
bigdaddy424 is offline
kiarronis
Junior Member
Join Date: Jan 2022
Location: Argentina
Old 01-18-2022 , 21:18   Re: Xp problem
Reply With Quote #6

Quote:
Originally Posted by kiarronis View Post
Sorry, im newbie. Here is the code
Quote:
Originally Posted by bigdaddy424 View Post
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?
kiarronis is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 01-18-2022 , 21:43   Re: Xp problem
Reply With Quote #7

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) }
bigdaddy424 is offline
kiarronis
Junior Member
Join Date: Jan 2022
Location: Argentina
Old 01-18-2022 , 22:14   Re: Xp problem
Reply With Quote #8

Quote:
Originally Posted by bigdaddy424 View Post
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

Last edited by kiarronis; 01-18-2022 at 23:17.
kiarronis is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-18-2022 , 23:32   Re: Xp problem
Reply With Quote #9

Quote:
Originally Posted by bigdaddy424 View Post
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.
__________________
fysiks is offline
kiarronis
Junior Member
Join Date: Jan 2022
Location: Argentina
Old 01-19-2022 , 17:45   Re: Xp problem
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
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

Last edited by kiarronis; 01-19-2022 at 17:47.
kiarronis 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 13:06.


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