Jump to content
  • 0

Make the player move next beside the NPC in 2x2 distance first to claim the reward


CyanZoldyck

Question


  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.01
  • Content Count:  31
  • Reputation:   0
  • Joined:  01/09/21
  • Last Seen:  

Hi script Godz! I would like to ask assistance regarding my issue. My problem is that I wanted to make the characters go beside the treasure chest first with at least 1x1 cell distance before the progress bar to open the treasure chest starts.

1st issue: Recently, I found out that players are able to cheat by doing Close Confine skill and then the looter will be able to loot the box bypassing the unitwalkto getcharid(3),getnpcid(0); that I set in my script as shown in the attached video below:

2nd issue: If you can notice, the progress bar to loot the treasure chest has started as soon as I clicked the chest. I wanted to make it that the character should go beside the chest first before the progress bar starts.

 

Please help me. I have attached the script that I am currently using. I am still a newbie and I am very willing to learn. Thank you!

wtreasure.txt

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 1

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  663
  • Reputation:   671
  • Joined:  11/12/12
  • Last Seen:  

Heya,

A few comments first:

  • I assume that this script is going to be duplicated since you have multiple copies of it in your replay.
  • I made it into a floating script instead.
  • There are no handy methods to use for making a character walk towards a target with 1 cell distance (it will try to go on top of the target). If you want something more convenient, you'll have to use unitwalk with x/y coordinates, or make your own function. Though for a starting script, unitwalkto will do.
  • Since you can break the script by simply walking away, while unitwalkto is running, it will trigger the OnOpenChest event label for some unknown reason. So you need to check the distance again. Plus, by doing so, you also prevent other type of exploits like using close confine.
  • I added an ID next to the NPC name (World Boss Treasure#ID), which is used to prevent another exploit:
    • If two players talk to the treasure at the same time, they'll both be able to get the items from the treasure box, whether or not you disabled the NPC.
    • NPC variables (those starting with a .) are shared among all the duplicated NPCs. That's why I use an unique ID to track whether the box was already looted or not.
-	script	World Boss Treasure#wb	1324,{
	getmapxy(.@map$, .@npc_x, .@npc_y, 0);
	getmapxy(.@map$, .@player_x, .@player_y, 1);
	
	.@distance = distance(.@npc_x, .@npc_y, .@player_x, .@player_y);
	
	if (.@distance > 1) {
		unitwalkto getcharid(3), getnpcid(0), strnpcinfo(0) + "::OnOpenChest";
		end;
	}
	
	goto OnOpenChest;
	end;
OnOpenChest:
	getmapxy(.@map$, .@npc_x, .@npc_y, 0);
	getmapxy(.@map$, .@player_x, .@player_y, 1);
	
	.@distance = distance(.@npc_x, .@npc_y, .@player_x, .@player_y);
	
	if (.@distance > 1) {
		end;
	}
	
	progressbar "ffff00", 10;
	.@id = atoi(strnpcinfo(2));
	
	// I presume you don't want multiple people to loot the same chest...?
	if (.npc_disabled[.@id]) {
		//dispbottom "This chest has been looted by someone else!";
		end;
	}
	
	specialeffect EF_COIN;
	
	.wb_treasure[.wb_treasure_size++] = getcharid(3);
	
	setarray .@catch, 30203, 30202, 607, 504; // List of Junk/Other
	getitem .@catch[rand(getarraysize(.@catch))], 1;
	
	disablenpc strnpcinfo(0);
	.npc_disabled[.@id] = true;
	initnpctimer;
	end;
OnReward:
	.@id = atoi(strnpcinfo(2));
	.npc_disabled[.@id] = false;
	deletearray .wb_treasure;
	enablenpc strnpcinfo(0);
	initnpctimer;
	end;
OnTimer7200000:
	disablenpc strnpcinfo(0);
	stopnpctimer;
	end;
}

prontera,150,180,3	duplicate(World Boss Treasure#wb)	World Boss Treasure#1	1324
prontera,152,180,3	duplicate(World Boss Treasure#wb)	World Boss Treasure#2	1324
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.01
  • Content Count:  31
  • Reputation:   0
  • Joined:  01/09/21
  • Last Seen:  

Update: All good and working!!! I just modified this part since I am getting the buildin_getmapxy: Invalid type 0 error.

-	getmapxy(.@map$, .@npc_x, .@npc_y, 0);
+	getmapxy(.@map$, .@npc_x, .@npc_y, BL_NPC);

I tested with skills like Close Confine and Spider Web and it's all working the way I wanted it to be.

Thank you so much Sir @Tokei I really appreciate it! More power!!!

image.png.8667cb6495390569429f2a12ce102553.png


I also want to give kudos to this very smart try and catch event here. It added more spice to my server since they both don't know who clicked the chest first XD

// I presume you don't want multiple people to loot the same chest...?
	if (.npc_disabled[.@id]) {
		dispbottom "This chest has been looted by someone else!";
		end;
	}

This case is resolved!

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