Jump to content
  • 0
Hadeszeus

Can I request this awesome script? I hope it's easy

Question

if the player step down on warps.. the warp checks the item if the user has required item he will enter the warp automatically else message "You need this item to enter on this map".. 

Share this post


Link to post
Share on other sites

13 answers to this question

Recommended Posts

  • 0

It's better to use the mapflag loadevent.

 

Why would it be? OnPCLoadMapEvent doesn't run until the player is already on the map. Your example would leave the player on the map itself after simply prompting them that they needed to have something to be there; then with that close, they'd walk happily off, confused as to why they were even told such a thing.

 

Mhalicot's approach was on the right track, but I believe the topic starter would something more seamless. Here's my method:

 

prontera,150,150,0	script	testwarp	WARPNPC,1,1,{	/*-----------------------------------------------------	Configuration	-----------------------------------------------------*/	OnInit:		.item_id = Jellopy;		.item_amount = 1;		.warp_map$ = "prontera";		.warp_x = 155;		.warp_y = 179;		end;			/*-----------------------------------------------------	Script	-----------------------------------------------------*/	OnTouch:		if (countitem(.item_id) < .item_amount) {			message strcharinfo(0), "You need "+ .item_amount +" "+ getitemname(.item_id) +" to access this warp.";		} else {			delitem .item_id, .item_amount;			warp .warp_map$, .warp_x, .warp_y;		}				end;}

Share this post


Link to post
Share on other sites
  • 0

replace your warp with this

