Jump to content
  • 0

How do I make an NPC to calculate a logarithm?


Question

Posted (edited)

How do I make an NPC to calculate a logarithm?

for example:

 set @tax,log10(Zeny) * 10;

Edited by Freyr

2 answers to this question

Recommended Posts

Posted (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 by Haziel
Posted (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    8

Returns 3

Check:
2 ^ 3 = 8


You can do it this way since, in my knowledge, everything ingame works with an integer.

Edited by jezznar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...