get actor ID of item target

Discussion in 'RGSSx Script Support' started by Malchar, Nov 12, 2019.

  1. Malchar

    Malchar Villager Member

    Messages:
    6
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMVXA
    Hello,

    I am making an item which runs a common event script. From inside the common event's script, is there a way to reference the actor ID of the actor that the item was used on?

    I basically just need the item to do stuff to whichever actor it is used on, but I don't know how to get the actor ID to use in scripts. It will only be used outside of combat, if that matters.

    I am still learning the basics of Ruby. I know Java, and I am struggling a bit with the lack of obvious "getter" functions in Ruby.

    Thank you
     
    #1
  2. Ossra

    Ossra Formerly Exhydra Veteran

    Messages:
    913
    Likes Received:
    659
    First Language:
    English
    Primarily Uses:
    RMMV
    @Malchar Sure, here is some event code and javascript that should grab the actorId whether you are in battle or on the map.

    Code:
    ◆Comment:// Determine if Party is in Battle
    ◆If:Script:$gameParty.inBattle()
      ◆Comment:// Party in Battle; store 'BattleManager._targetId' into variable 1
      ◆Control Variables:#0001 = BattleManager._action._subjectActorId + 1
      ◆
    :Else
      ◆Comment:// Party is on Map; store '$gameParty._targetActorId' into variable 1
      ◆Control Variables:#0001 = $gameParty._targetActorId
      ◆
    :End
    
    From there you can use the 'variable' option instead of the 'fixed' option when selecting actors in certain event commands, or you can grab the actor data directly via $gameActors.actor($gameVariables.value(variableId))
     
    #2
  3. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,512
    Likes Received:
    5,122
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    @Ossra I like that how many times that you answer VXA question with Javascript :D

    @Malchar the simplest thing would be assigning your actor id into a variable. You can use the damage formula for that. Even if you don't use the damage formula to deal damage or heal, but it is enough as script call.

    Write this in your formula box
    Code:
    v[x] = a.id
    Replace x with the variable id you want to use to store the actor id.

    Then in common event, use that variable to check.
     
    #3
  4. Ossra

    Ossra Formerly Exhydra Veteran

    Messages:
    913
    Likes Received:
    659
    First Language:
    English
    Primarily Uses:
    RMMV
    @TheoAllen Bah! Whenever I check the sub-forum of the post it is MV, and whenever I do not check the sub-forum of the post it is always VXA. I will learn someday.
     
    #4
    standardplayer likes this.
  5. Malchar

    Malchar Villager Member

    Messages:
    6
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMVXA
    Thank you for the reply.

    I did some additional reading and I found that a.id returns the id of the item user, and b.id returns the id of the target. In my case, I needed to use b.id, and I got it working now.

    Thank you
     
    Last edited: Nov 13, 2019
    #5

Share This Page