Jump to content
  • 0

If funtion with getitem error


Question

Posted (edited)

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

3 answers to this question

Recommended Posts

Posted


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
Posted

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

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