Err... Make this script effect party members only and not global actors

Revival

Veteran
Veteran
Joined
May 16, 2012
Messages
71
Reaction score
25
First Language
English
Primarily Uses
Hi everybody this is a simple script I had made by a friend on the old forums and now I've come to find I'm having slight issues with it.

The purpose of the script is to Check an Actor by ID, check out what weapon he has, based on that it checks for an item (the ammo) and the total of that item is output into a variable (that variable displays a gauge through another script, therefore this is my ammo bar.)

# Ammo Updater# by ???nOBodY???# Requested By: RevivalAMMO_HASH = {# WARRIOR key => [actorID, wpnID, ammoID, varID], "Raven" => [11, 1, 401, 777], "Raven" => [13, 1, 401, 777], }#Frames to wait before updatingUPDATE_DELAY = 90#==============================================================================# ** Game_Player#------------------------------------------------------------------------------# This class handles maps. It includes event starting determinants and map# scrolling functions. The instance of this class is referenced by $game_map.#==============================================================================class Game_Player < Game_Character #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- alias ammoGauge_initializer initialize def initialize ammoGauge_initializer @ammoCounter = 0 end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- alias ammoGauge_updater update def update ammoGauge_updater if @ammoCounter >= UPDATE_DELAY for ammoType in AMMO_HASH.keys actor = $game_actors[AMMO_HASH[ammoType][0]] if actor.weapons.include?($data_weapons[AMMO_HASH[ammoType][1]]) if $game_party.has_item?($data_items[AMMO_HASH[ammoType][2]]) $game_variables[AMMO_HASH[ammoType][3]] = $game_party.item_number($data_items[AMMO_HASH[ammoType][2]]) else $game_variables[AMMO_HASH[ammoType][3]] = 0 end break end end @ammoCounter=0 end @ammoCounter+=1 endendThe problem itself is simple, I even left it in there configured as 'problematic'  The issue is I have multiple actors who can use the same weapons - curiously though they are never in the party at the same time so I didn't expect this to conflict, this is a 1 player thing.  

So the issue is if I have actor 11 out the game is still checking for ammo on actor 13 even though he isn't present at all.  Since actor 13 is not even initialized nor does he have a weapon equipped this results in the gauge as always reading blank with no ammo even though Actor 11 does have it.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.


Why do you have a hash with the same key defined twice? If you put [11, 1, 401, 777] into "Raven" and then put [13, 1, 401, 777] into "Raven", then "Raven" is going to have [13, 1, 401, 777] - it's as simple as that.


Doesn't matter if the actor, is, was, or has never been in your party. If you reference a $game_actor that doesn't exist yet (because you never added them to your party), the engine will create a new $game_actor object based on the corresponding $data_actor details.


If you want them both defined, give them different names. Better to use the actor id than the actor name, as you know they will be unique.
 
Last edited by a moderator:

Revival

Veteran
Veteran
Joined
May 16, 2012
Messages
71
Reaction score
25
First Language
English
Primarily Uses
Oops, my bad, didn't realize this was a support thing I was requesting a fix but will keep that in mind.

Because the name in the Hash key is nothing more than a comment it seems, I'm no scripting master but it does nothing to the script as far as I know, its there for my own ease so I know which weapon is there.  It is the Raven, just with a different loadoat.    That name isn't the name of the actor... its the name of the gun and its only there so I know what loadout I'm setting up.  The actor IS defined by the ID, either 11 or 13 which its checking for both...

EDIT: Taking your advice I changed one of them to be named Raven2, it still does not work.  The issue is that it is checking for the other actor I'm positive that issue because when I cute the Raven2 line altogether it works fine again.  Its checking if Actor 13 has it equipped, Actor 13 does not have it equipped therefore it reads 0. 

IF the script runs chronologically its simple:
1. It sees actor 11 - doesn't care if he's in the party or not
2. It checks is actor 11 has the Raven equpped
3. It then checks the amount of lead ammo
4. It outputs to variable
5. It sees actor 13 - doesn't care if he's in the party or not
6. Checks to see if actor 13 has the Raven equipped - He does not therefore the script believes no Raven is quipped, there is no need to check ammo and as a result reads as 0 ammo and the variable gets reset to 0

Since I only ever have 1 party member at a time it seems logical to somehow make it also ensure the person is a party member somehow with a check.  I want that to be the first thing it checks... If it sees actor 13 is not in the party I want it to move on and not change the variable at all.  

 
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Try adding this:

Code:
next if !$game_party.all_members.any? {|id| AMMO_HASH[ammoType][0] == id}
before this line:
Code:
actor = $game_actors[AMMO_HASH[ammoType][0]]
That basically says to skip this iteration if the actor in that hash element is not in the party.
 
Last edited by a moderator:

Revival

Veteran
Veteran
Joined
May 16, 2012
Messages
71
Reaction score
25
First Language
English
Primarily Uses
Hmmm I get undefined error for 'all_members' when I insert the line.  Might be a VX thing,
really appreciating the help though, this stuff is beyond me. 
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Oh sorry - I'm looking at Ace.


Use $game_party.members instead of $game_party.all_members


I really never got into VX, so the differences between it and Ace are not as obvious as the differences between XP and Ace.
 

Revival

Veteran
Veteran
Joined
May 16, 2012
Messages
71
Reaction score
25
First Language
English
Primarily Uses
Well that did stop it from crashing, however it doesn't seem to be doing anything, either that or its skipping the current actor as well. 
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
ugh! Clearly I need my coffee.


I'm sorry I'm not testing these before I suggest them ... it'd require a bit of setting up in the database and configuring that I don't really want to do.

Code:
next if !$game_party.members.any? {|actor| AMMO_HASH[ammoType][0] == actor.id}
 

Revival

Veteran
Veteran
Joined
May 16, 2012
Messages
71
Reaction score
25
First Language
English
Primarily Uses
Hmm same effect.. zilch. 

And lol don't worry about it, I don't blame you on the database thing, probably an arm and a leg to set it all up. 

I can confirm now its skipping the party member as well, I removed the second info for the Raven, as I did previously and now that doesn't work either. 
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Okay, I'm taking a closer look at what the script is doing ...

Try changing it to this:

def update ammoGauge_updater if @ammoCounter >= UPDATE_DELAY for ammoType in AMMO_HASH.keys actor_id = AMMO_HASH[ammoType][0] $game_variables[AMMO_HASH[ammoType][3]] = 0 if $game_party.members.any? {|actor| actor.id == actor_id } # actor is in the party if $game_actors[actor_id].weapons.include?($data_weapons[AMMO_HASH[ammoType][1]]) # weapon is equipped $game_variables[AMMO_HASH[ammoType][3]] = $game_party.item_number($data_items[AMMO_HASH[ammoType][2]]) end end end @ammoCounter = 0 end @ammoCounter += 1endTry this ... not sure if it's correct. The original seemed to just be interested in finding the first weapon that was equipped - I suppose that makes sense if you only have one actor.If it works, but seems a bit laggy, just add a break before the 3 end lines and it'll skip any remaining checks after a weapon is found.
 

Revival

Veteran
Veteran
Joined
May 16, 2012
Messages
71
Reaction score
25
First Language
English
Primarily Uses
Okay, I'm taking a closer look at what the script is doing ...

Try this ... not sure if it's correct. 
It IS correct, all is in order, thank you so much for the help Shaz, I really appreciate it :)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
awesome! I was going to give up and cry a little if that didn't work :D
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,986
Members
137,561
Latest member
visploo100
Top