ID:266199
 
How would I get it so if a knight clicks on practice swords
they get 5% more efficient every 30 seconds?

Does it have anything to do with Sleep?
Air _King wrote:
How would I get it so if a knight clicks on practice swords
they get 5% more efficient every 30 seconds?

Does it have anything to do with Sleep?

actually it has to do with spawn, and you cannot directory loop a proc, because that would cause all other procs to stop all the time, because in byond you can only have 1 proc running at one time, doesnt make sense i know, but its true.

this is why you need a spawn() in the middle of things to let the proc rest for a bit, then continue. Now we are talking about a 30 second rest for this specific example, this is how it could be done

mob/knight/proc/gainswords()
src.swords += (src.swords * 0.05)
spawn(300)
gainswords()

in the above example, the gainswords() proc is called every 30 seconds AFTER it is called one time. Then each time its called, the person who called it gains 5% in a swords variable.
In response to FIREking
FIREking wrote:
Air _King wrote:
How would I get it so if a knight clicks on practice swords
they get 5% more efficient every 30 seconds?

Does it have anything to do with Sleep?

actually it has to do with spawn, and you cannot directory loop a proc, because that would cause all other procs to stop all the time, because in byond you can only have 1 proc running at one time, doesnt make sense i know, but its true.

this is why you need a spawn() in the middle of things to let the proc rest for a bit, then continue. Now we are talking about a 30 second rest for this specific example, this is how it could be done

mob/knight/proc/gainswords()
src.swords += (src.swords * 0.05)
spawn(300)
gainswords()

in the above example, the gainswords() proc is called every 30 seconds AFTER it is called one time. Then each time its called, the person who called it gains 5% in a swords variable.


How would i fit it in if i wanted the usr to Click() a trainer to train swords though?
In response to Air _King
Air _King wrote:
FIREking wrote:
Air _King wrote:
How would I get it so if a knight clicks on practice swords
they get 5% more efficient every 30 seconds?

Does it have anything to do with Sleep?

actually it has to do with spawn, and you cannot directory loop a proc, because that would cause all other procs to stop all the time, because in byond you can only have 1 proc running at one time, doesnt make sense i know, but its true.

this is why you need a spawn() in the middle of things to let the proc rest for a bit, then continue. Now we are talking about a 30 second rest for this specific example, this is how it could be done

mob/knight/proc/gainswords()
src.swords += (src.swords * 0.05)
spawn(300)
gainswords()

in the above example, the gainswords() proc is called every 30 seconds AFTER it is called one time. Then each time its called, the person who called it gains 5% in a swords variable.


How would i fit it in if i wanted the usr to Click() a trainer to train swords though?

well first you use that code i just gave you, then you make an object that calls the verb

obj
something
verb
train()
usr.gainswords()

but somehow you have to limit© it so that they can only click it one time, since the proc loops its self, make a variable and set it to one when used, and return when that variable is 0.

obj
something
var
beingused = 0
verb
train()
if(beingused == 1)
return 0
beingused = 1
usr.gainswords()

then there you go, the swords stat will rasie for an infinite amout of time, at intervals of 30 seconds, by 5% increase.

Thats what you asked, and this is the answer.
In response to FIREking
FIREking wrote:
Air _King wrote:
FIREking wrote:
Air _King wrote:
How would I get it so if a knight clicks on practice swords
they get 5% more efficient every 30 seconds?

Does it have anything to do with Sleep?

actually it has to do with spawn, and you cannot directory loop a proc, because that would cause all other procs to stop all the time, because in byond you can only have 1 proc running at one time, doesnt make sense i know, but its true.

this is why you need a spawn() in the middle of things to let the proc rest for a bit, then continue. Now we are talking about a 30 second rest for this specific example, this is how it could be done

mob/knight/proc/gainswords()
src.swords += (src.swords * 0.05)
spawn(300)
gainswords()

in the above example, the gainswords() proc is called every 30 seconds AFTER it is called one time. Then each time its called, the person who called it gains 5% in a swords variable.


How would i fit it in if i wanted the usr to Click() a trainer to train swords though?

well first you use that code i just gave you, then you make an object that calls the verb

obj
something
verb
train()
usr.gainswords()

but somehow you have to limit© it so that they can only click it one time, since the proc loops its self, make a variable and set it to one when used, and return when that variable is 0.

obj
something
var
beingused = 0
verb
train()
if(beingused == 1)
return 0
beingused = 1
usr.gainswords()

then there you go, the swords stat will rasie for an infinite amout of time, at intervals of 30 seconds, by 5% increase.

Thats what you asked, and this is the answer.



mob
trainer
Click()
usr.pswords()



mob/proc/pswords()
src.pswords +=(*0.05)
spawn(30)
pswords()


var
beingused = 0

mob
trainer
Click()
set src in oview()
if(beingused == 1)return 0
switch(input("What do you want to prac?","Practice")in list("swords","maces"))
if("swords")beingused = 1
usr.pswords()

if("maces")beingused = 1


I tried this it wont work Why?
In response to Air _King
mob/proc/pswords()
src.pswords +=(*0.05)
spawn(30)
pswords()

pswords() needs to be indented.

Also, on another note, you CAN in fact use sleep for this.
One thing you might want to consider is what kind of limit you can have on training. Say your efficiency maxes out at 100%. Well, nobody just trains 20 times until they know everything there is to know about swords; usually what they're really doing is reducing inefficiency. As is the way of these things, often the most gain in performance will be in early training, whereas later on you're working to gain subtle improvements. The math behind this is such:

Instead of:

y' = y+inc (inc is the increment, in this case 0.05)

It's:

y' = 1-(1-y)*(1-inc) = inc+y*(1-inc)

If you tried that formula in this case, sword skill would increase like this:

0 -> 0.05 -> 0.0975 -> 0.142625 -> ...

As you see, the amount of gain actually decreases over time; on the second try, you gain 4.75%, and on the third you gain a little over 4.5%, and so on. You'll never reach 100% but you'll get closer the more you practice; it'll take 14 training periods to get over 50% skill, and 45 to get to 90%. Your formula would look something like this:

skills["sword"]=0.05+skills["sword"]*0.95

If you want training to be a little faster than that, you can play with the proportions a little, to say, increase by 10%:

skills["sword"]=0.1+skills["sword"]*0.9

It now takes 7 lessons to get to 50% skill, and 22 to get to 90%. That's not so bad. You can figure out the number of lessons by putting ln(1-desired level)/ln(1-inc) into a calculator and rounding up; or you can use log(1-inc,1-level) in BYOND, which does the same calculation.

Lummox JR