Jump to content
  • 0

R> Cart NPC Script


DutchDuck

Question


  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  64
  • Reputation:   0
  • Joined:  02/23/14
  • Last Seen:  

hello

 

i was wondering if its possible to make a script when players can talk to this npc to be able to use Carts and then they are able at the same npc to change their cart? for lets say 

 

1000x  RoS_Tokens (id 7227) people get a cart

and for 100 RoS_Tokens ( id 7227 ) people can change the cart appereance from 1 / 9

 

i think somehow we have to use the #cart playername parameter  command.. but idunno thats why im asking someone out here :)

 

hope to hear anything soon :)

 

Greetings!

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  92
  • Reputation:   17
  • Joined:  08/11/12
  • Last Seen:  

Hello DutchDuck, how are you buddy?

Well, I need to consider some things before doing your request, please answer me asap.

Players are able to change their cart appearance by using the Change Cart Skill. If you want to force players to use this NPC to change their cart appearance you should block that skill by removing its quest or removing the skill itself.

Now let's move to the NPC. I'll be back soon with your request.

C ya!

EDIT---

Here is your request, please let me know if it works!

Bye!
 

prontera,150,150,5	script	Cart Rental NPC	73,{

	mes "[Sophia]";
	mes "Hello "+strcharinfo(0)+", how may I help you?";
	next;
	set .@option, select("Please, rent me a cart!:Can you change my cart appearance?");
	switch(.@option) {
		case 1:
		{
			mes "[Sophia]";
			mes "Here is what I need to rent you a cart:";
			mes "^FF0000("+.ingredients[1]+"x) - "+getitemname(.ingredients[0])+"^000000";
			next;
			mes "[Sophia]";
			mes "Have you already got everything I need?";
			next;
			if (select("Yes, sure!:Hmm not yet...") == 2) {
				mes "[Sophia]";
				mes "No problem I'm always here, please come back whenever you want!";
				close;
			}

			if (countitem(.ingredients[0]) < .ingredients[1]) {
				mes "[Sophia]";
				mes "Liar, I trusted you!";
				close2;
				emotion e_cry;
				end;
			}
			else {
				delitem .ingredients[0], .ingredients[1];
				if (!checkcart()) setcart 1;

				mes "[Sophia]";
				mes "Hope you enjoy it, bye!";
				close;
			}
		}
		case 2:
		{
			if (!checkcart()) {
				mes "[Sophia]";
				mes "You must have a cart to change its appearance.";
				close;
			}

			mes "[Sophia]";
			mes "Here is what I need to change your cart appearance:";
			mes "^FF0000("+.ingredients[3]+"x) - "+getitemname(.ingredients[2])+"^000000";
			next;
			mes "[Sophia]";
			mes "Have you already got everything I need?";
			next;
			if (select("Yes, sure!:Hmm not yet...") == 2) {
				mes "[Sophia]";
				mes "No problem I'm always here, please come back whenever you want!";
				close;
			}

			if (countitem(.ingredients[2]) < .ingredients[3]) {
				mes "[Sophia]";
				mes "Liar, I trusted you!";
				close2;
				emotion e_cry;
				end;
			}
			else {
				mes "[Sophia]";
				mes "Wow, nice!";
				mes "Which cart do you want? (1 ~ "+MAX_CART+")"; 
				next;
				input(.@cart_number, 1, MAX_CART);

				delitem .ingredients[2], .ingredients[3];
				setcart 0; // I don't know if I need to remove it before changing its appearance but I don't think so... regardless it's better to let the command here but feel free to remove it if you think you're not gonna need it.
				setcart .@cart_number;

				mes "[Sophia]";
				mes "Hope you enjoy it, bye!";
				close;
			}
		}
	}

OnInit:
	setarray .ingredients[0], 7227, 1000, // item_id, amount -> needed for renting a cart.
				  7227, 100;  // item_id, amount -> needed for changing cart appearance.
}
Edited by _Okuz_
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

Hey guys, I made one too ^^ (that looked interesting)

 

My npc is a little bit less gentle  :P

