Javascript Code for user's target.

Fernyfer775

Veteran
Veteran
Joined
Oct 6, 2013
Messages
1,317
Reaction score
818
First Language
English
Hey all, so, I'm not very fluent in Javascript and have no idea how to accomplish but, I was looking to see if somebody could help me change the following a bit. The bolded part will randomly select living enemy targets and randomly hit them. I was wanting to change it so that it only hits the target the user selects.

<Custom Target Eval>
var missiles = Math.floor((Math.random()*100)+1)
var hits = 0
if (missiles >= 1 && missiles < 15) {
//4 missiles
hits = 4
}else if (missiles >= 16 && missiles < 30){
//5 missiles
hits = 5
}else if (missiles >= 31 && missiles < 51){
//6 missiles
hits = 6
}else if (missiles >= 52 && missiles < 71){
//7 missiles
hits = 7
}else if (missiles >= 72 && missiles < 88){
//8 missiles
hits = 8
}else if (missiles >= 89 && missiles < 101){
//9 missiles
hits = 9
}
for (var i = 0; i < hits; ++i) {
var member = foes.aliveMembers()[Math.floor(((Math.random()*foes.aliveMembers().length)))];
if (member) targets.push(member);

}
</Custom Target Eval>

Any help would be appreciated!
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
I think (I THINK) that most of the damage calculations are done on the reciever side.
so, the target of any used item is "self".
through "self", you then get "friends of *self*" and "opponents of *self*"
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
776
Reaction score
487
First Language
English
Primarily Uses
RMMV
The target core documentation says that if the skill is single target, 'target' references the target chosen by player when picking the skill.

I'm not at a PC right now, but that should mean that if you change the for loop so that it's pushing target to the targets array, it should target the original target multiple times (up to hits number), possibly like below (although I'm not 100% sure right now)
Code:
for (var i = 0; i < hits; ++i) {
if (target) targets.push(target);
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,045
Members
137,569
Latest member
Shtelsky
Top