Freyr Posted October 18, 2015 Posted October 18, 2015 (edited) How do I make an NPC to calculate a logarithm? for example: set @tax,log10(Zeny) * 10; Edited October 18, 2015 by Freyr Quote
Haziel Posted October 18, 2015 Posted October 18, 2015 (edited) If I recall correctly, a logarithm is the calculation about which exponent a base must be raised to reach a value.If I also recall correctly, there is not a in-built function which calculates that, so, you need a Custom Function.I made this one: prontera,150,150,3 script Test#log 420,{ mes "" + callfunc("Logarithim",10,10000) + ""; close; } function script Logarithim { set @basis, getarg(0); set @value, getarg(1); set @m, @basis; for (set @n, 2; @m < @value; set @n, @n + 1){ for (set @o, 1; @o < @n; set @o, @o + 1){ set @m, @m * @basis; } if (@m == @value) return @n; else if (@m > @value) return (@n - 1); else set @m, @basis; } return 0; } It's just a scratch and I don't know if it works perfectly.By the way, you can enter an basis and a target value, it will returns either the correct Logarithim or the closest one. Edited October 18, 2015 by Haziel Quote
Ninja Posted October 18, 2015 Posted October 18, 2015 (edited) set @tax,log10(Zeny) * 10; Function script logarthm { Set .@base, getarg(0); Set .@targetnum, getarg(1); Set .@x1, 1; For(set .@x,0:.@x<=.@targetnum;set .@x, .@x +1) { Set .@x1, .@x1 * .@base; } Return .@x*10; } Usage: set @tax, callfunc("logarthm",basenum,targetnum);Sample simulation: Log2(8).@x 0 1 2 3.@x1 1 2 4 8Returns 3Check:2 ^ 3 = 8You can do it this way since, in my knowledge, everything ingame works with an integer. Edited October 19, 2015 by jezznar Quote
Question
Freyr
How do I make an NPC to calculate a logarithm?
for example:
set @tax,log10(Zeny) * 10;
Edited by Freyr2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.