Jump to content
  • 0

Help, please make my script line shorter.


namerpus18

Question


  • Group:  Members
  • Topic Count:  38
  • Topics Per Day:  0.07
  • Content Count:  95
  • Reputation:   1
  • Joined:  11/15/22
  • Last Seen:  

Good Day everyone,

 I just need some help, if someone can help me shorten this script. My methods are too limited and i cant find a way to shorten it.

Does it improve if i manage to optimize this script? I feel that this script alone takes a lot of checking.

Thank you so much,

if(getmonsterinfo(killedrid, MOB_MVPEXP) > 1 && isbegin_quest(19000) > 0 || isbegin_quest(19001) > 0 || isbegin_quest(19002) > 0 || isbegin_quest(19003) > 0 || isbegin_quest(19004) > 0 || isbegin_quest(19005) > 0 || isbegin_quest(19006) > 0 || isbegin_quest(19007) > 0 || isbegin_quest(19008) > 0 || isbegin_quest(19009) > 0 || isbegin_quest(19010) > 0 || isbegin_quest(19011) > 0 || isbegin_quest(19012) > 0 || isbegin_quest(19013) > 0 || isbegin_quest(19014) > 0 || isbegin_quest(19015) > 0 || isbegin_quest(19016) > 0 || isbegin_quest(19017) > 0 || isbegin_quest(19018) > 0 || isbegin_quest(19019) > 0 )	{
  ....
}

 

Edited by namerpus18
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  233
  • Reputation:   86
  • Joined:  06/30/18
  • Last Seen:  

25 minutes ago, namerpus18 said:

Good Day everyone,

 I just need some help, if someone can help me shorten this script. My methods are too limited and i cant find a way to shorten it.

Does it improve if i manage to optimize this script? I feel that this script alone takes a lot of checking.

Thank you so much,

if(getmonsterinfo(killedrid, MOB_MVPEXP) > 1 && isbegin_quest(19000) > 0 || isbegin_quest(19001) > 0 || isbegin_quest(19002) > 0 || isbegin_quest(19003) > 0 || isbegin_quest(19004) > 0 || isbegin_quest(19005) > 0 || isbegin_quest(19006) > 0 || isbegin_quest(19007) > 0 || isbegin_quest(19008) > 0 || isbegin_quest(19009) > 0 || isbegin_quest(19010) > 0 || isbegin_quest(19011) > 0 || isbegin_quest(19012) > 0 || isbegin_quest(19013) > 0 || isbegin_quest(19014) > 0 || isbegin_quest(19015) > 0 || isbegin_quest(19016) > 0 || isbegin_quest(19017) > 0 || isbegin_quest(19018) > 0 || isbegin_quest(19019) > 0 )	{
  ....
}

 

It is hard to really optimize the script without knowing the whole code. But to make the snippet you have more manageable, you could organize your code like this:
 

for(.@i = 0; .@i < 20; .@i++) {
    if(isbegin_quest(19000 + .@i) > 0) {
        .@has_quest = 1;
        break;
    }
 }

if(getmonsterinfo(killedrid, MOB_MVPEXP) > 1 && .@has_quest)	{

}

 

Edited by Winterfox
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  38
  • Topics Per Day:  0.07
  • Content Count:  95
  • Reputation:   1
  • Joined:  11/15/22
  • Last Seen:  

On 9/6/2023 at 8:48 PM, Winterfox said:

It is hard to really optimize the script without knowing the whole code. But to make the snippet you have more manageable, you could organize your code like this:

I am sorry, I also tried that method but the thing is inside the quote should be a <condition> can be any expression similar to the <condition> in the 'if' command. I am not quite sure if doing for inside it is really possible. Thank you

OnInit:
questinfo(QTYPE_QUEST),QMARK_YELLOW, "checkquest (11114,HUNTING) == 2 || checkquest (11115,HUNTING) == 2 || checkquest (11116,HUNTING) == 2 || checkquest (11117,HUNTING) == 2 || checkquest (11118,HUNTING) == 2 || checkquest (11119,HUNTING) == 2 || checkquest (11120,HUNTING) == 2 || checkquest (11121,HUNTING) == 2 || checkquest (11122,HUNTING) == 2 || checkquest (11123,HUNTING) == 2";

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  233
  • Reputation:   86
  • Joined:  06/30/18
  • Last Seen:  

1 hour ago, namerpus18 said:

I am sorry, I also tried that method but the thing is inside the quote should be a <condition> can be any expression similar to the <condition> in the 'if' command. I am not quite sure if doing for inside it is really possible. Thank you

OnInit:
questinfo(QTYPE_QUEST),QMARK_YELLOW, "checkquest (11114,HUNTING) == 2 || checkquest (11115,HUNTING) == 2 || checkquest (11116,HUNTING) == 2 || checkquest (11117,HUNTING) == 2 || checkquest (11118,HUNTING) == 2 || checkquest (11119,HUNTING) == 2 || checkquest (11120,HUNTING) == 2 || checkquest (11121,HUNTING) == 2 || checkquest (11122,HUNTING) == 2 || checkquest (11123,HUNTING) == 2";

 

You are right, it doesn't seem like you can put anything inside the condition argument of the questinfo function that doesn't return a value directly.
It simply evaluates if the result of the script in the conditions string results in true or false, when certain events like the completion of a quest trigger a reevaluation. 

That means you can only use functions that the script engine knows and that return a value. 
So what you can do alternatively is to build the condition string dynamically. 

prontera,150,193,4	script	DEMO	124,{
	OnInit:
		setarray(.@quests, 11114, 11115, 11116, 11117, 11118, 11119, 11120, 11121, 11122, 11123);
		for(.@i = 0; .@i < getarraysize(.@quests); .@i++)
			.@condition$[.@i] = "checkquest(" + .@quests[.@i] + ", HUNTING) == 2";

		questinfo(QTYPE_QUEST, QMARK_YELLOW,  implode(.@condition$, "||"));
}

 

Edited by Winterfox
  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  38
  • Topics Per Day:  0.07
  • Content Count:  95
  • Reputation:   1
  • Joined:  11/15/22
  • Last Seen:  

10 hours ago, Winterfox said:

You are right, it doesn't seem like you can put anything inside the condition argument of the questinfo function that doesn't return a value directly.
It simply evaluates if the result of the script in the conditions string results in true or false, when certain events like the completion of a quest trigger a reevaluation. 

That means you can only use functions that the script engine knows and that return a value. 
So what you can do alternatively is to build the condition string dynamically. 

prontera,150,193,4	script	DEMO	124,{
	OnInit:
		setarray(.@quests, 11114, 11115, 11116, 11117, 11118, 11119, 11120, 11121, 11122, 11123);
		for(.@i = 0; .@i < getarraysize(.@quests); .@i++)
			.@condition$[.@i] = "checkquest(" + .@quests[.@i] + ", HUNTING) == 2";

		questinfo(QTYPE_QUEST, QMARK_YELLOW,  implode(.@condition$, "||"));
}

 

This method is something new to me, I am not quite familiar specially this "implode" thing so i will read about it and I will try this today. Thank you so much always

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...