Jump to content
  • 0

If funtion with getitem error


Vincent

Question


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Hi,

i have a If/ else if / else function in my script. Where player get item via getitem. If i use ony onetime "getitem" the script worked but if i add more than one "getitem" into the statsment the script dont work and create error at the mapserver:

 

Dont work (3 getitem via)

 

if (.@checker_level > 9)
											getitem 509, rand(20, 50); // white herb
											getitem 510, rand(1, 10); //  Blue herb
											getitem 521, rand(1, 5); //  Aloe Leaf
												else if (.@checker_level  > 19)
											getitem 509, rand(45, 85); // white herb
											getitem 510, rand(9, 25); //  Blue herb
											getitem 521, rand(15, 35); //  Aloe Leaf
												else
											getitem 507, rand( 10, 75); // red herb
										    getitem 508, rand(1, 10); // yellow herb

Work (only one getitem via if)

 

if (.@checker_level > 9)
											getitem 509, rand(20, 50); // white herb
											//getitem 510, rand(1, 10); //  Blue herb
											//getitem 521, rand(1, 5); //  Aloe Leaf
												else if (.@checker_level  > 19)
											getitem 509, rand(45, 85); // white herb
											//getitem 510, rand(9, 25); //  Blue herb
											//getitem 521, rand(15, 35); //  Aloe Leaf
												else
											getitem 507, rand( 10, 75); // red herb
                                                                                       //getitem 508, rand(1, 10); // yellow herb

 

 

Error:

[Error]:  Loading NPC file: npc/custom/script.txt
script error on npc/custom/tree_script.txt line 98 parse_line: expect command, missing function name or calling undeclared function
Edited by Loco
Link to comment
Share on other sites

3 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  341
  • Reputation:   43
  • Joined:  01/10/12
  • Last Seen:  


if (.@checker_level > 9) {

getitem 509, rand(20, 50); // white herb

getitem 510, rand(1, 10); // Blue herb

getitem 521, rand(1, 5); // Aloe Leaf

}

else if (.@checker_level > 19) {

getitem 509, rand(45, 85); // white herb

getitem 510, rand(9, 25); // Blue herb

getitem 521, rand(15, 35); // Aloe Leaf

}

else {

getitem 507, rand( 10, 75); // red herb

getitem 508, rand(1, 10); // yellow herb

}

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

To explain Joseph's post: you need to enclose any code after 'if' (also 'for' and 'while') with brackets, {}, when you're using more than 1 command. The brackets group all of the code under the condition, and 'else' can only follow an 'if'.

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Ah thanks :)

 

Edit: Best Awnser goes to Euphy because he also explain how it workd but both become +repuration ;)

Edited by Loco
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...