Jump to content
  • 0

[Arrays] Non-donate pvp map


sotf

Question


  • Group:  Members
  • Topic Count:  43
  • Topics Per Day:  0.01
  • Content Count:  173
  • Reputation:   9
  • Joined:  11/14/12
  • Last Seen:  

Hi rathena!

I have successfully made a not-so little script that warps someone out of a map if he's wearing a donate item, here's the code:

 

-	script	nodonatemap	-1,{

OnPCLoadMapEvent:
	getmapxy @map$,@x,@y,0;
	if (@map$ == "pvp_n_4-3") {
		if(52) >= 1 || countitem(21267) >= 1 || countitem(21268) >= 1 || countitem(21269) >= 1 || countitem(21270) >= 1 || countitem(21271) >= 1 || countitem(21272) >= 1 || countitem(21273) >= 1 || countitem(21274) >= 1 || countitem(21275) >= 1 || countitem(21276) >= 1 || countitem(21277) >= 1 || countitem(21278) >= 1 || countitem(1316) >= 1 || countitem(1588) >= 1 || countitem(1932) >= 1 || countitem(1987) >= 1 || countitem(1833) >= 1 || countitem(1700) >= 1 || countitem(13435) >= 1 || countitem(1500) >= 1 || countitem(1600) >= 1 || countitem(13080) >= 1 || countitem(13079) >= 1 )
			{
				warp "SavePoint",0,0;
				end;
			}
	}
   end;

}

But it's just too damn long so I tried doing arrays, code here:

 

-	script	nodonatemap	-1,{

setarray @donateitems[0],21849,21850,21851,21852,21267,21268,21269,21270,21271,21272,21273,21274,21275,21276,21277,21278,1316,1588,1932,1987,1833,1700,13435,1500,1600,13080,13079;

OnPCLoadMapEvent:
	getmapxy @map$,@x,@y,0;
	if (@map$ == "pvp_n_4-3") {
		if (countitem(@donateitems) >= 1)
			{
				warp "SavePoint",0,0;
				end;
			}
	}
   end;

}

my first script worked, but the second one doesn't. Can you please tell me what's wrong in it? And how do I fix it?

 


BTW I got this error on my mapserver when I tried the second one:

 

[Error]: buildin_countitem: Invalid item '0'.

 

 

Thanks in advance for those who are going to help with my noobish questions :D

 

*Sorry I am not really educated with this coding and stuffs, so bare with me please

Edited by orochimakoto
Link to comment
Share on other sites

12 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  6
  • Topics Per Day:  0.00
  • Content Count:  26
  • Reputation:   0
  • Joined:  06/25/12
  • Last Seen:  

I support yah bro! lez bump this!

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

You could try to put this part

setarray @donateitems[0],21849,21850,21851,21852,21267,21268,21269,21270,21271,21272,21273,21274,21275,21276,21277,21278,1316,1588,1932,1987,1833,1700,13435,1500,1600,13080,13079;

under a OnInit: label like this.

OnInit:
setarray @donateitems[0],21849,21850,21851,21852,21267,21268,21269,21270,21271,21272,21273,21274,21275,21276,21277,21278,1316,1588,1932,1987,1833,1700,13435,1500,1600,13080,13079;
end;

I haven't tested it, but it might work.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  43
  • Topics Per Day:  0.01
  • Content Count:  173
  • Reputation:   9
  • Joined:  11/14/12
  • Last Seen:  

^I'll try it! Thanks!

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

Oh, and I noticed you use a temporary character variable. This won't work as there seems to be no player attached to the script.

You should use .donateitems rather than @donateitems.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  43
  • Topics Per Day:  0.01
  • Content Count:  173
  • Reputation:   9
  • Joined:  11/14/12
  • Last Seen:  

ah I see, maybe that's why it's not working, thanks!

 

 

EDIT: OnInit works! Thanks a lot!

Edited by orochimakoto
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

With just this

	if (@map$ == "pvp_n_4-3") {
		if (countitem(.donateitems) >= 1)

the script will only check the first value in the array like

if (countitem(.donateitems[0]) >= 1)

You must make a loop to check all item in the array

 

 

btw you wrote

if he's wearing a donate item, here's the code:

countitem count the number of item in the inventory, items equipped include.

If you only want to check if he is wearing something, use isequippedcnt command

if ( isequippedcnt(21849,21850,21851,21852,21267,21268,21269,21270,21271,21272,21273,21274,21275,21276,21277,21278,1316,1588,1932,1987,1833,1700,13435,1500,1600,13080,13079) > 0 )
{
	warp "SavePoint",0,0;
	end;
}
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  43
  • Topics Per Day:  0.01
  • Content Count:  173
  • Reputation:   9
  • Joined:  11/14/12
  • Last Seen:  

^Ah thanks! Well I really intended to use countitem because let's say they are not wearing any donate items, but they do have some on their inventory. When they warp to the map, they will not get warped out because they are not wearing any donates, they can just wear it on the map and not get detected. So I want the script to check also their inventory :D

 

 

EDIT: By the way, can I do that too with countitem? Because I am currently having a real hard time using arrays. I tried to make another script for another map but now both scripts wont work..

will this work?

 

countitem(909,910,911) >= 1

Edited by orochimakoto
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

will this work?

countitem(909,910,911) >= 1

Nope. You must make a loop.

 

-	script	nodonatemap	-1,{
OnInit:
	setarray .donateitems[0],21849;
	.size_don = getarraysize( .donateitems );
	end;
OnPCLoadMapEvent:
	if ( strcharinfo(3) != "pvp_n_4-3" ) end;
	while( .@i < .size_don ) {
		if ( countitem( .donateitems[.@i] ) ) break;
		.@i++;
	}
	if ( .@i == .size_don ) end;	// no item found
	warp "SavePoint",0,0;
	end;
}
pvp_n_4-3	mapflag	loadevent

 

Edit : fix throw error, thanks DeadlySilence

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

Your version gives an error in case none of the items is in the player's inventory. ([Error]: buildin_countitem: Invalid item '0'.)

And a for loop would fit there better, as you have to go to a given maximum amount of loops. (Just my opinion.)

 

-	script	nodonatemap	-1,{
OnInit:
	setarray .donateitems[0],21849,21850,21851,21852,21267,21268,21269,21270,21271,21272,21273,21274,21275,21276,21277,21278,1316,1588,1932,1987,1833,1700,13435,1500,1600,13080,13079;
	end;
    
OnPCLoadMapEvent:
    
    if ("pvp_n_4-3" == strcharinfo(3)) {
    
        for (.@i = 0; .@i < getarraysize(.donateitems); .@i += 1) {
        
            if (0 < countitem(.donateitems[.@i])) {
                
                warp "SavePoint", 0, 0;
                dispbottom "You have been kicked from the map because you used the illegal item \"" + getitemname(.donateitems[.@i]) + "\"";
                end;
            }
        }
    }
    end;
}
pvp_n_4-3	mapflag	loadevent

This should work and also informs the player because of which item he has been kicked from the map.

Edited by DeadlySilence
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

Your version gives an error in case none of the items is in the player's

inventory. ([Error]: buildin_countitem: Invalid item '0'.)

Nope. It's coz the script also check in the case of max size, but there is nothing defined in max size.. so it throw an error

 

 

And a for loop would fit there better, as you have to go to a given maximum amount of loops. (Just my opinion.)

I 'm not sure to understand what you mean... The size of the array ? My max array is defined by .size_don

 

I fixed mine btw yeah, you script should working

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

Yes, I mean the size of the array.

You already know there can only be X iterations, so a "for" loop would be more suitable, since you know "the script has to repeat the task until either a special condition is met, or the very last iteration is done".

"While" loops should be mostly used to iterate through tasks of an undefined maximum length and without a linear growth (.@i grows in a linear fashion), like validating user input and repeat the input prompt until the user enters a valid value.

I don't mean this as criticism, I just wanted to suggest an alternative way :)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  43
  • Topics Per Day:  0.01
  • Content Count:  173
  • Reputation:   9
  • Joined:  11/14/12
  • Last Seen:  

Thank you so much guys! I'll try which one of these will work well on my server. I really appreciate your help :D

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