Bob423 52 Report post Posted May 28, 2014 So because of a rule in my game, I need items that cast spells. The rule: In order to use Mana (cast a spell) the user must channel Mana through an object. Because of this, most weapons have what is called a Mana Crystal Core. The more powerful the core, the more powerful spells it can cast (and the more the weapon increases your INT stat) The "Crystal" and "Stone" items, are special kinds of Mana Crystals, infused with certain elements and stuff. Because of this, they can be used to cast spells, but only certain kinds of spells. If you try to cast a fire spell through a Thunder Crystal, the crystal will explode. Same with if the spell is too powerful. (e.g. using Ignurentus (the Arcatis equivalent of Firaga) instead of Ignis (the Arcatis equivalent of Fire) ...I just realized this means it's a bit like Materia and I could use a Materia system if I wanted to set that up...but I don't. I want an item that deals damage and takes into account the user's INT. It's already possible to use the target's PDEF, and MDEF as well as use variance, and I have some code set up to use a formula, but I can't get something like user.int to work. Share this post Link to post Share on other sites
Saltome 16 Report post Posted May 28, 2014 You can't get it to work because it's not user.int. @active_battler is the variable that holds the actor which is used when choosing actions in battle. base_int is the method that gives you the int of the actor. But that's all irrelevant. The tricky part here is, that normally items don't care who the user is. To do this you have to change the item_effect method in Game_Battler 3 Then pass the actor as an argument, in addition to the item itself. And to add the necessary formula. But changing default code is potentially dangerous, and you should keep note of it for future reference. Here is what you have to do, in "Game_Battler 3" line 209 should be def item_effect(item), change that to def item_effect(item, actor=nil) line 259 is where the damage is calculated, I assume that's where you need to put your formula.(use actor.base_int to get the int) Lastly, "Scene_Battle 4" line 389 from target.item_effect(@item) to (@item.name.include?("rock")||@item.name.include?("crystal"))? target.item_effect(@item, @active_battler) : target.item_effect(@item)(it's a whole line) To declare an item to be magical, just put the word "rock" or "crystal" in it's name. When adding your damage formula to the item_effect method keep in mind, that the battle system will only pass an actor if the item used is actually magical, otherwise it will be nil. You can use that to add a branch so the formula only gets called when the item is magical. I suppose this will cover your needs? Share this post Link to post Share on other sites
Bob423 52 Report post Posted May 28, 2014 That helps a lot, but I have one problem. The battle system I'm using has a completely different "def make_item_action_result" (and is under Scene_Battle) which is the function that "target.item_effect(@item)" is in in the default script, but that line isn't even in the new one. Kinda worried it'll override it and cause problems. def make_item_action_result item = $data_items[@active_battler.current_action.item_id] unless $game_party.item_can_use?(item.id) @phase4_step = 1 return end if @item.consumable $game_party.lose_item(item.id, 1) end immortaling target_decision(item) @spriteset.set_action(@active_battler.actor?, @active_battler.index, item.base_action) @help_window.set_text(item.name, 1) unless item.extension.include?("HELPHIDE") playing_action @common_event_id = item.common_event_id end I also want the elements of the item to effect the damage, if that's not done already. Thanks :D Share this post Link to post Share on other sites
Saltome 16 Report post Posted May 28, 2014 (edited) Well this isn't enough, I need the rest of the script to know for sure. Edited May 30, 2014 by Saltome Share this post Link to post Share on other sites
Bob423 52 Report post Posted May 28, 2014 Well the script is kinda huge, but here's the part that has that http://pastebin.com/985hnzh2 I've edited that part too a bit Just the battle formula, and the skill formula is overwritten in another script I did for that. This is where the full script should be, but if it doesn't work, then blame Mark, because I posted about this problem like 2 weeks ago and he replied to the post, but seems to have ignored it or forgotten. http://www.gdunlimited.net/scripts/rpg-maker-xp/custom-battle-scripts/sideview-battle-system-tankentai-xp Share this post Link to post Share on other sites
Saltome 16 Report post Posted May 29, 2014 Ah, yes... Tankentai. I'm curious about perfect_item_effect, doesn't seem to be used anywhere in the script. Now the method that should be important is make_item_damage_value Change def make_item_damage_value(item) to def make_item_damage_value(item, actor) "actor.base_int"? I assume that's your doing. Go to def item_effect(item, actor=nil) that's where make_item_damage_value is called. Change effective |= make_item_damage_value(item) to effective |=(@item.name.include?("rock")||@item.name.include?("crystal"))? make_item_damage_value(item, actor) : make_item_damage_value(item)(again a whole line) That should hopefuly make the actor accessible so you can incorporate the damage formula, and enable the item declaration I told you about. If that doesn't work I'm gonna need to have a working copy of your script. Share this post Link to post Share on other sites
Bob423 52 Report post Posted May 29, 2014 the line: effective |=(@item.name.include?("Stone")||@item.name.include?("Crystal"))? make_item_damage_value(item, actor) : make_item_damage_value(item) gave an error undefined method "name" for nil:nilclass Share this post Link to post Share on other sites
Saltome 16 Report post Posted May 29, 2014 effective |=(item.name.include?("Stone")||item.name.include?("Crystal"))? make_item_damage_value(item, actor) : make_item_damage_value(item) My bad, the variable is "item" not "@item". Share this post Link to post Share on other sites
Bob423 52 Report post Posted May 29, 2014 Got the same error :( Share this post Link to post Share on other sites
Saltome 16 Report post Posted May 29, 2014 That doesn't make any sense, this is the line. effective |=(item.name.include?("Stone")||item.name.include?("Crystal"))? make_item_damage_value(item, actor) : make_item_damage_value(item) Make sure you copied it right, or if the error message really says the same thing. Share this post Link to post Share on other sites
Bob423 52 Report post Posted May 29, 2014 Oh...I must not have pressed save or something. Now I get this: Line 2279 undefined method `base_int' for nil:NilClass I also noticed that I should've changed skill.pdef_f and skill.mdef_f to item.pdef_f and item.mdef_f Share this post Link to post Share on other sites
Marked 197 Report post Posted May 30, 2014 Blame mark for a broken link... or praise mark for distributing it to 10,000 ppl? Share this post Link to post Share on other sites
Bob423 52 Report post Posted May 30, 2014 You fixed it, so it's not a big deal :P Share this post Link to post Share on other sites
Saltome 16 Report post Posted May 30, 2014 Ok, before I even try to understand the problem you are having, can either of you explain this to me: The topic preview from my email: "Oh...I must not have pressed save or something. Now it shows Script '* Sideview 2' line 2275: NameError occurred.undefined local variable or method `skill' for #<Game_Enemy:0x2861800> which is weird because it knew what skill meant before I used the code you gave me." The message according to the forum: "Oh...I must not have pressed save or something. Now I get this: Line 2279 undefined method `base_int' for nil:NilClass I also noticed that I should've changed skill.pdef_f and skill.mdef_f to item.pdef_f and item.mdef_f" So, which one is it!? For the base_int for nilclass error, you aren't paying attention... You need to add an if statement, like this: if actor #this means that when actor is equal to nil it will skip the formula, avoiding the crash. You don't need to run the formula when the actor doesn't get passed, because that means the item in use isn't magical. actor.base_int end Share this post Link to post Share on other sites
Bob423 52 Report post Posted May 30, 2014 I edited the post. You don't get an email when someone does that. I was paying attention, but clearly you've forgotten I'm still new at this and, you never said I would have to use "if actor" I was also having it test if the item uses a different damage formula by using if item.mdef_f == 100, since those are the only items that are like that. The "Stone" and "Crystal" Thing seems a bit redundant, but I added "and actor != nil" to it and it worked, even though the item I was trying to use IS "magical" and it allowed me to use the item, but now it doesn't know to use the my new formula instead of the normal item formula. And I probably should've mentioned that the "Stone" items don't do any damage, so it would be better if they used the normal item formula Share this post Link to post Share on other sites
Saltome 16 Report post Posted May 30, 2014 I assumed that's what happened with the post, but since when I can't see that people have edited their post? I mentioned to you adding a branch that checks for the actor value. You said that you changed skill.pdef_f and skill.mdef_f to item.pdef_f and item.mdef_f that might be the cause of that problem. Share this post Link to post Share on other sites
Bob423 52 Report post Posted May 30, 2014 (edited) That's not the problem. Changing it back to skill just causes problems because it's not a skill, it's an item. And the reason it doesn't show that the post has been edited is because I'm a mod and by default it's set to not show that I edited the post. I'm just used to not having to do that and I don't want to have to click that check box every time Maybe I can use something like "if item has element ID 6"? Because the Crystals already have that element. Edited May 30, 2014 by Bob423 See? This one has it Share this post Link to post Share on other sites
ShinkuAura 15 Report post Posted May 30, 2014 Don't mind me. I'm just here seeing how bob keeps failing to intergrate the script flawlessly. Saltome I smell script incompatibility. Share this post Link to post Share on other sites
Saltome 16 Report post Posted May 31, 2014 Ok, look this was fun the first couple of days, but now it's just a waste of time. Give me a copy of your scripts file in the data folder. What you want to happen and what is actually happening. Then I'll take care of it. Share this post Link to post Share on other sites
Bob423 52 Report post Posted May 31, 2014 Ok I'll PM you, but you may have to create some dummy graphics. Shouldn't be more than 1 or 2 though. Share this post Link to post Share on other sites
Saltome 16 Report post Posted June 3, 2014 I feel stupid now. Change this: def make_item_damage_value(item, actor) To this: def make_item_damage_value(item, actor=nil) Let's see where that gets us. Share this post Link to post Share on other sites
Bob423 52 Report post Posted June 3, 2014 That didn't seem to work either. Did I replace the right thing? def item_effect(item, actor=nil) self.critical = @evaded = @missed = false if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or ((item.scope == 5 or item.scope == 6) and self.hp >= 1) return false end effective = false effective |= item.common_event_id > 0 hit_result = (rand(100) < item.hit) @missed = true unless hit_result effective |= item.hit < 100 if hit_result == true effective |=(item.name.include?("Crystal"))? make_item_damage_value(item, actor) : make_item_damage_value(item) else @missed = true end self.damage = nil unless $game_temp.in_battle self.damage = POP_MISS if @missed return effective end #-------------------------------------------------------------------------- def perfect_item_effect(item) self.critical = @evaded = @missed = false if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or ((item.scope == 5 or item.scope == 6) and self.hp >= 1) return false end effective = false effective |= item.common_event_id > 0 effective |= item.hit < 100 effective |= make_item_damage_value(item) self.damage = nil unless $game_temp.in_battle self.damage = POP_MISS if @missed return effective end #-------------------------------------------------------------------------- def make_item_damage_value(item, actor=nil) if item.name.include?("Crystal") and actor != nil recover_hp = item.recover_hp_rate puts "power" puts recover_hp defendrate = 0 defendrate += (self.pdef * item.pdef_f / 100) defendrate += (self.mdef * item.mdef_f / 100) puts "defend rate" puts defendrate damage = actor.base_int * 2 damage += 3 puts "damage" puts damage damage *= (recover_hp / 100) puts "damage * power" puts damage damage -= defendrate puts "minus defense" puts damage finaldamage = damage puts ".to_i" puts finaldamage damage = finaldamage.to_i puts damage damage *= elements_correct(item.element_set) puts damage damage /= 100 puts "elements" puts damage if item.variance > 0 and recover_hp.abs > 0 amp = [recover_hp.abs * item.variance / 100, 1].max recover_hp += rand(amp+1) + rand(amp+1) - amp end recover_hp = damage * -1 else recover_hp = maxhp * item.recover_hp_rate / 100 + item.recover_hp recover_sp = maxsp * item.recover_sp_rate / 100 + item.recover_sp if recover_hp < 0 recover_hp += self.pdef * item.pdef_f / 20 recover_hp += self.mdef * item.mdef_f / 20 recover_hp = [recover_hp, 0].min end recover_hp *= elements_correct(item.element_set) recover_hp /= 100 recover_sp *= elements_correct(item.element_set) recover_sp /= 100 if item.variance > 0 and recover_hp.abs > 0 amp = [recover_hp.abs * item.variance / 100, 1].max recover_hp += rand(amp+1) + rand(amp+1) - amp end if item.variance > 0 and recover_sp.abs > 0 amp = [recover_sp.abs * item.variance / 100, 1].max recover_sp += rand(amp+1) + rand(amp+1) - amp end recover_hp /= 2 if recover_hp < 0 and self.guarding? self.damage = -recover_hp last_hp = self.hp last_sp = self.sp self.hp += recover_hp self.sp += recover_sp effective |= self.hp != last_hp effective |= self.sp != last_sp @state_changed = false effective |= states_plus(item.plus_state_set) effective |= states_minus(item.minus_state_set) if item.parameter_type > 0 and item.parameter_points != 0 case item.parameter_type when 1 @maxhp_plus += item.parameter_points when 2 @maxsp_plus += item.parameter_points when 3 @str_plus += item.parameter_points when 4 @dex_plus += item.parameter_points when 5 @agi_plus += item.parameter_points when 6 @int_plus += item.parameter_points end effective = true end if item.recover_hp_rate == 0 and item.recover_hp == 0 self.damage = "" if item.recover_sp_rate == 0 and item.recover_sp == 0 and (item.parameter_type == 0 or item.parameter_points == 0) unless @state_changed @missed = true end end end end return effective end Share this post Link to post Share on other sites
Saltome 16 Report post Posted June 3, 2014 You know I'm kinda lost right now. What do you want it to do again? Share this post Link to post Share on other sites
Bob423 52 Report post Posted June 3, 2014 ...Reread the first post then. Somehow I feel like you ignored my PM entirely. Share this post Link to post Share on other sites
Saltome 16 Report post Posted June 6, 2014 I didn't ignore anything, I just got a bit confused with conflicting information. You are rather vague with the description of what you want, so I made certain exclusions. For example, I designed my script around giving you a confortable way to declare magical items, and allowing you to use actor information in the damage calculation. You can easily make it look like the item is casting a spell by using a specific animation, altho it doesn't allow you to select the spell, at least in the implementation I had planned. Anyhow, I'm officially putting this request on hold, because it would take more effort than I want to put in, in implementing it the way I want, due to the latter reasons. Here is my summary, make_item_damage_value is the method that calculates the damage, it needs to have another argument passed in, that contains the actor which used the item. You also need to make sure that the battle system itself passes the actor data to the newly defined make_item_damage_value, or rather to item_effect which in turn calls make_item_damage_value. And lastly, script compatibility, there are at least 4 different definitions of item_effect, along all the enabled scripts. That means, to add yet another redefinition of item_effect and you have to place it bellow all the other custom scripts. While it's easy enough to prevent that from causing bugs in the existing scripts, it's even easier to cause incompatability errors in future scripts. Soo yeah, if anyone wants to do the actual implementation, feel free. Share this post Link to post Share on other sites
Bob423 52 Report post Posted June 6, 2014 Well you did help a little bit, so thanks. I'll take a look at my scripts again and see if there's anything I can do. Share this post Link to post Share on other sites
Bob423 52 Report post Posted June 10, 2014 Well I have no clue what to do so I'm bumping the topic and re-wording my problem. This is what I want: I have made 29 items that are useable in battle. Of those, 9 deal damage. The other 20 just cause status effects. Each item that deals damage, except for 1, casts a spell. The exception is "Bomb" which has fixed damage and ignores DEF. The spell casting items are literally just items that, when used, deal weak magic damage. The damage formula used should be the same as the skill formula I use, which, when used for an item, would look something like this: attack = (User's INT * 2) + (User's ATK * 3)defense = target's MDEF * (mdef_f / 100)attack2 = attack * (item's heal HP stat /100) * -1damage = attack2 - defense ATK is called PWR in my game and is the strength of the weapon. Since the item IS the weapon, it would probably be 1 or 2 (so it would add 3 or 6) mdef_f isn't very important since it's always set to 100, but basically, it's what I use to tell if the item will use a different formula. if mdef_f == 100 new_damage_formula end before factoring in DEF, the game checks the skill's (or item's) power (or how much HP it heals) and uses it as a multiplier. The magic items all heal -120 HP, so their damage multiplier is x1.2. So, in other words: ((2*INT + 3) * 1.2) - MDEF with a variance of 15. Each has two elements: Magic, and 1 of 8 others. Fire, Thunder, Ice, Water, Earth, Air, Light, and Dark Hopefully that helps. :) Share this post Link to post Share on other sites