How to make the most of custom formulae. Part #1

Nope... you generate a random number, but you don't use it anywhere else...

it should be like

n=rand(10);(n < 8)? $game.party.item[n]+=1 : nil; 0

btw... I think you just better do this using a common event rather than using the damage formula... especially if you want to show messages and stuff afterwards...
Oh, I get it now. Thanks. Also, I think I will change to a common event on this one. Thanks for the support.
Spoiler
class Game_Battler < Game_BattlerBase   def Custom_Dream_Slash(a,     (a.apply_variance([a.atk*4+a.agi*0.5+$game_actors[1].level*25-b.def*1.2,130*$game_actors[1].level].min,10));  end   def Custom_Lunar_Pierce(a,     if (a.weapons.select { |item| item.wtype_id == 11 }).size > 0      then 40 + a.atk * 6;    elsif (a.weapons.select { |item| item.wtype_id == 17 }).size > 0      then 75 + a.atk * 6 + a.def * 0.5;    else      25 + a.atk * 5;    end      end  end
I am beyond clueless on how to get this to work (and as far as I can tell the semicolons have no bearing, but I left them in just in case) and would ask for assistance from somebody that could explain this.

I did try looking up bits elsewhere, but I couldn't find anything that helped.

For clarity; the first one is supposed to be damage-capped by level and then apply variance AFTER capping; the second one deals bonus damage if you have certain weapon types equipped (e.g. you lunge forward, so it deals more damage when you use a lance or rapier than longsword or axe).
what happens actually when you use them?

btw, why are there thens in the 2nd one? don't need them... and why are there semicolons there anyways?

Also, your 2nd method doesn't return anything really... coz in that format, it will always return the last line of the method, which is nil...

it should be

def Custom_Lunar_Pierce(a, b)
    if (a.weapons.select { |item| item.wtype_id == 11 }).size > 0
      return 40 + a.atk * 6
    elsif (a.weapons.select { |item| item.wtype_id == 17 }).size > 0
      return 75 + a.atk * 6 + a.def * 0.5
    else
      return 25 + a.atk * 5
    end

end

Also, make sure that there aren't error parts in the code, since the damage eval simply returns nil if there's an error based on my experience...
I get nulls.

The thens are habit, I did not think they mattered.

Also, I somehow believed that return was only needed for booleans (and for that I could not explain)

and I tried what you wrote, I get nulls... which really confuses me. Am I actually putting 'end's where they don't belong? If I put less than this or in a different order it complains about expecting 'keyword_end' and got '$end' (or vica versa, I forget which case yielded which); yet having 3 'end's as the ending seems wrong.

[for the sake of making sure that nobody reads what I wrote describing that wrong, code]

Spoiler
Code:
class Game_Battler < Game_BattlerBase   def Custom_Dream_Slash(a,     (a.apply_variance([a.atk*4+a.agi*0.5+$game_actors[1].level*25-b.def*1.2,130*$game_actors[1].level].min,10));  end   def Custom_Lunar_Pierce(a,     if (a.weapons.select { |item| item.wtype_id == 11 }).size > 0      return 40 + a.atk * 6    elsif (a.weapons.select { |item| item.wtype_id == 17 }).size > 0      return 75 + a.atk * 6 + a.def * 0.5    else      return 25 + a.atk * 5    endend  end
I don't know if this will make a difference, but try putting some spaces into that top formula.


Also, turn on the console, and add some 'p' statements before some of the conditions, so you can see what the script is attempting to do each time.
you need explicit return statements here since ,by default, methods return whatever it is on the last line of that method... which in the case of the 2nd method, is clearly, non-existent (null/nil)... and the value that you are trying to return is in the middle of the method, so you need to explicitly tell the engine what value to return...

if ur still getting nulls for the second formula then there might be errors in that formula... maybe something is wrong with those a.weapons lines?

BTW, how are you calling it on your formula bar?
Upon adding the single character p or the whole 'p', before the 'if' or after it (did I need to place it midst the condition? I assumed that the edge would be best, saying 'start printing'?), all I get is

unexpected keyword_elsif, expecting keyword_end

elsif (a.weapons.select { |item| item.wtype_id == 17 }).size > 0
which... confuses me, but I am pretty sure the reason why is because I did it wrongly somehow?I am just so far beyond confusedcat with this

The formula bars read

"Custom_Dream_Slash(a,b)"

and

"Custom_Lunar_Pierce(a,b)"; I've had formulas work before this way and called them in that fashion (I, however, lost the working script to a dropbox error)

Code:
class Game_Battler < Game_BattlerBase   def Custom_Dream_Slash(a,     (a.apply_variance([a.atk * 4 + a.agi * 0.5 + $game_actors[1].level * 25 - b.def * 1.2, 130 * $game_actors[1].level].min, 10));  end   def Custom_Lunar_Pierce(a,     p if (a.weapons.select { |item| item.wtype_id == 11 }).size > 0      return 40 + a.atk * 6    elsif (a.weapons.select { |item| item.wtype_id == 17 }).size > 0      return 75 + a.atk * 6 + a.def * 0.5    else      return 25 + a.atk * 5    endend  end
Shaz meant p (as in print) a line before (or after) the condition to be able to see what's going on.

Something like:

Code:
  def Custom_Lunar_Pierce(a,     if (a.weapons.select { |item| item.wtype_id == 11 }).size > 0      p "weapon type 11"      return 40 + a.atk * 6    elsif (a.weapons.select { |item| item.wtype_id == 17 }).size > 0      p "weapon type 17"      return 75 + a.atk * 6 + a.def * 0.5    else      p "other weapon type"      return 25 + a.atk * 5    end  end
I actually meant something more like this:

def Custom_Lunar_Pierce(a, 😎 if (a.weapons.select { |item| item.wtype_id == 11 }).size > 0 p 'weapon type 11 equipped' p 40 * a.atk * 6 return 40 + a.atk * 6 elsif (a.weapons.select { |item| item.wtype_id == 17 }).size > 0 p 'weapon type 17 equipped' p 75 + a.atk * 6 + a.def * 0.5 return 75 + a.atk * 6 + a.def * 0.5 else p 'other weapon type equipped' p 25 + a.atk * 5 return 25 + a.atk * 5 end endSo this way, you can see which condition it's trying to run, and what the result of the calculation SHOULD be. If those are showing correctly but you're still getting nil, then the problem may be elsewhere within your formula.Can you also show us how you're calling it from the formula box? The other day, I had one that did the calculation correctly, but something else I had in the formula box was causing it to return 0 instead of what it was actually calculating.
formula bar should read a.Custom_Lunar_Pierce(a, 😎
This community is the best I think I've ever been to for assistance

I FEEL SO DERP (Xypher, thank you so much, I somehow missed that I needed the 'a.' first...)

Copying what Shaz wrote; the console returns:

"other weapon type equipped" [equipped no weapons]

30

"other weapon type equipped" [equipped weapon type 8]

930

"other weapon type equipped" [equipped weapon type 11]

935
which makes me think that the '|item| item.wtype_id' is incorrect; but I have no idea (and can't make heads nor tails of how it's incorrect). Going to try replacing those 'item' spots with 'weapon' and see if that changes anything.

edit: actually I'm an idiot

Does it start counting from 01 or from 00; because the weapon types I equipped were Rapier and Eliwan, so I might have just done all that wrongly

Spoiler
01 Soul02 Instrument

03

04 1H Sword

05 2H Sword

06 Bow

07 Dagger

08 Rapier

09 Staff

10 Rod

11 Kyogia

12 Eliwan

13 Mystic

14 Legionary

15 Lance

16 Frying Pan

17 Nalwei

18 Superior
edit2

Spoiler
the results of testing

"other weapon type equipped"

33.75

"weapon type 11 equipped"

54

"weapon type 04 equipped"

61.25

"other weapon type equipped"

37.5

"weapon type 08 equipped"

80.0

"weapon type 12 equipped"

108.0

"weapon type 12 equipped"

247.5

"weapon type 04 equipped"

61.25

"weapon type 06 equipped"

1433.3

"weapon type 07 equipped"

801

"other weapon type equipped"

52.5

"weapon type 18 equipped"

[null]

Code:
class Game_Battler < Game_BattlerBase   def Custom_Dream_Slash(a,     (a.apply_variance([a.atk * 4 + a.agi * 0.5 + $game_actors[1].level*25 - b.def*1.2,130*$game_actors[1].level].min,10));  end   def Custom_Lunar_Pierce(a,     if (a.weapons.select { |item| item.wtype_id == 4 }).size > 0      p 'weapon type 04 equipped'      p 40 + a.atk * 4.25      return 40 + a.atk * 5.25    elsif (a.weapons.select { |item| item.wtype_id == 6 }).size > 0      p 'weapon type 06 equipped'      p 50 + a.atk * 5.3      return 50 + a.atk * 5.3    elsif (a.weapons.select { |item| item.wtype_id == 7 }).size > 0      p 'weapon type 07 equipped'      p 40 + a.atk * 5 + a.agi      return 40 + a.atk * 5 + a.agi    elsif (a.weapons.select { |item| item.wtype_id == 8 }).size > 0      p 'weapon type 08 equipped'      p 55 + a.atk * 6 + a.def * 0.5      return 55 + a.atk * 6 + a.def * 0.5    elsif (a.weapons.select { |item| item.wtype_id == 11 }).size > 0      p 'weapon type 11 equipped'      p 40 + a.atk * 4 + a.agi * 2      return 40 + a.atk * 4 + a.agi * 2    elsif (a.weapons.select { |item| item.wtype_id == 12 }).size > 0      p 'weapon type 12 equipped'      p 75 + a.atk * 6 + a.def * 1.5      return 75 + a.atk * 6 + a.def * 1.5    elsif (a.weapons.select { |item| item.wtype_id == 17 }).size > 0      p 'weapon type 17 equipped'      p 75 + a.atk * 6 + a.mag * 2      return 75 + a.atk * 6 + a.mag * 2    elsif (a.weapons.select { |item| item.wtype_id == 18 }).size > 0      p 'weapon type 18 equipped'      p 100 + a.atk * 6 + a.def * 1.5 + a.agi * 2 + a.mag * 2      return 100 + a.atk * 6 + a.def * 1.5 + a.agi * 2 + a.mag * 2    else      p 'other weapon type equipped'      p 30 + a.atk * 3.75      return 30 + a.atk * 3.75    end  endend
The data starts with 1, 0 doesn't have anything in it for the $data_ objects...

btw, you get all those prints with just one test? if yes, then there's something weird with your script since it should only be able to process true for one of the conditions and not all...

wtype_id the id of the weapon type right? can we see the database for the weapon types?
Ahhh, from the help file:

skill_types


A list of skill types. A string array using skill type IDs as subscripts, with the element in the 0 position being nil.


weapon_types


A list of weapon types. A string array using weapon type IDs as subscripts, with the element in the 0 position being nil.


armor_types


A list of armor types. A string array using armor type IDs as subscripts, with the element in the 0 position being nil.


switches


A switch name list. A string array using switch IDs as subscripts, with the element in the 0 position being nil.


variables


A variable name list. A string array using variable IDs as subscripts, with the element in the 0 position being nil.
So the first weapon type in your list will be weapon type 1, not 0.


Now, they all return something useful except weapon type 18. I think that might be because a.mag - I suspect it should be a.mat instead, because I can't find a mag method for battlers. THAT might be why that one's giving you null.


Now, if they are all printing valid amounts, but you're STILL getting nil/null, it could be the way you're calling it, so you'd need to show us everything you have in the formula box.
I ran the test multiple times; yes


Also, I typed a.mag out of habit (so used to 'mag' being the abbreviation for 'magic' opposed to 'mat'), which explains why 18 nulled.


Thank you so much; I can properly adjust the skills now wheee
I know that I can use a formula to have actor X 'instruct' actor Y to hit the enemy instead of X by using:

$game.actors[2].atk*4-b.def*2

However, what I would really like to do is to have actor X select another party member to strike instead of having a pre-set choice.  Is that possible with a formula or am I going to have to go down an even more obscure path than that?

Thanks
If you need him to use a target selection,  I believe there's no way to make it run correctly using the formula bar ALONE... so you might wanna make that as a custom method of the game_battler class so that you can initiate it using the formula bar... at least the part where you pick a target, because that would probably involve quite a number of methods (like accessing target selection, defining what happens when you select a target, etc)... 

you might even need to create another target selection window just to set the custom selection behavior that you will need for this to work... or edit the OK and Cancel handlers of the default target selection so that it will work correctly...

just think of it like this:

anything that needs the user/player to do more than just use the skill will probably not be doable by using the formula bar alone... You would need to set-it up using scripts first before you run it via the formula bar... 🙂

and of course, this is assuming that the formula bar eval will actually allow you to run multiple methods that are not "instant"...
@adiktuzmiko

I was afraid it was something like that.

Unfortunately I am totally useless at scripting (that is something I intend to tackle for my next project) so I don't even understand all of your answer, let alone know how to implement it.  Oh well, I think I shall have to let the idea die.

But thanks anyway.
well, you can also try to event it using common events... though the damage will be handled thru the common events too or via a forced action or a script call...

AFAIK, it is doable in that manner and without much hassle too... and least not as much as if you try to do the selection via scripts...
adiktuzmiko is correct about target selection, but if I read your original question correctly, you were asking about user selection, especially about the $game.actors[2] - Part.

A full user selection (as in who pays for the skill and who uses up the action) isn't possible (same as with target selection), but if it's just about whose attributes are used, you can replace the fixed number 2 (the actor-ID) with a $game_variable, that will allow you to set the triggered user by that variable.

That still requires you to find a way to set the variable before the skill is executed, but it's one step farther for your game...

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-the-most-of-custom-formulae-part-1.1143/