Browse Source

Conversion to command, cleanup

TeraProxy 9 years ago
parent
commit
cee4f2015d
2 changed files with 12 additions and 72 deletions
  1. 8 13
      README.md
  2. 4 59
      index.js

+ 8 - 13
README.md

@@ -2,29 +2,24 @@
 A tera-proxy module that automatically uses the items "Elite Everful Nostrum" and "Complete Crystal Bind" whenever needed.  
   
 ## Usage  
-While ingame, open a whisper chat session with "!Essentials" by typing "/w !essentials" in chat and hitting the space bar.
-This serves as the script's command interface. 
-The following commands are supported:  
-  
-* on - Enables the script (default)  
-* off - Disables the script  
+If you are playing on a non-NA server, you need to replace "ITEMS_NOSTRUM" in "index.js" with the matching item id.  
   
-Any other input returns a summary of above commands in the game.  
-  
-Alternative commands in all other chats:  
-* !essentials - Toggles between "on" and "off" state  
+While in game, open a proxy chat session by typing "/proxy" or "/8" in chat and hitting the space bar.  
+This serves as the script's command interface.  
+The following commands are supported:  
   
-Support for Pinkie Pie's command module:  
-* /proxy afk - Toggles between "on" and "off" state  
+* essentials - enable/disable Essentials  
   
 ## Safety
-Whatever you send to "!Essentials" ingame is intercepted client-side. The chat is NOT sent to the server.  
+Whatever you send to the proxy chat in game is intercepted client-side. The chat is NOT sent to the server.  
 The script makes sure that you are not dead, mounted, in a battleground or in a negotiation before using an item.  
   
 ## Credits  
 Contains code from true-everful-nostrum by Pinkie Pie https://github.com/pinkipi  
   
 ## Changelog
+### 1.2.1
+* [*] Full conversion to Pinkie Pie's command module
 ### 1.2.0
 * [+] Added support for Pinkie Pie's command module which is now a requirement
 * [+] Added randomized timers

+ 4 - 59
index.js

@@ -10,7 +10,6 @@ const ITEMS_NOSTRUM = 184659, // EU 152898, NA 184659, RU 201005
 
 module.exports = function Essentials(dispatch) {
 	let cid = null,
-		player = '',
 		slot = -1,
 		timeout = null,
 		timeoutCCB = null,
@@ -26,7 +25,6 @@ module.exports = function Essentials(dispatch) {
 
 	dispatch.hook('S_LOGIN', 1, event => {
 		({cid} = event)
-		player = event.name
 		nextUse = Date.now() + randomNumber(RANDOM_SHORT)
 		setTimeout(ccb, 20000) // check if you have a CCB 20 seconds after login
 	})
@@ -169,63 +167,10 @@ module.exports = function Essentials(dispatch) {
 	// ### Chat Hook ### //
 	// ################# //
 	
-	dispatch.hook('C_WHISPER', 1, (event) => {
-		if(event.target.toUpperCase() === "!essentials".toUpperCase()) {
-			if (/^<FONT>on?<\/FONT>$/i.test(event.message)) {
-				enabled = true
-				message('Essentials <font color="#56B4E9">enabled</font>.')
-			}
-			else if (/^<FONT>off?<\/FONT>$/i.test(event.message)) {
-				enabled = false
-				message('Essentials <font color="#E69F00">disabled</font>.')
-			}
-			else message('Commands:<br>'
-								+ ' "on" (enable Essentials),<br>'
-								+ ' "off" (disable Essentials)'
-						)
-			return false
-		}
-	})
-	
-	function message(msg) {
-		dispatch.toClient('S_WHISPER', 1, {
-			player: cid,
-			unk1: 0,
-			gm: 0,
-			unk2: 0,
-			author: '!Essentials',
-			recipient: player,
-			message: msg
-		})
-	}
-	
-	dispatch.hook('C_CHAT', 1, event => {
-		if(/^<FONT>!essentials<\/FONT>$/i.test(event.message)) {
-			if(!enabled) {
-				enabled = true
-				message('Essentials <font color="#56B4E9">enabled</font>.')
-				console.log('Essentials enabled.')
-			}
-			else {
-				enabled = false
-				message('Essentials <font color="#E69F00">disabled</font>.')
-				console.log('Essentials disabled.')
-			}
-			return false
-		}
-	})
-	
 	const command = Command(dispatch)
-	command.add('essentials', function() {
-		if(!enabled) {
-			enabled = true
-			message('Essentials <font color="#56B4E9">enabled</font>.')
-			console.log('Essentials enabled.')
-		}
-		else {
-			enabled = false
-			message('Essentials <font color="#E69F00">disabled</font>.')
-			console.log('Essentials disabled.')
-		}
+	command.add('essentials', () => {
+		enabled = !enabled
+		command.message('[Essentials] ' + (enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
+		console.log('[Essentials] ' + (enabled ? 'enabled' : 'disabled'))
 	})
 }