Level Requirement for Items

Started by [Faint], November 04, 2009, 04:48:06 pm

Previous topic - Next topic

[Faint]

November 04, 2009, 04:48:06 pm Last Edit: November 05, 2009, 09:32:42 am by [Faint]
ok so I am brand new at RGSS and I am trying to work on a script that allows you to designate required levels for items. I have so been able to get it to work kind of. The problem iis that it only seems to want to work for the first actor in the party. any help would be greatly appreciated.


Spoiler: ShowHide
#==============================================================================
# Level requirement Items
# Author:[Faint]
# Special Thanks: Longfellow - for helping me figure my first script out!
#
# Description: This script allows you to set Items to have a required level to
#              used by the Actor.
#
# Sidenotes: Script works great with Game_Guy's Skill Teaching Items's script.
#==============================================================================
module LRConfigs 
  def self.item(id)
    case id

# When item.id then return required_level
    when 1 then return 5
    when 3 then return 3
    end
    return 1
  end
 
end

#==============================================================================
# Game_Actor
#==============================================================================

class Game_Actor
 
  alias item_effect_lvl_requirement item_effect
  def item_effect(item)
    result = item_effect_lvl_requirement(item)
  return LRConfigs.item(id) > @level ? false : item_effect_lvl_requirement(item)
    end
   
  end
 
Scripts by me - State Requirement Skills
current project - Project: AURA

fugibo

Well, I don't see any particular reason why the script wouldn't be working, so it'd help if you uploaded a demo for someone to look at or posted your current settings/etc.

However, I can tell you that your coding is a bit off. For one, you should be subclassing Game_Actor, since I highly doubt this would even work for enemies. For another, you're ignoring the concept of expressions - you can plug any expression into an "if" statement, meaning that you can just us "LRConfigs.item(id) > @level." Note that I used "@" instead of "self.level;" it's better practice to do this, since "self.level" will only work if you've got an accessor method (a method used to access a variable from the outside) for that variable, though both should work in most cases. Also, you should probably use a ternary operator - they go something like this:

<expression> ? <expression to replace ternary statement if the first expression is true> : <expression to replace TS otherwise>


Thus, your item_effect(item) method could be written as:
return LRConfigs.item(id) > @level ? false : item_effect_lvl_requirement(item)


Hope that helps ;)

[Faint]

November 05, 2009, 09:18:50 am #2 Last Edit: November 06, 2009, 03:49:44 pm by [Faint]
heh yea I am brand new to scripting :P, but hey I tried lol. anyways thanks for the help I will try it out and see if it works out.

**edit: Hmmm if I keep the line : "result = item_effect_lvl_requirement"  , it makes it where no actor can use the item regardless of their level. and if I remove it, it allows the script to function properly on the first actor but then the rest of the actors can use the item regardless of their level. any clue as to what I might be doing wrong?
Scripts by me - State Requirement Skills
current project - Project: AURA

winkio

You shouldn't be modifying item_effect at all.  A call to item_effect should use the item on a target.  What you should be modifying is item_can_use? (or something of the sort), which is in Game_Party.  You might be able to make something work by modifying item_effect, but it just makes your game less stable/compatible.  You should modify item_can_use to have an additional parameter of a game_actor that you can check the level from.  Then, you would just need to change the 3 or so calls to item_can_use in the game scripts.

[Faint]

I feel a little smart I was looking through the script and figured I would probably need to alias item_can_use? from Game_Party but, how would I go about adding a game_actor parameter that I can check the level from?
Scripts by me - State Requirement Skills
current project - Project: AURA

winkio


alias item_can_use_later? item_can_use?
def item_can_use?(item_id, actor=actors[0])
    return (LRConfigs.item(id) > actor.level && item_can_use_later?(item_id))
end


when you declare the method, just add it in.  I made it an optional parameter with the "=actor[0]" because then you don't have to change the call from the map, just from battle.  Once you do this though, you will still need to change the call from scene_battle.

fugibo

I'd just like to point out that this is proof that the RTP scripts aren't very well thought out - item_can_use? should only be used in Game_Party from the menu, and when used as an action is should be sent to the actor, since it's an action of that actor, not the entire party.

winkio

but the actor doesn't have the items, the party does, therefore, the actor can't check anything about the items.

Blizzard

And I'd like to point out that this is the proof that the RTP scripts are actually good for the purpose they were made.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

[Faint]

sooo the script is working for the most part except that if 1 actor meets the lvl requirement then even the lower lvl actors can use the items. :(
Scripts by me - State Requirement Skills
current project - Project: AURA