prontera,150,150,0	script	testwarp	WARPNPC,1,1,{OnTouch:	mes "[Test Warp]";	mes "Hello "+strcharinfo(0)+"!";	mes "You need this item to enter on this map.";	mes "Do you have it?";	if(select("No:Yes") == 1) {		close;	} else {		if(!countitem(501)) { //<- item required = Apple			next;			mes "[Test Warp]";			mes "Where is it?";			close;		}		close2;		warp "izlude",0,0;		end;	}}

Share this post


Link to post
Share on other sites
  • 0

It's better to use the mapflag loadevent.

Put this inside any script file:

mapname	mapflag	loadevent
Put this inside any npc:
OnPCLoadMapEvent:	set @id, ITEMID;	set @quantity, QUANTITY;	if( strcharinfo(3) == MAPNAME )	{		if( countitem(@id) >= @quantity )			end;		mes "[Warp master]";		mes "You don't have the required item to enter this map!";		mes "Get "+@quantity+" "+getitemname(@id)+""+((@quantity > 1)?"s.":".");		close2;		warp "prontera",150,150;	}	end;
EDIT:

Corrected script

Edited by pan

Share this post


Link to post
Share on other sites
  • 0

 

Why would it be? OnPCLoadMapEvent doesn't run until the player is already on the map. Your example would leave the player on the map itself after simply prompting them that they needed to have something to be there; then with that close, they'd walk happily off, confused as to why they were even told such a thing.

 

Mhalicot's approach was on the right track, but I believe the topic starter would something more seamless. Here's my method:

 

prontera,150,150,0	script	testwarp	WARPNPC,1,1,{	/*-----------------------------------------------------	Configuration	-----------------------------------------------------*/	OnInit:		.item_id = Jellopy;		.item_amount = 1;		.warp_map$ = "prontera";		.warp_x = 155;		.warp_y = 179;		end;			/*-----------------------------------------------------	Script	-----------------------------------------------------*/	OnTouch:		if (countitem(.item_id) < .item_amount) {			message strcharinfo(0), "You need "+ .item_amount +" "+ getitemname(.item_id) +" to access this warp.";		} else {			delitem .item_id, .item_amount;			warp .warp_map$, .warp_x, .warp_y;		}				end;}

 

Ops, sorry, my mistake. It would be possible to use a warp afterwards, having to replace every warp that goes to a map would be a pain, and also every warp npc would have to mimic that invisible line that all warps have that triggers them.

Share this post


Link to post
Share on other sites
  • 0

Ops, sorry, my mistake. It would be possible to use a warp afterwards, having to replace every warp that goes to a map would be a pain, and also every warp npc would have to mimic that invisible line that all warps have that triggers them.

 

Yeah, but OnPCLoadMapEvent runs through all maps that have a loadevent mapflag, which can cause high stress on the server when several players load those maps continuously. Understandably, there are some scenarios where a map isn't accessed by warp portal and OnPCLoadMapEvent would be appropriate; however, in this case the topic starter simply wanted a portal for quest-like purposes (and likely seamless integration). Sure, you'd have to disable existing warps that you would replace this "quest warp" with, but it would make sense that this tedium would be found in sensible applications, such as blocking off all warp-portal entrances into Morroc or something - and even so, this can be done by using duplicate to copy your script over without actually having to add another file/script.

Share this post


Link to post
Share on other sites
  • 0

Yeah, but OnPCLoadMapEvent runs through all maps that have a loadevent mapflag, which can cause high stress on the server when several players load those maps continuously. Understandably, there are some scenarios where a map isn't accessed by warp portal and OnPCLoadMapEvent would be appropriate; however, in this case the topic starter simply wanted a portal for quest-like purposes (and likely seamless integration). Sure, you'd have to disable existing warps that you would replace this "quest warp" with, but it would make sense that this tedium would be found in sensible applications, such as blocking off all warp-portal entrances into Morroc or something - and even so, this can be done by using duplicate to copy your script over without actually having to add another file/script.

 

I see. Oh, and I think that after the header you should put an 'end;', if the script stays this way every time someone clicks the warp it will execute everything that's under OnInit's scope, that's unnecessary overhead. Thank you for your answer.

Share this post


Link to post
Share on other sites
  • 0

I see. Oh, and I think that after the header you should put an 'end;', if the script stays this way every time someone clicks the warp it will execute everything that's under OnInit's scope, that's unnecessary overhead. Thank you for your answer.

 

I typically wouldn't place OnInit overhead, but due to the behaviour of the WARPNPC sprite, its script won't be run when clicked upon. Add this line above the OnInit label and see for yourself:

 

message strcharinfo(0), "You touched me!";

 

However, I do concede that it would be good habit to throw an end up there in any similar situation.

Share this post


Link to post
Share on other sites
  • 0

 

I typically wouldn't place OnInit overhead, but due to the behaviour of the WARPNPC sprite, its script won't be run when clicked upon. Add this line above the OnInit label and see for yourself:

 

message strcharinfo(0), "You touched me!";
 

However, I do concede that it would be good habit to throw an end up there in any similar situation.

 

Just tested, indeed WARPNPC has this behavior.

Share this post


Link to post
Share on other sites
  • 0

 

It's better to use the mapflag loadevent.

 

Why would it be? OnPCLoadMapEvent doesn't run until the player is already on the map. Your example would leave the player on the map itself after simply prompting them that they needed to have something to be there; then with that close, they'd walk happily off, confused as to why they were even told such a thing.

 

Mhalicot's approach was on the right track, but I believe the topic starter would something more seamless. Here's my method:

 

prontera,150,150,0	script	testwarp	WARPNPC,1,1,{	/*-----------------------------------------------------	Configuration	-----------------------------------------------------*/	OnInit:		.item_id = Jellopy;		.item_amount = 1;		.warp_map$ = "prontera";		.warp_x = 155;		.warp_y = 179;		end;			/*-----------------------------------------------------	Script	-----------------------------------------------------*/	OnTouch:		if (countitem(.item_id) < .item_amount) {			message strcharinfo(0), "You need "+ .item_amount +" "+ getitemname(.item_id) +" to access this warp.";		} else {			delitem .item_id, .item_amount;			warp .warp_map$, .warp_x, .warp_y;		}				end;}

 

+1 to this. Thank you it's working. BTW How to check/add more item in .item_id for example atleast 3 or more items..

 

I tried adding comma but it's not working.

Share this post


Link to post
Share on other sites
  • 0

+1 to this. Thank you it's working. BTW How to check/add more item in .item_id for example atleast 3 or more items..

 

I tried adding comma but it's not working.

 

Here's a version that supports multiple items:

prontera,150,150,0	script	testwarp	WARPNPC,1,1,{	message strcharinfo(0), "You touched me!";	/*-----------------------------------------------------	Configuration	-----------------------------------------------------*/	OnInit:		// Item constant/ID, amount		setarray .item_id[0],	Jellopy, 1,								Clover, 5,								Fluff, 10;				// Warp destination		.warp_map$ = "prontera";		.warp_x = 155;		.warp_y = 179;		end;			/*-----------------------------------------------------	Script	-----------------------------------------------------*/	OnTouch:		// Check items		for (.@i = 0; .@i < getarraysize(.item_id); .@i += 2) {			if (countitem(.item_id[.@i]) < .item_id[.@i + 1]) {				message strcharinfo(0), "You need the following items to access this warp:";				for (.@j = 0; .@j < getarraysize(.item_id); .@j += 2) {					message strcharinfo(0), .item_id[.@j + 1] +" "+ getitemname(.item_id[.@j]);				}				message strcharinfo(0), "Access denied.";				end;			}		}				// Delete items		for (.@i = 0; .@i < getarraysize(.item_id); .@i += 2) {			delitem .item_id[.@i], .item_id[.@i + 1];		}				// Warp player		warp .warp_map$, .warp_x, .warp_y;		end;}

Share this post


Link to post
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.   Restore formatting

  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.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.