Skip to content

Instantly share code, notes, and snippets.

@guy0090
Last active February 21, 2017 18:00
Show Gist options
  • Save guy0090/3eab0688a6e9e1d8fdc0dc17da111a63 to your computer and use it in GitHub Desktop.
Save guy0090/3eab0688a6e9e1d8fdc0dc17da111a63 to your computer and use it in GitHub Desktop.
const KYRAS_CATALYST_ID = 183456
const interval = 1 // Anything below 1 second is dangerous to use :^)
module.exports = function AutoClaim(dispatch) {
let enabled = false,
catAmount = 0,
location = null,
inventory = null,
player = null,
hasKyrasCatalysts = null,
claimer = null
dispatch.hook('sLogin', (event) => { player = event })
dispatch.hook('cPlayerLocation', (event) => { location = event })
dispatch.hook('sCompleteChronoscrollUse', 'raw', (code, data, fromServer) => { return false })
dispatch.hook('sInven', (event) => {
hasKyrasCatalysts = event.items.find((element) => {
return element.item === KYRAS_CATALYST_ID
})
})
dispatch.hook('cWhisper', (event) => {
if (/^<FONT>.autoclaim?<\/FONT>$/i.test(event.message)) {
if (!enabled) {
enabled = true
sendWhisper('Starting AutoClaim. Use .autoclaim to cancel claiming.')
claimer = setInterval(() => {
if (hasKyrasCatalysts) {
useCatalyst()
catAmount++
} else {
enabled = false
clearInterval(claimer)
if (catAmount > 0) sendWhisper('Claimed ' + catAmount + (catAmount == 1 ? ' catalyst.' : ' catalysts.' + ' Use .autoclaim to run again.'))
else sendWhisper('No catalysts found. Use .autoclaim to run again.')
catAmount = 0
}
}, interval*1000)
} else {
enabled = false
if (claimer) clearInterval(claimer)
if (catAmount == 0) sendWhisper('Stopped AutoClaim')
else sendWhisper('Stopped claiming. Claimed ' + catAmount + (catAmount == 1 ? ' catalyst' : ' catalysts') +' before canceling. Use .autoclaim to restart.')
catAmount = 0
}
return false
}
})
dispatch.hook('cChat', (event) => {
if (/^<FONT>.autoclaim?<\/FONT>$/i.test(event.message)) {
if (!enabled) {
enabled = true
sendWhisper('Starting AutoClaim. Use .autoclaim to cancel claiming.')
claimer = setInterval(() => {
if (hasKyrasCatalysts) {
useCatalyst()
catAmount++
} else {
enabled = false
clearInterval(claimer)
if (catAmount > 0) sendWhisper('Claimed ' + catAmount + (catAmount == 1 ? ' catalyst.' : ' catalysts.' + ' Use .autoclaim to run again.'))
else sendWhisper('No catalysts found. Use .autoclaim to run again.')
catAmount = 0
}
}, interval*1000)
} else {
enabled = false
if (claimer) clearInterval(claimer)
if (catAmount == 0) sendWhisper('Stopped AutoClaim')
else sendWhisper('Stopped claiming. Claimed ' + catAmount + (catAmount == 1 ? ' catalyst' : ' catalysts') +' before canceling. Use .autoclaim to restart.')
catAmount = 0
}
return false
}
})
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function useCatalyst() {
dispatch.toServer('cUseItem', {
ownerId: player.cid,
item: KYRAS_CATALYST_ID,
id: 0,
unk1: 0,
unk2: 0,
unk3: 0,
unk4: 1,
unk5: 0,
unk6: 0,
unk7: 0,
x: location.x1,
y: location.y1,
z: location.z1,
w: 0,
unk8: 0,
unk9: 0,
unk10: 0,
unk11: 1,
})
}
function sendWhisper(message) {
dispatch.toClient('sWhisper', {
player: player.cid,
unk1: 0,
gm: 0,
unk2: 0,
author: 'AutoClaim',
recipient: player.name,
message: '<FONT>' + message + '</FONT>',
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment