Jump to content
  • 0

How do I make an NPC to calculate a logarithm?


Freyr

Question


  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  38
  • Reputation:   7
  • Joined:  01/11/13
  • Last Seen:  

How do I make an NPC to calculate a logarithm?

for example:

 set @tax,log10(Zeny) * 10;

Edited by Freyr
Link to comment
Share on other sites

2 answers to this question

Recommended Posts


  • Group:  Content Moderator
  • Topic Count:  22
  • Topics Per Day:  0.00
  • Content Count:  639
  • Reputation:   609
  • Joined:  11/25/11
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  54
  • Topics Per Day:  0.01
  • Content Count:  513
  • Reputation:   84
  • Joined:  08/11/12
  • Last Seen:  

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
Link to comment
Share on other sites

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.

×
×
  • Create New...