prontera,150,184,4	script	cart_npc	73,{
	.@name$ = "[ ^0066ffcart giver^000000 ]";
	// in case the skill is lost for some reason
	if (CartType && !getskilllv(39)) { mes .@name$,"Oh my, you lost the skill!","Sorry for this, I'm giving it back right away!" ; skill 39,10,3 ; setcart CartType ; close; }
	
	if (Class == 5 || Class == 10 || Class == 18 || Class == 4005 || Class == 4010 || Class == 4018 || Class == 4028 || Class == 4032 || Class == 4040 || Class == 4057 || Class == 4063 || Class == 4071 || Class == 4078 || Class == 4085 || Class == 4086 || Class == 4106 || Class == 4111) { mes .@name$,"Tryin' to fool me, ain't you? Like you even need me.." ; close; }
	mes .@name$,"Hi there! I'm the cart giver!";
	mes "I can give you a cart for a few <ITEMLINK>tokens<INFO>7227</INFO></ITEMLINK> if you want"," ";
	mes "Do want want a cart?";
	if (CartType) mes "Or remove it maybe? Don't worry you can get it back anytime whithout paying.";
	next;
	if (select("Hell yeah!:What? No") == 2) close;
	mes .@name$,"Buying a cart is worth ^0000ff1000^000000 <ITEMLINK>tokens<INFO>7227</INFO></ITEMLINK>";
	mes "Changing its type is worth ^0000ff100^000000 <ITEMLINK>tokens<INFO>7227</INFO></ITEMLINK>"," ";
	mes "You can see the cart types <URL>here<INFO>https://www.google.be/imgres?imgurl=http%3A%2F%2Fimage.noelshack.com%2Ffichiers%2F2016%2F10%2F1457361787-new-carts.png&imgrefurl=http%3A%2F%2Fwww.aurora-odin.de%2F&docid=77fw6-EyusBFrM&tbnid=KR15X3SNwU_kgM%3A&w=383&h=191&bih=775&biw=1600&ved=0ahUKEwigm_nNleLNAhVJPRoKHVzNDbsQMwgfKAMwAw&iact=mrc&uact=8</INFO></URL>" ; next;
	if (!CartType) { if ((.@select = select("Buy cart:Change type:Leave")) == 3) close; }
	else if (!checkcart()) { if ((.@select = select("Get cart back:Leave")) == 2) close; }
	else { if ((.@select = select("Buy cart:Change type:Remove cart:Leave")) == 4) close; }
	
	if (.@select == 1) {
		if (CartType && !checkcart()) { setcart CartType ; mes .@name$,"There you go again, enjoy!" ; close; }
		if (CartType && checkcart()) { mes .@name$,"You already have a cart, don't you?" ; close; }
		if (countitem(7227) < 1000) { mes .@name$,"You don't have enough tokens! Like I'd do that for free.","Come back when you can pay me hehe." ; close; }
		delitem 7227,1000;
		if (!CartType) skill 39,10,3; // are you supposed to loose it at some point??
		setcart 1 ; CartType = 1;
		mes .@name$,"There you go, enjoy your new cart!";
		close;
	}
	else if (.@select == 2) {
		if (!CartType) { mes .@name$,"You don't even have a cart! Come back when your brain is working again hehe." ; close; }
		if (countitem(7227) < 100) { mes .@name$,"You don't have enough tokens! Like I'd do that for free.","Come back when you can pay me hehe." ; close; }
		mes .@name$,"Sure, which cart would you like?","","Here is the list of <URL>carts<INFO>https://www.google.be/imgres?imgurl=http%3A%2F%2Fimage.noelshack.com%2Ffichiers%2F2016%2F10%2F1457361787-new-carts.png&imgrefurl=http%3A%2F%2Fwww.aurora-odin.de%2F&docid=77fw6-EyusBFrM&tbnid=KR15X3SNwU_kgM%3A&w=383&h=191&bih=775&biw=1600&ved=0ahUKEwigm_nNleLNAhVJPRoKHVzNDbsQMwgfKAMwAw&iact=mrc&uact=8</INFO></URL>" ; next;
		if ((.@select = select("cart 1 : cart 2 : cart 3 : cart 4 : cart 5 : cart 6 : cart 7 : cart 8 : cart 9 : leave")) == 10) close;
		if (.@select == CartType) { mes .@name$,"You already have that one, don't waste your tokens like that.." ; close; }
		delitem 7227,100;
		setcart .@select ; CartType = .@select;
		mes .@name$,"There you go, enjoy your new cart!";
		close;
	}
	else {
		if (!checkcart()) { mes .@name$,"You don't even have one.." ; close; }
		setcart 0;
		mes .@name$,"There you go, see you soon!";
		close;
	}
}

