ID:2191703
 
(See the best response by Phat T.)
Code:
mob
verb
RFX_UP()
if(usr.levelpoints>=1)
var/effective_level = usr.blevel - (round(usr.levelpoints / 6)+1)
if(usr.rfx < ((usr.blevel)*3 + effective_level + 50))
var/rfxb=round(usr.rfx/10)

usr.rfx++
usr.levelpoints-=1

var/rfxc=round(usr.rfx/10)
if(rfxb!=rfxc)
usr.skillspassive[26]+=1

//usr.pint=0
usr:Level_Up("rfx")
winset(usr, "splabel", "text=\"[round(skillpoints)]\"")
winset(usr, "levellabel", "text=\"[levelpoints]\"")
else
usr<<"'Reflex' cannot exceed [(usr.blevel)*3+50] (+[effective_level]/[usr.blevel] levelup bonus points) at your current level."
STR_UP()
if(usr.levelpoints>=1)
var/effective_level = usr.blevel - (round(usr.levelpoints / 6)+1)
if(usr.str < ((usr.blevel)*3 + effective_level + 50))
var/strb=round(usr.str/10)

usr.str++
usr.levelpoints-=1

var/strc=round(usr.str/10)
if(strb!=strc)
usr.skillspassive[25]+=1

//usr.pint=0
usr:Level_Up("str")
winset(usr, "splabel", "text=\"[round(skillpoints)]\"")
winset(usr, "levellabel", "text=\"[levelpoints]\"")

else
usr<<"'Strength' cannot exceed [(usr.blevel)*3+50] (+[effective_level]/[usr.blevel] levelup bonus points) at your current level."


Problem description: Above is my code for players to increase their stats in Rfx meaning Reflex or Str meaning Strength. The problem is I want to add an input option so you can add lets say 20 of your given stats into Rfx instead of adding it 1 by 1.

Best response
If I understood you correctly you want to use something like this :
var/levelpoints_amount = input("How many levelpoints would you like to enter?\n- Your levelpoints: [usr.coins)]","Input Amount")as num|null


So you can pick the amount of points you want to add them to your str like this :

if(levelpoints_amount < levelpoints) return

if(levelpoints_amount)

usr.str += levelpoints_amount
usr.levelpoints-=levelpoints_amount


This is just an example and I hope it helps

Solved. Thank you.
send a link to ur game when its up so i can abuse
Lol?
you should check if theyre inputting negative numbers lol
where in my code am i inputting negative Numbers
I was just saying you should validate the input more by making sure they dont put in negative numbers
Yes you should do something like this :

if(levelpoints_amount < 1) return


or people can abuse like Zagros5000 said because you can use negative numbers for input
oh ok thanks
#define clamp(x, mi, ma) max(mi, min(ma, x)) // Use the built-in min/max() procs to set the parameter (x) to no less than 0, and no more than the player's levelpoints (in the given example)
Plug the define into your source, it'll come in handy a lot! A #define must also be placed before it's ever used in the source, unlike verbs/procs, so you can either place it at the top of the .dme itself or create a file specifically for #defines so it comes first in the file hierarchy, such as #define.dm.

var/levelpoints_amount = clamp(floor(input("How many levelpoints would you like to enter?\n- Your levelpoints: [usr.coins)]", "Input Amount")as num|null), 0, usr.levelpoints)
if(levelpoints_amount) // Check to see if it's not null, so if you for instance send the player a message, they don't see if it they cancel the input or input a negative/0.
usr.str += levelpoints_amount
usr.levelpoints-=levelpoints_amount

Potentially not as easily read as a few if()s, however it'll be easier in the long-run to write out your inputs using clamp/round than doing multiple checks to see if the value is negative, higher than what the player has or whatever.
Hmm.
How would I then insert it in this exactly? I'm still new with DM so I'm a bit confused right now.

        str_uparrow
Click()
if(usr.levelpoints>=1)
var/effective_level = usr.blevel - (round(usr.levelpoints / 6)+1)
if(usr.str < ((usr.blevel)*3 + effective_level + 50))
var/strb=round(usr.str/10)

usr.str++
usr.levelpoints-=1

var/strc=round(usr.str/10)
if(strb!=strc)
usr.skillspassive[25]+=1

//usr.pint=0
usr:Level_Up("str")
<dm>
sec
This is better:
        str_uparrow
Click()
if(usr.levelpoints>=1)
var/effective_level = usr.blevel - (round(usr.levelpoints / 6)+1)
if(usr.str < ((usr.blevel)*3 + effective_level + 50))
var/strb=round(usr.str/10)

usr.str++
usr.levelpoints-=1

var/strc=round(usr.str/10)
if(strb!=strc)
usr.skillspassive[25]+=1

//usr.pint=0
usr:Level_Up("str")

else
usr<<"'Strength' cannot exceed [(usr.blevel)*3+50] (+[effective_level]/[usr.blevel] levelup bonus points) at your current level."


How do I insert it into this?
In response to Dragnon20
I don't really see a need or use to include clamp to any of that code. Clamps are used to make sure a value is within the range it's suppose to be (such as within 0 (so it's not negative) and equal to or less than what a player has, if they're for instance spending money in a shop.) I don't see a need for that in that snippet.

However, is there a specific reason you're using : to call Level_Up() instead of . ? I may be mistaken here but : should only be used if there's a type difference (which can be fixed by setting the src/usr to a variable of that type,) or you absolutely have to for some reason.
I'm just talking about how would I insert an input option to the above line of code so people can choose how many levelpoints they want to add. Because the way the code is set it, levelpoints only are increased by 1 point everytime the user clicks str_uparrow
In response to Dragnon20
Ok. I'm stupid.

str_uparrow
Click()
if(usr.levelpoints)
var/effective_level = usr.blevel-(round(usr.levelpoints/6)+1)
var/max_str = (usr.blevel*3)+(effective_level+50)
if(usr.str<max_str)
var inc_amt = clamp(round(input("Input an amount to increase your strength by", "Increase strength") as null|num), 0, max_str-str)
if(inc_amt)
var/strb=round(usr.str/10)
usr.str+=inc_amt
usr.levelpoints-=inc_amt
var/strc=round(usr.str/10)
if(strb!=strc)
usr.skillspassive[25]+=1
// Not too sure what you're doing here so the strb and strc stuff may need adjusting since you can input your own amount
//usr.pint=0
usr:Level_Up("str") // Try using . instead of :
else
usr<<"'Strength' cannot exceed [(usr.blevel)*3+50] (+[effective_level]/[usr.blevel] levelup bonus points) at your current level."
Should work... should.
:P thanks ill prob get back to u later if it works. im so busy rn. Thanks