| [VX] Grouper des PNJ suivant le joueur | |
|
Auteur | Message |
---|
Citadin Lv.7
Inscrit le : 07/09/2011 Messages : 186
| Sujet: [VX] Grouper des PNJ suivant le joueur Ven 14 Oct 2011 - 9:00 | |
| DescriptionCe script est une version des scripts de chenilles sauf que les PNJ sont grouppés et ne se suivent pas en file indienne. Cependant, ils se placent en file lorsque les passages sont trop étroits. InstallationCopier / coller le script au dessus de main UtilisationLe groupeur fonctionne au moyen de fonctions - group 1, 2, 3, 4, 5 => groupera les évènements 1, 2, 3, 4, 5
- add_to_troop 6, 7, 8, 9 => Ajoute au groupe les evenements 6, 7, 8, 9
- clear_troop => Fait arrêter les PNJ de suivre le héros
- remove_to_troop 1, 2, 3 => Enlève les PNJ 1, 2, 3 du groupe
- troop_speed = 4 => Modifie la vitesse du groupe a 4
- adjust_speed => Ajuste la vitesse du groupe à celle du héros
Il est tout de même déconseillé de faire de trop gros groupe, car ce script est avant tout une alternative au script de chenilles connus. Il est possible de passer au travers des PNJ du groupe (pour ne pas être bloqué) en appuyant 2 fois sur une fleche directionnelle. Code - Code:
-
#============================================================================= # Author : S4suk3, Scriptopathe # Permet de créer un groupe suivant le héro #============================================================================== # ** Game_Map #------------------------------------------------------------------------------ # This class handles maps. It includes scrolling and passage determination # functions. The instance of this class is referenced by $game_map. #============================================================================== class Game_Map #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :troop #-------------------------------------------------------------------------- # * Alias #-------------------------------------------------------------------------- alias old_setup setup alias old_update update #-------------------------------------------------------------------------- # * Object Setup #-------------------------------------------------------------------------- def setup(map_id) @troop = Array.new old_setup(map_id) end #-------------------------------------------------------------------------- # * Return an event #-------------------------------------------------------------------------- def event(id) return (id == 0) ? $game_player : $game_map.events[id] end #-------------------------------------------------------------------------- # * Returns true if the given member is in the troop #-------------------------------------------------------------------------- def troop_contains?(id) return ((@troop.find{|elt| elt.id == id}) != nil) end #-------------------------------------------------------------------------- # * Add a member into a troop #-------------------------------------------------------------------------- def troop_add(members, order=0) member = Troop::Member.new(members, order) return false if self.troop_contains? members @troop << member self.event(members).move_speed = ($game_player.move_speed)-1 return true end #-------------------------------------------------------------------------- # * Removes a member from a troop #-------------------------------------------------------------------------- def troop_remove(member) if self.troop_contains? member @troop.delete_if{|elt| elt.id == member} end end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update Troop::move(@troop) if @troop != nil old_update end #-------------------------------------------------------------------------- # * Change the speed a troop #-------------------------------------------------------------------------- def troop_speed=(value) @troop.each do |elt| self.event(elt.id).move_speed = value end end #-------------------------------------------------------------------------- # * Change the speed a troop by the player speed #-------------------------------------------------------------------------- def adjust_speed self.troop_speed = $game_player.move_speed end end # End of Game_Map
#============================================================================== # ** Game_Interpreter #------------------------------------------------------------------------------ # An interpreter for executing event commands. This class is used within the # Game_Map, Game_Troop, and Game_Event classes. #==============================================================================
class Game_Interpreter #-------------------------------------------------------------------------- # * Groups a troop #-------------------------------------------------------------------------- def group(*members) order = 1 members.each do|elt| $game_map.troop_add(elt, order) order += 1 end end #-------------------------------------------------------------------------- # * Adds members to troup #-------------------------------------------------------------------------- def add_to_troop(*members) order = $game_map.troop.length members.each do|elt| $game_map.troop_add(elt, order) order += 1 end end #-------------------------------------------------------------------------- # * Clears the troop #-------------------------------------------------------------------------- def clear_troop $game_map.troop = Array.new end #-------------------------------------------------------------------------- # * Remove members from a troop #-------------------------------------------------------------------------- def remove_to_troop(*members) members.each do|elt| $game_map.troop_remove(elt) end end #-------------------------------------------------------------------------- # * Modifiy troop_speed #-------------------------------------------------------------------------- def troop_speed=(speed) $game_map.troop_speed = speed end #-------------------------------------------------------------------------- # * Adjust speed #-------------------------------------------------------------------------- def adjust_speed $game_map.adjust_speed end end # End of Game_Interpreter
#============================================================================== # ** Game_Event #------------------------------------------------------------------------------ # This class deals with events. It handles functions including event page # switching via condition determinants, and running parallel process events. # It's used within the Game_Map class. #============================================================================== class Game_Event #-------------------------------------------------------------------------- # * Alias #-------------------------------------------------------------------------- alias old_update update #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update collide if $game_map.troop_contains? @id old_update end #-------------------------------------------------------------------------- # * Collide with a troop's member #-------------------------------------------------------------------------- def collide if(Input.trigger?(Input::LEFT) && @x+1==$game_map.event(0).x && @y==$game_map.event(0).y && $game_player.direction==4) # GhostMode temp_through = @through @through=true $game_player.move_left self.move_right # NormalMode @through=temp_through end if(Input.trigger?(Input::RIGHT) && @x-1==$game_map.event(0).x && @y==$game_map.event(0).y && $game_player.direction==6) # GhostMode temp_through = @through @through=true $game_player.move_right self.move_left # NormalMode @through=temp_through end if(Input.trigger?(Input::UP) && @x==$game_map.event(0).x && @y+1==$game_map.event(0).y && $game_player.direction==8) # GhostMode temp_through = @through @through=true $game_player.move_up self.move_down # NormalMode @through=temp_through end if(Input.trigger?(Input::DOWN) && @x==$game_map.event(0).x && @y-1==$game_map.event(0).y && $game_player.direction==2) # GhostMode temp_through = @through @through=true $game_player.move_down self.move_up # NormalMode @through=temp_through end end end # End of Game_Event
#============================================================================== # ** Game_Character #------------------------------------------------------------------------------ # This class deals with characters. It's used as a superclass of the # Game_Player and Game_Event classes. #============================================================================== class Game_Character #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :move_speed end
#-------------------------------------------------------------------------- # * Troop DATA #-------------------------------------------------------------------------- module Troop #-------------------------------------------------------------------------- # * Member of a group Definition #-------------------------------------------------------------------------- class Member attr_accessor :id, :pos def initialize(id, pos) @id = id @pos = pos end end class << self #-------------------------------------------------------------------------- # * Movement update #-------------------------------------------------------------------------- def move(troop) troop.each do |elt| $game_map.event(elt.id).move_toward_player if $game_map.event(elt.id) != nil && elt != nil && !$game_map.event(elt.id).moving? end end end # End of Singleton end # End of Troop
|
|
| |
Citadin Lv.7
Inscrit le : 15/03/2011 Messages : 167
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mar 27 Déc 2011 - 11:06 | |
| Je me suis permis d'y ajouter une petite modification - Code:
-
#============================================================================= # Author : S4suk3, Scriptopathe, Molok # Permet de créer un groupe suivant le héro #============================================================================== # ** Game_Map #------------------------------------------------------------------------------ # This class handles maps. It includes scrolling and passage determination # functions. The instance of this class is referenced by $game_map. #============================================================================== class Game_Map #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :troop #-------------------------------------------------------------------------- # * Alias #-------------------------------------------------------------------------- alias old_setup setup alias old_update update #-------------------------------------------------------------------------- # * Object Setup #-------------------------------------------------------------------------- def setup(map_id) @troop = Array.new old_setup(map_id) end #-------------------------------------------------------------------------- # * Return an event #-------------------------------------------------------------------------- def event(id) return (id == 0) ? $game_player : $game_map.events[id] end #-------------------------------------------------------------------------- # * Returns true if the given member is in the troop #-------------------------------------------------------------------------- def troop_contains?(id) return ((@troop.find{|elt| elt.id == id}) != nil) end #-------------------------------------------------------------------------- # * Add a member into a troop #-------------------------------------------------------------------------- def troop_add(members, order=0) member = Troop::Member.new(members, order) return false if self.troop_contains? members @troop << member self.event(members).move_speed = ($game_player.move_speed)-1 return true end #-------------------------------------------------------------------------- # * Removes a member from a troop #-------------------------------------------------------------------------- def troop_remove(member) if self.troop_contains? member @troop.delete_if{|elt| elt.id == member} end end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update Troop::move(@troop) if @troop != nil old_update end #-------------------------------------------------------------------------- # * Change the speed a troop #-------------------------------------------------------------------------- def troop_speed=(value) @troop.each do |elt| self.event(elt.id).move_speed = value end end #-------------------------------------------------------------------------- # * Change the speed a troop by the player speed #-------------------------------------------------------------------------- def adjust_speed self.troop_speed = $game_player.move_speed end end # End of Game_Map
#============================================================================== # ** Game_Interpreter #------------------------------------------------------------------------------ # An interpreter for executing event commands. This class is used within the # Game_Map, Game_Troop, and Game_Event classes. #==============================================================================
class Game_Interpreter #-------------------------------------------------------------------------- # * Groups a troop #-------------------------------------------------------------------------- def group(*members) order = 1 members.each do|elt| $game_map.troop_add(elt, order) order += 1 end end #-------------------------------------------------------------------------- # * Adds members to troup #-------------------------------------------------------------------------- def add_to_troop(*members) order = $game_map.troop.length members.each do|elt| $game_map.troop_add(elt, order) order += 1 end end #-------------------------------------------------------------------------- # * Clears the troop #-------------------------------------------------------------------------- def clear_troop $game_map.troop = Array.new end #-------------------------------------------------------------------------- # * Remove members from a troop #-------------------------------------------------------------------------- def remove_to_troop(*members) members.each do|elt| $game_map.troop_remove(elt) end end #-------------------------------------------------------------------------- # * Modifiy troop_speed #-------------------------------------------------------------------------- def troop_speed=(speed) $game_map.troop_speed = speed end #-------------------------------------------------------------------------- # * Adjust speed #-------------------------------------------------------------------------- def adjust_speed $game_map.adjust_speed end end # End of Game_Interpreter
#============================================================================== # ** Game_Event #------------------------------------------------------------------------------ # This class deals with events. It handles functions including event page # switching via condition determinants, and running parallel process events. # It's used within the Game_Map class. #============================================================================== class Game_Event #-------------------------------------------------------------------------- # * Alias #-------------------------------------------------------------------------- alias old_update update #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update collide if $game_map.troop_contains? @id old_update end #-------------------------------------------------------------------------- # * Collide with a troop's member #-------------------------------------------------------------------------- def collide if(Input.trigger?(Input::LEFT) && @x+1==$game_map.event(0).x && @y==$game_map.event(0).y && $game_player.direction==4) temp_through = @through @through=true $game_player.move_left self.move_right @through=temp_through end if(Input.trigger?(Input::RIGHT) && @x-1==$game_map.event(0).x && @y==$game_map.event(0).y && $game_player.direction==6) temp_through = @through @through=true $game_player.move_right self.move_left @through=temp_through end if(Input.trigger?(Input::UP) && @x==$game_map.event(0).x && @y+1==$game_map.event(0).y && $game_player.direction==8) temp_through = @through @through=true $game_player.move_up self.move_down @through=temp_through end if(Input.trigger?(Input::DOWN) && @x==$game_map.event(0).x && @y-1==$game_map.event(0).y && $game_player.direction==2) temp_through = @through @through=true $game_player.move_down self.move_up @through=temp_through end end end # End of Game_Event
#============================================================================== # ** Game_Character #------------------------------------------------------------------------------ # This class deals with characters. It's used as a superclass of the # Game_Player and Game_Event classes. #============================================================================== class Game_Character #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :move_speed #-------------------------------------------------------------------------- # * Calculate X Distance From other_event #-------------------------------------------------------------------------- def distance_x_from_event(event) sx = @x - event.x if $game_map.loop_horizontal? if sx.abs > $game_map.width / 2 sx -= $game_map.width end end return sx end #-------------------------------------------------------------------------- # * Calculate Y Distance From other_event #-------------------------------------------------------------------------- def distance_y_from_event(event) sy = @y - event.y if $game_map.loop_vertical? if sy.abs > $game_map.height / 2 sy -= $game_map.height end end return sy end #-------------------------------------------------------------------------- # * Move toward Event #-------------------------------------------------------------------------- def move_toward_event(other_event) event = $game_map.event(other_event) sx = distance_x_from_event(event) sy = distance_y_from_event(event) if sx != 0 or sy != 0 if sx.abs > sy.abs sx > 0 ? move_left : move_right if @move_failed and sy != 0 sy > 0 ? move_up : move_down end else sy > 0 ? move_up : move_down if @move_failed and sx != 0 sx > 0 ? move_left : move_right end end move_toward_player if @move_failed && $game_player.moving? end end end
#-------------------------------------------------------------------------- # * Troop DATA #-------------------------------------------------------------------------- module Troop #-------------------------------------------------------------------------- # * Member of a group Definition #-------------------------------------------------------------------------- class Member attr_accessor :id, :pos def initialize(id, pos) @id = id @pos = pos end end class << self #-------------------------------------------------------------------------- # * Movement update #-------------------------------------------------------------------------- def move(troop) order = 0 before = 0 troop.each do |elt| if $game_map.event(elt.id) != nil && elt != nil && !$game_map.event(elt.id).moving? if order == 0 $game_map.event(elt.id).move_toward_player before = elt.id else $game_map.event(elt.id).move_toward_event(before) end end $game_map.event(elt.id).turn_toward_player unless $game_map.event(elt.id).moving? order += 1 end end end # End of Singleton end # End of Troop
|
|
| |
Citadin Lv.7
Age : 29 Inscrit le : 17/05/2011 Messages : 153
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mar 27 Déc 2011 - 15:47 | |
| Super! Ça va beaucoup me servir! Juste une question: la fonction suivre le héros fait en sorte que le groupe vienne vers le joueur même quand il est à l'arrêt? |
|
| |
Citadin Lv.7
Inscrit le : 15/03/2011 Messages : 167
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mar 27 Déc 2011 - 15:53 | |
| Oui. Cependant, il y a une limite. Si le Level Design est trop "labyrinthodonte", ils seront bloqué (ce qui est normal, je n'ai pas implémenté de Pathfinding parce que c'est lourd et chiant mais dans une version future pourquoi pas). Ce script permet tout de même de bloquer moins souvent les personnages que avec l'ancienne routine de recherche de case. |
|
| |
Citadin Lv.7
Age : 29 Inscrit le : 17/05/2011 Messages : 153
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mar 27 Déc 2011 - 16:48 | |
| C'est parce que j'aimerais mettre en place un genre de patrouille qui viendrait vers le héros quand il fais certaines actions. |
|
| |
Citadin Lv.7
Inscrit le : 15/03/2011 Messages : 167
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mar 27 Déc 2011 - 17:05 | |
| Hum, je pense que je vais releaser une version plus indépendante dans les jours a venir pour que tu puisse faire ce que tu veux. |
|
| |
Citadin Lv.7
Age : 29 Inscrit le : 17/05/2011 Messages : 153
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mar 27 Déc 2011 - 17:40 | |
| Ok merci |
|
| |
Invité
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mer 28 Déc 2011 - 20:56 | |
| Ok, ça marche, j'ai testé et regardé le code. Ça a un comportement un peu chaotique parfois, mais ça marche pas mal !
+3 de participation pour S4suk3 et +2 pour Molok |
|
| |
Citadin Lv.7
Inscrit le : 15/03/2011 Messages : 167
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mar 3 Jan 2012 - 15:22 | |
| Petite création de s4suk3 mais qu'il m'a permis de publier ! Dans certains cas, les PNJ's mobiles peuvent détruire le level design d'une map en bloquant (a cause de leur mouvement aléatoire) un chemin étroit. Ce script permet que pour les PNJ au même niveau que le heros et qui bougent, si on s'approche d'eux et qu'on appuie 2 fois dans leur directions, il change de place avec le héros. - Code:
-
class Game_Event alias vx_update update def update collide if @move_type != 0 and @priority_type == 1 vx_update end end il s'utilise avec le groupeur |
|
| |
Invité
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mar 3 Jan 2012 - 15:26 | |
| Ah, ça c'est vraiment pratique, je trouve que ce script est une très bonne utilisation de la méthode 'collide' développée pour le groupeur ! Simple et efficace, mais il fallait y penser ! Je rajoute 1 point de participation pour Sasuk3 et un pour Molok ! |
|
| |
Voyageur Lv.10
Age : 28 Inscrit le : 24/10/2011 Messages : 411
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mar 3 Jan 2012 - 16:28 | |
| Pas mal le script,merci du partage |
|
| |
Citadin Lv.7
Inscrit le : 15/03/2011 Messages : 167
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mar 3 Jan 2012 - 18:53 | |
| Je l'ai un peu modifié, maintenant ils ont des comportements plus rigolos - Code:
-
#============================================================================= # Author : S4suk3, Scriptopathe, Molok # Permet de créer un groupe suivant le héro #============================================================================== # ** Game_Map #------------------------------------------------------------------------------ # This class handles maps. It includes scrolling and passage determination # functions. The instance of this class is referenced by $game_map. #============================================================================== class Game_Map #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :troop #-------------------------------------------------------------------------- # * Alias #-------------------------------------------------------------------------- alias old_setup setup alias old_update update #-------------------------------------------------------------------------- # * Object Setup #-------------------------------------------------------------------------- def setup(map_id) @troop = Array.new old_setup(map_id) end #-------------------------------------------------------------------------- # * Return an event #-------------------------------------------------------------------------- def event(id) return (id == 0) ? $game_player : $game_map.events[id] end #-------------------------------------------------------------------------- # * Returns true if the given member is in the troop #-------------------------------------------------------------------------- def troop_contains?(id) return ((@troop.find{|elt| elt.id == id}) != nil) end #-------------------------------------------------------------------------- # * Add a member into a troop #-------------------------------------------------------------------------- def troop_add(members, order=0) member = Troop::Member.new(members, order) return false if self.troop_contains? members @troop << member self.event(members).move_speed = ($game_player.move_speed)-1 return true end #-------------------------------------------------------------------------- # * Removes a member from a troop #-------------------------------------------------------------------------- def troop_remove(member) if self.troop_contains? member @troop.delete_if{|elt| elt.id == member} end end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update @troop.sort{|event1, event2|event1 <=> event2} Troop::move(@troop) if @troop != nil old_update end #-------------------------------------------------------------------------- # * Change the speed a troop #-------------------------------------------------------------------------- def troop_speed=(value) @troop.each do |elt| self.event(elt.id).move_speed = value end end #-------------------------------------------------------------------------- # * Change the speed a troop by the player speed #-------------------------------------------------------------------------- def adjust_speed self.troop_speed = $game_player.move_speed end end # End of Game_Map
#============================================================================== # ** Game_Interpreter #------------------------------------------------------------------------------ # An interpreter for executing event commands. This class is used within the # Game_Map, Game_Troop, and Game_Event classes. #==============================================================================
class Game_Interpreter #-------------------------------------------------------------------------- # * Groups a troop #-------------------------------------------------------------------------- def group(*members) order = 1 members.each do|elt| $game_map.troop_add(elt, order) order += 1 end end #-------------------------------------------------------------------------- # * Adds members to troup #-------------------------------------------------------------------------- def add_to_troop(*members) order = $game_map.troop.length members.each do|elt| $game_map.troop_add(elt, order) order += 1 end end #-------------------------------------------------------------------------- # * Clears the troop #-------------------------------------------------------------------------- def clear_troop $game_map.troop = Array.new end #-------------------------------------------------------------------------- # * Remove members from a troop #-------------------------------------------------------------------------- def remove_to_troop(*members) members.each do|elt| $game_map.troop_remove(elt) end end #-------------------------------------------------------------------------- # * Modifiy troop_speed #-------------------------------------------------------------------------- def troop_speed=(speed) $game_map.troop_speed = speed end #-------------------------------------------------------------------------- # * Adjust speed #-------------------------------------------------------------------------- def adjust_speed $game_map.adjust_speed end end # End of Game_Interpreter
#============================================================================== # ** Game_Event #------------------------------------------------------------------------------ # This class deals with events. It handles functions including event page # switching via condition determinants, and running parallel process events. # It's used within the Game_Map class. #============================================================================== class Game_Event #-------------------------------------------------------------------------- # * Alias #-------------------------------------------------------------------------- alias old_update update #-------------------------------------------------------------------------- # * Compare proximity with heroes #-------------------------------------------------------------------------- def <=>(other_event) distance = lambda{|event| Math.hypot((event.x - $game_player.x), (event.y-$game_player.y))} return distance.call(self) > distance.call(other_event) ? 1 : distance.call(self) == distance.call(other_event) ? 0 : -1 end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update collide if $game_map.troop_contains? @id old_update end #-------------------------------------------------------------------------- # * Collide with a troop's member #-------------------------------------------------------------------------- def collide if(Input.trigger?(Input::LEFT) && @x+1==$game_map.event(0).x && @y==$game_map.event(0).y && $game_player.direction==4) temp_through = @through @through=true $game_player.move_left self.move_right @through=temp_through end if(Input.trigger?(Input::RIGHT) && @x-1==$game_map.event(0).x && @y==$game_map.event(0).y && $game_player.direction==6) temp_through = @through @through=true $game_player.move_right self.move_left @through=temp_through end if(Input.trigger?(Input::UP) && @x==$game_map.event(0).x && @y+1==$game_map.event(0).y && $game_player.direction==8) temp_through = @through @through=true $game_player.move_up self.move_down @through=temp_through end if(Input.trigger?(Input::DOWN) && @x==$game_map.event(0).x && @y-1==$game_map.event(0).y && $game_player.direction==2) temp_through = @through @through=true $game_player.move_down self.move_up @through=temp_through end end end # End of Game_Event
#============================================================================== # ** Game_Character #------------------------------------------------------------------------------ # This class deals with characters. It's used as a superclass of the # Game_Player and Game_Event classes. #============================================================================== class Game_Character #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :move_speed #-------------------------------------------------------------------------- # * Calculate X Distance From other_event #-------------------------------------------------------------------------- def distance_x_from_event(event) sx = @x - event.x if $game_map.loop_horizontal? if sx.abs > $game_map.width / 2 sx -= $game_map.width end end return sx end #-------------------------------------------------------------------------- # * Calculate Y Distance From other_event #-------------------------------------------------------------------------- def distance_y_from_event(event) sy = @y - event.y if $game_map.loop_vertical? if sy.abs > $game_map.height / 2 sy -= $game_map.height end end return sy end #-------------------------------------------------------------------------- # * Move toward Event #-------------------------------------------------------------------------- def move_toward_event(other_event) event = $game_map.event(other_event) sx = distance_x_from_event(event) sy = distance_y_from_event(event) if sx != 0 or sy != 0 if sx.abs > sy.abs sx > 0 ? move_left : move_right if @move_failed and sy != 0 sy > 0 ? move_up : move_down end else sy > 0 ? move_up : move_down if @move_failed and sx != 0 sx > 0 ? move_left : move_right end end move_toward_player if @move_failed && $game_player.moving? #move_random if @move_failed && $game_player.moving? end end end
#-------------------------------------------------------------------------- # * Troop DATA #-------------------------------------------------------------------------- module Troop #-------------------------------------------------------------------------- # * Member of a group Definition #-------------------------------------------------------------------------- class Member attr_accessor :id, :pos def initialize(id, pos) @id = id @pos = pos end def <=>(other_member) return $game_map.event(@id) <=> $game_map.event(other_member.id) end end class << self #-------------------------------------------------------------------------- # * Movement update #-------------------------------------------------------------------------- def move(troop) order = 0 before = 0 troop.each do |elt| if $game_map.event(elt.id) != nil && elt != nil && !$game_map.event(elt.id).moving? if order == 0 $game_map.event(elt.id).move_toward_player else $game_map.event(elt.id).move_toward_event(before) end before = elt.id end $game_map.event(elt.id).turn_toward_player unless $game_map.event(elt.id).moving? order += 1 end end end # End of Singleton end # End of Troop
Je n'ai pas encore écris le Pathfinding (flemme), donc le script a ses limites. |
|
| |
Maître des Duels
Age : 32 Inscrit le : 29/07/2009 Messages : 7841
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mar 3 Jan 2012 - 23:16 | |
| C'est bof. Y'a pas de fonction pour faire cuire des frites.
Salut ! Si tu lis ce message, c'est que tu as soit édité (vilain/e modo/admin/angel) ou alors que tu as cité. Sache que c'est un troll et que Molok saura comprendre ce que veut dire ce message codé. Merci de ne pas garnir mon message d'inepties ou alors de tenter de me démontrer argument par argument que je devrais pas me moquer de Molok car il a un pseudo à 5 lettres et de ne pas dénigrer la Belgique sous prétexte que leur drapeau est pas fashion car je n'en tiendrais pas compte du tout étant donné que je me fous totalement de l'avis de autres en ma condition de moralisateur trolloll et informaticien de renomée mondiale à l'IUT d'Amiens à programmer un Monopoly qui ne sera surement jamais terminé. D'ailleurs, je ne sais pas pour vous, mais j'ai passé un très bon réveillon de fin d'année. J'ai bien mangé et j'ai bien bu, j'avais la peau du ventre bien tendu, mais comme j'aime pas Jésus je ne l'ai pas remercié. En même temps, je ne sais même pas s'il existe vraiment... mais je me perds, je devais écrire un message pour les gens qui oseront cliquer sur Citer/Editer et au final je me trouve à pondre un pavé ou je raconte des idioties afin de me venger ed'avance de ceux qui oseront le lire. Merci d'avoir lu. Au revoir. |
|
| |
Seigneur Lv.18
Age : 28 Inscrit le : 26/12/2010 Messages : 2220
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mer 4 Jan 2012 - 14:22 | |
| - Molok a écrit:
- Je l'ai un peu modifié, maintenant ils ont des comportements plus rigolos
- Code:
-
#============================================================================= # Author : S4suk3, Scriptopathe, Molok # Permet de créer un groupe suivant le héro #============================================================================== # ** Game_Map #------------------------------------------------------------------------------ # This class handles maps. It includes scrolling and passage determination # functions. The instance of this class is referenced by $game_map. #============================================================================== class Game_Map #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :troop #-------------------------------------------------------------------------- # * Alias #-------------------------------------------------------------------------- alias old_setup setup alias old_update update #-------------------------------------------------------------------------- # * Object Setup #-------------------------------------------------------------------------- def setup(map_id) @troop = Array.new old_setup(map_id) end #-------------------------------------------------------------------------- # * Return an event #-------------------------------------------------------------------------- def event(id) return (id == 0) ? $game_player : $game_map.events[id] end #-------------------------------------------------------------------------- # * Returns true if the given member is in the troop #-------------------------------------------------------------------------- def troop_contains?(id) return ((@troop.find{|elt| elt.id == id}) != nil) end #-------------------------------------------------------------------------- # * Add a member into a troop #-------------------------------------------------------------------------- def troop_add(members, order=0) member = Troop::Member.new(members, order) return false if self.troop_contains? members @troop << member self.event(members).move_speed = ($game_player.move_speed)-1 return true end #-------------------------------------------------------------------------- # * Removes a member from a troop #-------------------------------------------------------------------------- def troop_remove(member) if self.troop_contains? member @troop.delete_if{|elt| elt.id == member} end end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update @troop.sort{|event1, event2|event1 <=> event2} Troop::move(@troop) if @troop != nil old_update end #-------------------------------------------------------------------------- # * Change the speed a troop #-------------------------------------------------------------------------- def troop_speed=(value) @troop.each do |elt| self.event(elt.id).move_speed = value end end #-------------------------------------------------------------------------- # * Change the speed a troop by the player speed #-------------------------------------------------------------------------- def adjust_speed self.troop_speed = $game_player.move_speed end end # End of Game_Map
#============================================================================== # ** Game_Interpreter #------------------------------------------------------------------------------ # An interpreter for executing event commands. This class is used within the # Game_Map, Game_Troop, and Game_Event classes. #==============================================================================
class Game_Interpreter #-------------------------------------------------------------------------- # * Groups a troop #-------------------------------------------------------------------------- def group(*members) order = 1 members.each do|elt| $game_map.troop_add(elt, order) order += 1 end end #-------------------------------------------------------------------------- # * Adds members to troup #-------------------------------------------------------------------------- def add_to_troop(*members) order = $game_map.troop.length members.each do|elt| $game_map.troop_add(elt, order) order += 1 end end #-------------------------------------------------------------------------- # * Clears the troop #-------------------------------------------------------------------------- def clear_troop $game_map.troop = Array.new end #-------------------------------------------------------------------------- # * Remove members from a troop #-------------------------------------------------------------------------- def remove_to_troop(*members) members.each do|elt| $game_map.troop_remove(elt) end end #-------------------------------------------------------------------------- # * Modifiy troop_speed #-------------------------------------------------------------------------- def troop_speed=(speed) $game_map.troop_speed = speed end #-------------------------------------------------------------------------- # * Adjust speed #-------------------------------------------------------------------------- def adjust_speed $game_map.adjust_speed end end # End of Game_Interpreter
#============================================================================== # ** Game_Event #------------------------------------------------------------------------------ # This class deals with events. It handles functions including event page # switching via condition determinants, and running parallel process events. # It's used within the Game_Map class. #============================================================================== class Game_Event #-------------------------------------------------------------------------- # * Alias #-------------------------------------------------------------------------- alias old_update update #-------------------------------------------------------------------------- # * Compare proximity with heroes #-------------------------------------------------------------------------- def <=>(other_event) distance = lambda{|event| Math.hypot((event.x - $game_player.x), (event.y-$game_player.y))} return distance.call(self) > distance.call(other_event) ? 1 : distance.call(self) == distance.call(other_event) ? 0 : -1 end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update collide if $game_map.troop_contains? @id old_update end #-------------------------------------------------------------------------- # * Collide with a troop's member #-------------------------------------------------------------------------- def collide if(Input.trigger?(Input::LEFT) && @x+1==$game_map.event(0).x && @y==$game_map.event(0).y && $game_player.direction==4) temp_through = @through @through=true $game_player.move_left self.move_right @through=temp_through end if(Input.trigger?(Input::RIGHT) && @x-1==$game_map.event(0).x && @y==$game_map.event(0).y && $game_player.direction==6) temp_through = @through @through=true $game_player.move_right self.move_left @through=temp_through end if(Input.trigger?(Input::UP) && @x==$game_map.event(0).x && @y+1==$game_map.event(0).y && $game_player.direction==8) temp_through = @through @through=true $game_player.move_up self.move_down @through=temp_through end if(Input.trigger?(Input::DOWN) && @x==$game_map.event(0).x && @y-1==$game_map.event(0).y && $game_player.direction==2) temp_through = @through @through=true $game_player.move_down self.move_up @through=temp_through end end end # End of Game_Event
#============================================================================== # ** Game_Character #------------------------------------------------------------------------------ # This class deals with characters. It's used as a superclass of the # Game_Player and Game_Event classes. #============================================================================== class Game_Character #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :move_speed #-------------------------------------------------------------------------- # * Calculate X Distance From other_event #-------------------------------------------------------------------------- def distance_x_from_event(event) sx = @x - event.x if $game_map.loop_horizontal? if sx.abs > $game_map.width / 2 sx -= $game_map.width end end return sx end #-------------------------------------------------------------------------- # * Calculate Y Distance From other_event #-------------------------------------------------------------------------- def distance_y_from_event(event) sy = @y - event.y if $game_map.loop_vertical? if sy.abs > $game_map.height / 2 sy -= $game_map.height end end return sy end #-------------------------------------------------------------------------- # * Move toward Event #-------------------------------------------------------------------------- def move_toward_event(other_event) event = $game_map.event(other_event) sx = distance_x_from_event(event) sy = distance_y_from_event(event) if sx != 0 or sy != 0 if sx.abs > sy.abs sx > 0 ? move_left : move_right if @move_failed and sy != 0 sy > 0 ? move_up : move_down end else sy > 0 ? move_up : move_down if @move_failed and sx != 0 sx > 0 ? move_left : move_right end end move_toward_player if @move_failed && $game_player.moving? #move_random if @move_failed && $game_player.moving? end end end
#-------------------------------------------------------------------------- # * Troop DATA #-------------------------------------------------------------------------- module Troop #-------------------------------------------------------------------------- # * Member of a group Definition #-------------------------------------------------------------------------- class Member attr_accessor :id, :pos def initialize(id, pos) @id = id @pos = pos end def <=>(other_member) return $game_map.event(@id) <=> $game_map.event(other_member.id) end end class << self #-------------------------------------------------------------------------- # * Movement update #-------------------------------------------------------------------------- def move(troop) order = 0 before = 0 troop.each do |elt| if $game_map.event(elt.id) != nil && elt != nil && !$game_map.event(elt.id).moving? if order == 0 $game_map.event(elt.id).move_toward_player else $game_map.event(elt.id).move_toward_event(before) end before = elt.id end $game_map.event(elt.id).turn_toward_player unless $game_map.event(elt.id).moving? order += 1 end end end # End of Singleton end # End of Troop
Je n'ai pas encore écris le Pathfinding (flemme), donc le script a ses limites. Tu veux dire quoi par là ? Qu'est ce qu'il font de Rigolo ? |
|
| |
Citadin Lv.7
Inscrit le : 15/03/2011 Messages : 167
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur Mer 4 Jan 2012 - 14:28 | |
| ils font très chenilles mais en s'ordonnant de manière plus intelligente |
|
| |
| Sujet: Re: [VX] Grouper des PNJ suivant le joueur | |
| |
|
| |
| [VX] Grouper des PNJ suivant le joueur | |
|