@DutchDuck I'm used to put item links everywhere but I didn't ask if your client supports it, tell me if it works

May I know why you want to make everyone able to have carts? (I'm quite curious ^^)

 

@ Okuz the 'setcart' script command alone doesn't work unless you have the pushcart skill (id: 39), you need to add it if you want to make it work.

The problem with this skill is that you can't set it permanently unless you have the required class. Although setting it temporarly should work since it's supposed to be used in item scripts so that shouldn't be much of a problem.

 

I added a few checkings that you don't have, not sure they're very useful though ^^

  • forbid merchant classes to use that script (so that they don't use it to gain skill points or whatever)
  • made impossible for players who already have a cart to buy it twice, can't change the type to your current type either (people don't like wasting money/items ^^)
  • made people able to remove their carts and get it back with no fees (having a cart is not always useful)
  • added a checking in case the skill is removed for some reason (that should solve the temporay skill setting for this case)

Ahh I should put some emotions too, I never do that and it's so nice!

 

Take care  /no1

Edited by Kurofly
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  92
  • Reputation:   17
  • Joined:  08/11/12
  • Last Seen:  

@Kurofly
You did a really good work, buddy! I forgot some checks, as I always do... And it's all about reading the Kafra script, because all those requirements were right there in the F_KafCart function. And regarding to the setcart script command, in its description they say we need to have the MC_PUSHCART skill in order to make it work... Again, it's all about reading the script documentation...  /oops

Besides that, I like your custom features like the possibility to remove and get back the cart.  /no1 

PS: I'm not used to this new script syntax that uses links and multiple messages in the same mes command. Although I know this syntax is better to keep our code clean. /hum  
PS2: You should always use emoticons and other features like effects. Those commands makes me feel like if the NPC have the capability to react to my answers.  /rice 
PS3: Personally, I don't like inline coding... What I have in mind is that sometimes we have people here that never were able to write a line of code, so I prefer to keep my scripts with a few instructions on each line, in order to make them more readable.  /gawi 
 

Here is the new version based in your considerations.

prontera,150,150,5	script	Cart Rental NPC	73,{

	function F_checkRequirements;
	function F_getCart;

	mes "[Sophia]";
	mes "Hello "+strcharinfo(0)+", how may I help you?";
	next;
	set .@option, select("Please, rent me a Pushcart!:Can you change my cart appearance?");
	if (.@option == 1) {
		if (!F_checkRequirements(6,"5:10:18:23:4006:4011:4019:4028:4033:4041:4045:4058:4064:4071:4078:4086:4087:4100:4107:4112:4190:4191")) close;
		F_getCart(0, "rent you a cart");
	}
	else {
		if (!F_checkRequirements(12,"5:10:18:23:4006:4011:4019:4028:4033:4041:4045:4058:4064:4071:4078:4086:4087:4100:4107:4112:4190:4191")) close;
		F_getCart(2, "change your cart appearance");
	}

	// ========================================
	// F_checkRequirements based on F_KafCart.
	// Arg(0): flag (bit field)
	// 		1 - Ensure that the class wanting to rent a pushcart is a class listed in the second arg
	// 		2 - Make sure the invoking character does not have a cart already
	// 		4 - Check if the player has the Pushcart skill
	// 		8 - Make sure the invoking character does have a cart already
	// Arg(1): "class_id1,class_id2,class_idN..." (string field)
	// Return: boolean
	// ========================================
	function F_checkRequirements {
		if (getarg(0) & 1) {
			if (!.size) {
				explode(.class_id$, getarg(1), ":");
				set .size, getarraysize(.class_id$);
			}
			for (set .@i, 0; .@i < .size; set .@i, .@i + 1) {
				if (Class == atoi(.class_id$[.@i])) {
					set .@checked, 1;
					break;
				}
			}
			if (!.@checked) {
				mes "[Sophia]";
				mes "I'm sorry, but the Pushcart rental service is not available for your class.";
				return 0;
			}
		}
		if (getarg(0) & 2) {
			if (checkcart()) {
				mes "[Sophia]";
				mes "You already have a Pushcart equipped.";
				mes "Unfortunately, we can't rent more than one to each customer at a time.";
				return 0;
			}
		}
		if (getarg(0) & 4) {
			if (!getskilllv("MC_PUSHCART")) {
				mes "[Kafra Employee]";
				mes "You can only rent a cart after learning the \"Push Cart\" skill.";
				return 0;
			}
		}
		if (getarg(0) & 8) {
			if (!checkcart()) {
				mes "[Sophia]";
				mes "You don't have a Pushcart equipped.";
				mes "Unfortunately, we can't change your cart appearance if you don't even have one.";
				return 0;
			}
		}
		return 1;
	}

	// ========================================
	// F_getCart
	// Arg(0): flag (0: rent, 2: appearance)
	// Arg(1): message
	// Return: void
	// ========================================
	function F_getCart {
		set .@i, getarg(0);
		set .@message$, getarg(1);

		mes "[Sophia]";
		mes "Here is what I need to "+.@message$+":";
		mes "^FF0000("+.ingredients[(.@i + 1)]+"x) - "+getitemname(.ingredients[.@i])+"^000000";
		next;
		mes "[Sophia]";
		mes "Have you already got everything I need?";
		next;
		if (select("Yes, sure!:Hmm not yet...") == 2) {
			mes "[Sophia]";
			mes "No problem I'm always here, please come back whenever you want!";
			close;
		}
		if (countitem(.ingredients[.@i]) < .ingredients[(.@i + 1)]) {
			mes "[Sophia]";
			mes "Liar, I trusted you!";
			close2;
			emotion e_cry;
			end;
		}
		if (.@i == 2) {
			mes "[Sophia]";
			mes "Wow, nice!";
			mes "Which cart do you want? ^FF0000(1 ~ "+MAX_CART+")^000000"; 
			next;
			while (input(.@cart_number, 1, MAX_CART) != 0) {
				mes "[Sophia]";
				mes "Please, chose a look between ^FF00001 and "+MAX_CART+"^000000.";
				next;
			}
			setcart 0; // I don't know if I need to remove it before changing its appearance but I don't think so... regardless it's better to let the command here but feel free to remove it if you think you're not gonna need it.
			setcart .@cart_number;
		}
		else {
			setcart;
		}

		delitem .ingredients[.@i], .ingredients[(.@i + 1)];

		mes "[Sophia]";
		mes "Hope you enjoy it, bye!";
		close;
	}

OnInit:
	setarray .ingredients[0], 7227, 1000, // item_id, amount -> needed for renting a cart.
				  7227, 100;  // item_id, amount -> needed for changing cart appearance.
}

Please read the description above each function in order to understand their behavior.

  • Merged all the checks in a function called F_checkRequirements();
  • Merged the get cart and change cart look into the same function called F_getCart();

Take care you too, and thanks for all your notes!   /ho  /ho  /ho

Edited by _Okuz_
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

 

 

I know this syntax is better to keep our code clean

/heh You're actually the first one to tell me something like this, even I don't think this way  :P

The only reason I script in such a heavy and eyes bleeding way is that having everything in the shortest space makes me able not to forget things. I know very well people would have a hard time reading it but if I did otherwise I would definetely forget things ^^

 

Really nice script, I like the way it's done, I've actually never read the kafra script but it seems it's very well done!

 

 

Just a few notes:

  • F_checkRequirements(6,...
    ...
    	// Arg(0): flag (bit field)
    	// 		1 - Ensure that the class wanting to rent a pushcart is a class listed in the second arg
    ...
    		if (getarg(0) & 1) {
    			if (!.size) {
    				explode(.class_id, getarg(1), ":");
    				set .size, getarraysize(.class_id);
    			}
    			for (set .@i, 0; .@i < .size; set .@i, .@i + 1) {
    				if (Class == .class_id[.@i]) {
    					set .@checked, 1;
    					break;
    				}
    			}
    			if (!.@checked) {
    				mes "[Sophia]";
    				mes "I'm sorry, but the Pushcart rental service is not available for your class.";
    				return 0;
    			}
    		}
    

    What's the point if you don't put the 1 bitmask? xD

          Also you can't set an integer array using the explode command cause it will return strings, I checked it just in case and your '.class_id' array is always empty 

 

  • if (getarg(0) & 4) {
    			if (!getskilllv("MC_PUSHCART")) {
    				mes "[Kafra Employee]";
    				mes "You can only rent a cart after learning the \"Push Cart\" skill.";
    				return 0;
    			}
    		}
    

    She will always tell you that you don't have the skill, you don't  give it ^^

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  64
  • Reputation:   0
  • Joined:  02/23/14
  • Last Seen:  

okay guys thanks for the scripts!

 

im still learning a lot with scripting cause im sitll new to it though but this really helps me :)

 

... Why i wanted to use carts for evreone?

 

I like carts XD

i find it very funny seeing a Wizard or a Knight on a peco running around with a cart .. 

 

 

i will see if it works when i get home and ill let you guys know :D

 

Thanks for the help!

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  92
  • Reputation:   17
  • Joined:  08/11/12
  • Last Seen:  

 

 

 

I know this syntax is better to keep our code clean

/heh You're actually the first one to tell me something like this, even I don't think this way  :P

The only reason I script in such a heavy and eyes bleeding way is that having everything in the shortest space makes me able not to forget things. I know very well people would have a hard time reading it but if I did otherwise I would definetely forget things ^^

 

Really nice script, I like the way it's done, I've actually never read the kafra script but it seems it's very well done!

 

 

Just a few notes:

  • F_checkRequirements(6,...
    ...
    	// Arg(0): flag (bit field)
    	// 		1 - Ensure that the class wanting to rent a pushcart is a class listed in the second arg
    ...
    		if (getarg(0) & 1) {
    			if (!.size) {
    				explode(.class_id, getarg(1), ":");
    				set .size, getarraysize(.class_id);
    			}
    			for (set .@i, 0; .@i < .size; set .@i, .@i + 1) {
    				if (Class == .class_id[.@i]) {
    					set .@checked, 1;
    					break;
    				}
    			}
    			if (!.@checked) {
    				mes "[Sophia]";
    				mes "I'm sorry, but the Pushcart rental service is not available for your class.";
    				return 0;
    			}
    		}
    

    What's the point if you don't put the 1 bitmask? xD

          Also you can't set an integer array using the explode command cause it will return strings, I checked it just in case and your '.class_id' array is always empty 

 

  • if (getarg(0) & 4) {
    			if (!getskilllv("MC_PUSHCART")) {
    				mes "[Kafra Employee]";
    				mes "You can only rent a cart after learning the \"Push Cart\" skill.";
    				return 0;
    			}
    		}
    

    She will always tell you that you don't have the skill, you don't  give it ^^

 

@Kurofly

Ops, my mistake.. explode is intended to be used with string arrays /no1  [FIXED]
 
Regarding the bit field, well, let's say I have an equipment or item that gives me the skill, that way I don't need to check player's class. There are several ways to get the skill and I don't know how this would be done, then I'll leave as a bit field to be able to adjust when needed.

@DutchDuck

Can you tell us how do you intend to give your players the MC_PUSHCART skill?

C ya!

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  64
  • Reputation:   0
  • Joined:  02/23/14
  • Last Seen:  

well here is the post of my ranger with a cart :D

im able to relog warp and do all things with it :)

 

ill add a screenshot ... so i dont think we need to have pushcart skill though :) sure they walk slower by then but hey people can choose to use it or not :)

post-24283-0-33435300-1467999455_thumb.jpg

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   31
  • Joined:  07/08/14
  • Last Seen:  

Do you really move slower? Judging from the npc position it seems to be mine and you shouldn't since the skill is given level 10.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  64
  • Reputation:   0
  • Joined:  02/23/14
  • Last Seen:  

i just checked it i was wrong! the movement speed stays the same :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...