Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey, I'm pretty new to the Custom NPC Mod and I'd like to add a script to my npc that will pull a value from a scoreboard objective in the init hook to determine whether or not to actually spawn/respawn.  I'm not exactly sure how to do this even after several hours of Googling lol.  Here's what I have so far:

 

var respawnScore = 0;

function init(event){
   //set respawnScore equal to value pulled from scoreboard
   event.npc.say("I have been initialized. Score: " + respawnScore);
}

 

Obviously it's missing the main component there of pulling in the value from the scoreboard haha.  Any help would be appreciated!  Thanks!

  • 1 month later...
  • Author

Thanks Noppes!  Sorry for the delayed response, thought it was going to email me when I got a response lol.  Really appreciate the help!  Here's the final script that seems to work to respawn the npc when the scoreboard value changes.  The whole resetScore thing is to ensure all the npcs with this script are reset before the scoreboard value is reset.  There's probably a cleaner way of doing it, but I'm just happy it's working now haha.

 

var score = 0;
var resetScore = 0;

function tick(event){
if(event.npc.world.getAllPlayers().length > 0){
	score = event.npc.world.getScoreboard().getPlayerScore(event.npc.world.getAllPlayers()[0].getName(),'bonfire','');
	if(score == 0){
		resetScore = 0;
	}
	if(score == 1){
		if(resetScore > 2){
			var players = event.npc.world.getAllPlayers();
			for(i=0;i<players.length;i++){
				event.npc.world.getScoreboard().setPlayerScore(players[i].getName(),'bonfire',0,'');
			}
			resetScore = 0;
			return;
		}
		if(resetScore < 1){
			event.npc.getStats().setRespawnTime(1);
			event.npc.reset();
		}
		resetScore += 1;
	}
}
}

function init(event){
event.npc.getStats().setRespawnTime(9999999);
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.