RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
How do I change values like PDEF for specific actors?

0 Members and 1 Guest are viewing this topic.

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
try doing +100

technically the program stops at 999 without a script, so that wouldn't do anything.

***
Rep:
Level 82
We learn by living...
try doing +100

technically the program stops at 999 without a script, so that wouldn't do anything.

tried setting it to 100, but how is setting a variable going to target specific characters?

basically, I want to turn this effect backwards:

Code: [Select]
Control Variables: [001: PDEF] += [Aluxis]'s PDEF

into something like

Code: [Select]
Control Variables: [001: PDEF] = 100
Control Variables: [Aluxis]'s PDEF + = [001: PDEF]

so when i want to increase Aluxis's PDEF, and then check their values in Status Menu, the numbers displayed reflect these changes.

Aluxis has a default PDEF of 153.

What do I have to do to make it say 253?

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Oh frick, I forgot you wanted specific actors.

That's gonna take a lot more work. Sorry about this.

EDIT: Try using $game_party.actors[Id of actor].base_pdef += how much you want to add.
« Last Edit: May 07, 2010, 02:06:44 PM by cozziekuns »

***
Rep:
Level 82
We learn by living...
Oh frick, I forgot you wanted specific actors.

That's gonna take a lot more work. Sorry about this.

EDIT: Try using $game_party.actors[Id of actor].base_pdef += how much you want to add.



used:
Code: [Select]
$game_party.actors[10].base_pdef += 10

output:

Code: [Select]
undefined method 'base_pdef' for nil:NilClass


I see this 'nil:NilClass' a lot.

***
Rep:
Level 82
We learn by living...
come to think of it, I haven't been able to modify any values using script. I found you can see all sorts of values by typing

p game_actors[actor number]

and

p data_actors[actor number]

but I haven't figured out how to modify any of these values in a string.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Well it's finally obvious what the problem is. I downloaded RPG Maker XP (something I should have done a long time ago before I replied to this thread), and it seems that the methods pdef, and pdef= are different (something I should have realised a long time ago, I'm facepalming myself already).

Sorry, but I can't work on it just now. Hopefully you can get this resolved quickly.

***
Rep:
Level 82
We learn by living...
Well it's finally obvious what the problem is. I downloaded RPG Maker XP (something I should have done a long time ago before I replied to this thread), and it seems that the methods pdef, and pdef= are different (something I should have realised a long time ago, I'm facepalming myself already).

Sorry, but I can't work on it just now. Hopefully you can get this resolved quickly.

i can wait a really long time actually. I'm writing a K-12 learning game and just got to long division. I'm just hoping you or someone else can figure this out before I finish the section on pre-algebra.

***
Rep:
Level 82
We learn by living...
So far I've got

$game_actors[1].base_pdef + 100
$game_actors[2].pdef + 100
$game_actors[1].eva + 95
$game_actors[2].eva + 95

I've been asking around. Someone came up with this. It doesn't work (stats don't actually change), but it doesn't crash either. Event Script is clearly different from Script editor.

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
No, it's about the same. I couldn't imagine why it wouldn't be working, especially after several people (i think) suggested this. Try throwing Modern Algebra a PM about this topic and see what he has to say about it. He's our resident scripting God and he's nice too :]

***
Rep:
Level 82
We learn by living...
Someone said stats editing like

$game_actors[1].agi += 200

or

$game_actors[2].str += 35

could work (and it does), but things like PDEF only exist for equipment so the script editor needs some kind of prompt to create PDEF independent of equipment. Now I know if I modify this line in Game Actor:

return pdef1 + pdef2 + pdef3 + pdef4 + pdef5

to anything like

return pdef1 + pdef2 + pdef3 + pdef4 + pdef5 + my_new_stat

whatever I set as my_new_stat to be, it changes accordingly, but how do I access "my_new_stat" from the event script editor?

When I created my own stamina stat, I had to define it all over the place, in the Window Base, in the Game Actor, in the window Status, and so on. But realizing I didn't have a way to access it from the game, it ended up being a mesh of two stats, Strength and Level, plus a constant. So if anyone wants to know how to make a hybrid Stat, I can totally do that, but without knowing how to make an event script to address it, it won't feel like a real attribute.

This just means I've figured out half the puzzle.

a string like this

$game_actors[10].sta += 200

still doesn't work.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Well, I kind of already knew that the base_pdef class needed changing  with a new stat, thus the reason why I assigned a variable to add to the base defense. However, the placement of Game_Actor, as well as the fact that each actor needs a specific variable makes it more complicated. Your hybrid method works because the parameter str is stored in a RPGXP file, so it's different for every actor. However, I have yet to mimic this through scripting.

I'm still new to scripting, so Modern's your best bet.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, I think valdred was on the right track, though he didn't need to do quite as much as he did. I didn't look through his code, but it probably worked - but he didn't put it in a code box so it got corrupted halfway through. Anyway, this is what I whipped up:

Code: [Select]
#==============================================================================
# ** Game_Actor
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new accessor methods - @mod_pdef; @mod_mdef
#    aliased methods - initialize; base_pdef; base_mdef
#==============================================================================

class Game_Actor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Public Instance Variables
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  attr_accessor :mod_pdef
  attr_accessor :mod_mdef
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malgstsh_intz_6hn3 initialize
  def initialize (*args)
    @mod_pdef = 0
    @mod_mdef = 0
    malgstsh_intz_6hn3 (*args)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Base PDEF
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mashin_pmdefmod_basep_8ik2 base_pdef
  def base_pdef (*args)
    return mashin_pmdefmod_basep_8ik2 (*args) + @mod_pdef # Run Original Method
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Base MDEF
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias algtash_mpdmod_mdfbse_5yh3 base_mdef
  def base_mdef (*args)
    return algtash_mpdmod_mdfbse_5yh3 (*args) + @mod_mdef # Run Original Method
  end
end

Try throwing that in the script editor, somewhere above Main but below the other default scripts.

To change the pdef or mdef of a character, use the following code in a script call:

Code: [Select]
$game_actors[actor_id].mod_pdef += x
$game_actors[actor_id].mod_mdef += y

So, something like this:

Code: [Select]
$game_actors[1].mod_pdef += 15

would add 15 to Aluxes'  PDEF. Other operations will work, such as:

Code: [Select]
-=
%=
/=
*=
=

(subtract; mod; divide; multiply; set equal to)
Anyway, tell me if you have any problems.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
I should've known you could change what the value returned instead of trying to change it from the inside.

And I have a question unrelated to the topic. Why do you always put (*args) next to your definitions? I've never seen another scripter do that before, and the help topic doesn't really explain it too well.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
It's just a safety measure in terms of compatibility. Basically, it allows you to alter a method without knowing what arguments the method expects. Now, generally, this is not going to be a problem - you'll always know what a method expects by default. But, if another scripter alters the method and adds a new argument to it, then you will get an argument error since that scripter is passing an argument to the method that your method isn't passing. However, by putting in *args, I'm bypassing that problem since the argument will get passed even though I don't know what it is.

For the most part, this won't make much of a difference. But it's just a precaution.

***
Rep:
Level 82
We learn by living...
holy crap it works!

I got so used to it crashing I'm actually quite shocked!  :o

thank you very very much everyone!
I learned lots of script this week  :D

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween