Skip to content

Instantly share code, notes, and snippets.

@lucianspec
Created March 8, 2019 07:36
Show Gist options
  • Save lucianspec/24aea8ee221abe37063e1d424b59661a to your computer and use it in GitHub Desktop.
Save lucianspec/24aea8ee221abe37063e1d424b59661a to your computer and use it in GitHub Desktop.
// Hey there!
// This is CODE, lets you control your character with code.
// If you don't know how to code, don't worry, It's easy.
// Just set attack_mode to true and ENGAGE!
var attack_mode=false
game_log("My current Speed is " + character.speed)
//Source code of: use_hp_or_mp
function my_use_hp_or_mp()
{
if(safeties && mssince(last_potion)<600) return;
var used=false;
if(new Date()<parent.next_potion) return;
if(character.max_mp - character.mp > 300) use('use_mp'),used=true;
else if(character.hp/character.max_hp <0.5) use('use_hp'),used=true;
if(used) last_potion=new Date();
}
function is_attack_cd()
{
//if(new Date()>=parent.next_attack) return true;
if(mssince(parent.next_attack) > -500) return true;
return false;
}
function tri_math(length, dx, dy) {
var dis = sqrt(dx*dx+dy*dy)
return [length/dis*dx, length/dis*dy];
}
setInterval(function(){
my_use_hp_or_mp();
loot();
//if(!attack_mode || character.rip || is_moving(character)) return;
var target=get_targeted_monster();
if(!target)
{
//target=get_nearest_monster({min_xp:600, type: "squigtoad", target: false, path_check: true});
target=get_nearest_monster({min_xp:1000, target: false, path_check: true});
//target=get_nearest_monster({min_xp:300, target: false, path_check: true});
if(target) {
change_target(target);
}
else
{
set_message("No Monsters");
target=get_nearest_monster({min_xp:500, target: false, path_check: true});
change_target(target);
return;
}
}
var a = is_attack_cd()
var b = in_attack_range(target)
//var dis=(character.speed - target.speed)/4;
//var delta=tri_math(dis,target.x-character.x,target.y-character.y)
if(a && !b) {
set_message("Approach");
move(
character.x+(target.x-character.x)/4,
character.y+(target.y-character.y)/4
);
// Walk half the distance
}
else if(!a && b) {
set_message("Running");
move(
//character.x-(target.x-character.x)/2,
//character.y-(target.y-character.y)/2
character.x-(target.x-character.x)-(target.y-character.y)/4,
character.y-(target.y-character.y)+(target.x-character.x)/4
);
}
else if(a && b) {
set_message("Attacking");
attack(target);
}
else if(!a && !b) {
set_message("Wander");
move(
character.x-(target.x-character.x)-(target.y-character.y)/4,
character.y-(target.y-character.y)+(target.x-character.x)/4
);
}
},1000/4); // Loops every 1/4 seconds.
// Register to a single character event:
character.on("level_up",function(data){
game_log("I am now level "+data.level+"!");
});
// Learn Javascript: https://www.codecademy.com/learn/learn-javascript
// Write your own CODE: https://github.com/kaansoral/adventureland
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment