Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Help (https://forums.graalonline.com/forums/showthread.php?t=71496)

Rapidwolve 01-16-2007 06:10 AM

Help
 
I just recently scripted a mailing system and I am now scripting the part that states who has the most letters sent.

PHP Code:

for (iallplayers){
temp.player findPlayer(i);
this.sentmail.(@temp.player) = temp.player.clientr.sentmailamt;


I get it to output in the flags of the npc 'Mail':
PHP Code:

sentmail.MandangoP2P=19
sentmail
.rapidwolve=2
sentmail
.Spike5656=

I then use a function 'calcMostSent' to determine who sent the most I am stumped at this part, I have no clue what to do. I've tried:
PHP Code:

for (jthis.sentmail.getdynamicvarnames()){
if (
this.sentmail.(@j) > this.sentmail(@j[j+j-1]){
this.mostsent this.sentmail.(@j);
this.mostsentacc j;
}


Don't even ask why I did that, because I was just guessing X_x. I tried alot of other ways but it hasn't worked. Can somebody help me?

Inverness 01-16-2007 07:22 AM

PHP Code:

temp.keys getstringkeys("this.sentmail.");
setarray(temp.mostsent2); // account & number sent
for (temp.0temp.temp.keys.size(); temp.++) {
  
temp.current makevar("this.sentmail." temp.keys[temp.i]);
  if (
temp.current temp.mostsent[1]) {
    
temp.mostsent[1] = temp.current;
    
temp.mostsent[0] = temp.keys[temp.i];
  }
}
return 
temp.mostsent[0]; 

I prefer using makevar() since the other way seems to get funky sometimes.

Rapidwolve 01-17-2007 03:00 AM

Once again you helped me :)

projectigi 01-17-2007 06:10 PM

PHP Code:

for (jthis.sentmail.getdynamicvarnames()){
if (
this.sentmail.(@j) > this.sentmail(@j[j+j-1]){
this.mostsent this.sentmail.(@j);
this.mostsentacc j;
}


PHP Code:

if (this.sentmail.(@j) > this.sentmail(@j[j+j-1]){ 

i guess it could work if you change it to, and you forgot a closing )

PHP Code:

if (this.sentmail.(@j) > this.(@ "sentmail" j[j+j-1])){ 

or did you try to do this
PHP Code:

if (this.sentmail.(@j) > this.sentmail.(@j[j+j-1])){ 


Chompy 01-17-2007 06:16 PM

Quote:

Originally Posted by projectigi (Post 1265808)
PHP Code:

for (jthis.sentmail.getdynamicvarnames()){
if (
this.sentmail.(@j) > this.sentmail(@j[j+j-1]){
this.mostsent this.sentmail.(@j);
this.mostsentacc j;
}


PHP Code:

if (this.sentmail.(@j) > this.sentmail(@j[j+j-1]){ 

i guess it could work if you change it to, and you forgot a closing )

PHP Code:

if (this.sentmail.(@j) > this.(@ "sentmail" j[j+j-1])){ 

or did you try to do this
PHP Code:

if (this.sentmail.(@j) > this.sentmail.(@j[j+j-1])){ 


he only missed a bracet :O

if (this.sentmail.(@j) > this.sentmail(@j[j+j-1]){

should be

if (this.sentmail.(@j) > this.sentmail(@j[j+j-1])){

NPC Code:

if (this.sentmail.(@j) > this.sentmail(@j[j+j-1])){


ApothiX 01-17-2007 08:13 PM

Quote:

Originally Posted by Chompy (Post 1265815)
NPC Code:

if (this.sentmail.(@j) > this.sentmail(@j[j+j-1])){


That wouldn't work, because it would be trying to call the 'sentmail' function, the correct way to do it was already stated: this.(@"sentmail" @ j[j+j-1]), or by using makevar()

Tolnaftate2004 01-17-2007 08:30 PM

Quote:

Originally Posted by Inverness (Post 1265456)
I prefer using makevar() since the other way seems to get funky sometimes.

this.(@varname) is more efficient and less cluttered. It's 'funky' in the original post because he's using the for-each loop variables incorrectly.

Quote:

Originally Posted by projectigi (Post 1265808)
i guess it could work if you change it to, and you forgot a closing )

PHP Code:

if (this.sentmail.(@j) > this.(@ "sentmail" j[j+j-1])){ 

or did you try to do this
PHP Code:

if (this.sentmail.(@j) > this.sentmail.(@j[j+j-1])){ 


Neither works. j is most likely a string. I don't know what str + str -1 makes. Nor can I be certain what str[str+str-1] does.

Quote:

Originally Posted by Chompy (Post 1265815)
NPC Code:

if (this.sentmail.(@j) > this.sentmail(@j[j+j-1])){



PHP Code:

temp.arr this.sentmail.getdynamicvarnames();
temp.max = {-1,{""}};
for (
jtemp.arr) {
  
temp.sent this.sentmail.(@j);
  if (
temp.sent temp.max[0]) {
    
temp.max = {temp.sent,{j}};
  } elseif (
temp.sent == temp.max[0]) temp.max[1].add(j);
}
return 
temp.max[1]; 

Or something of that sort.

Inverness 01-17-2007 10:52 PM

Quote:

Originally Posted by Tolnaftate2004
this.(@varname) is more efficient and less cluttered. It's 'funky' in the original post because he's using the for-each loop variables incorrectly.

How exactly is it more efficient?

napo_p2p 01-18-2007 12:56 AM

Quote:

Originally Posted by Inverness (Post 1265882)
How exactly is it more efficient?

My guess is that is just has to access the variable, rather than have to call a function.

Not a big difference really ... I was just never a big fan of makevar.... (but you know that already :P).

Rapidwolve 01-18-2007 01:11 AM

Quote:

Originally Posted by Inverness (Post 1265882)
How exactly is it more efficient?

I never understood how it was more efficient either but I use it now because I dont want to type makevar all the time

Tolnaftate2004 01-18-2007 01:33 AM

Quote:

Originally Posted by Inverness (Post 1265882)
How exactly is it more efficient?

I think Stefan said it somewhere. I went looking for it, but I couldn't find it.

But logically, one could assume that the makevar function is just doing a (@var) thing anyway.

Skyld 01-18-2007 01:37 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1265930)
I think Stefan said it somewhere. I went looking for it, but I couldn't find it.

But logically, one could assume that the makevar function is just doing a (@var) thing anyway.

Logically it would perform (@ var) in iteration for each part.of.the.variable, I suppose, not sure if that is how it is actually working though.

Inverness 01-18-2007 07:28 AM

Quote:

Originally Posted by Rapidwolve (Post 1265921)
I never understood how it was more efficient either but I use it now because I dont want to type makevar all the time

Typeing makevar is not a problem with me it takes no time at all. And I don't need to use makevar in the mudlib anyhow since I have functions for that. I like makevar because it looks better to me than the other option.


All times are GMT +2. The time now is 03:34 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.