Night.png);">
Apprendre


Vous êtes
nouveau sur
Oniromancie?

Visite guidée
du site


Découvrir
RPG Maker


Apprendre
RPG Maker

Tutoriels
Guides
Making-of

Dans le
Forum

Section Entraide

Jeux: Final Destiny / Jeux: puie z / Jeux: Citymaime - Chapitre 1 / Jeux: Mer, îles et fous / News: Du neuf dans le making / Chat

Bienvenue
visiteur !




publicité RPG Maker!

Statistiques

Liste des
membres


Contact

Mentions légales

238 connectés actuellement

30739585 visiteurs
depuis l'ouverture

3171 visiteurs
aujourd'hui



Barre de séparation

Partenaires

Indiexpo

Akademiya RPG Maker

Blog Alioune Fall

Fairy Tail Constellations

RPG Maker - La Communauté

Leo-Games

Le Temple de Valor

Eclipso

New RPG Maker

Tous nos partenaires

Devenir
partenaire



Item Crafting

Pour créer un système de forge/alchimie, soit fabriquer ses objets.

Script pour RPG Maker XP
Ecrit par kellesdee
Publié par Motoki (lui envoyer un message privé)
Signaler un script cassé

❤ 0

Auteur : kellessdee
Logiciel : RPG Maker XP
Nombre de scripts : 1
Source : https://gdu.one/forums/topic/6729-item-crafting-scriptrmxp/

Installation
A placer au-dessus de Main.

Portion de code : Tout sélectionner

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
=begin
~ Item Crafting ~
By kellessdee
RPG Maker XP
-----------------------------------------------------------------------------
*** RECIPE CONFIGURATION ****************************************************
-----------------------------------------------------------------------------
INSTRUCTIONS:
This module contains the constant variables used for each recipe
format: 
RECIPE[index] = [recipe_id, [product_type, product_id],
                 [material_1_type, material_1_id, material_1_qty], ...]
recipe_id       : this is the ID number in "items" tab of database
product_type    : this is the "type" of item that will be created
                : 0 = item; 1 = weapon; 2 = armor
product_id      : this is the ID number in corresponding "type" tab of database
                : for finished product
material_1_type : first required material "type"
                : 0 = item; 1 = weapon; 2 = armor
material_1_id   : this is the ID number in corresponding "type" tab of database
                : for first material
material_1_qty  : the quantity required of first material to create product
*NOTE:*
This Script supports any number of required materials for each recipe, simply 
write in extra materials, following the same format 
EX. RECIPE[0] = [1, [0, 25], [0, 15, 5], [0, 12, 2], [0, 5, 1]]
that recipe would be found as the first item in the database, would create
item # 25 in the item database, and requires 5 item#15, 2 item#12 and 1 item#5
=end
module Crafting
  # Menu style, true - draw map and resize windows to fit contents
  # false - draw full windows
  RESIZE_MENU = true
  # Create array to hold recipe data
  RECIPE = []
  # Create recipes below
  # High Potion
  RECIPE[0] = [1, [0, 2], [0, 1, 2], [0, 17, 1]]               
  # Full Potion
  RECIPE[1] = [34, [0, 3], [0, 2, 1], [0, 28, 1]]               
  # High Perfume
  RECIPE[2] = [35, [0, 5], [0, 4, 2], [0, 18, 1]]               
  # Iron Sword
  RECIPE[3] = [36, [1, 2], [1, 1, 1], [0, 13, 5], [0, 23, 5]] 
  # Ring of Water 
  RECIPE[4] = [37, [2, 32], [2, 26, 1], [2, 30, 1], [2, 29, 1], [0, 14, 1]]
  #Steel Axe
  RECIPE[5] = [33, [1,11], [0, 30, 1], [1, 29, 1]]
end
#============================================================================
# ** Window_Prompt
#----------------------------------------------------------------------------
#   This window asks the user if they would like to create the item
#============================================================================
class Window_Prompt < Window_Command
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     item    : item that will be created
  #--------------------------------------------------------------------------
  def initialize
    super(200, ['Create', 'Cancel'])
    self.x += 16
    self.y += 80
    self.z += 100
  end
end
#============================================================================
# ** Window_Materials
#----------------------------------------------------------------------------
#   This window displays required materials to synthesize recipe
#============================================================================
class Window_Materials < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(recipe)
    super(320, 64, 320, 416)
    refresh(recipe)
    self.index = -1 
    self.active = false
  end
  #--------------------------------------------------------------------------
  # * Current Item
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Refresh Contents
  #--------------------------------------------------------------------------
  def refresh(recipe)
    @recipe = recipe
    if self.contents != nil
      self.contents.clear
      self.contents = nil
    end
    # If no recipes are possessed do not draw item
    @data = []
    if @recipe == nil
      self.height = 96 if Crafting::RESIZE_MENU
      self.contents = Bitmap.new(self.width - 32, self.height - 32)
      # Memorize font size
      font_size = self.contents.font.size
      # Draw Header
      self.contents.font.color = system_color
      self.contents.draw_text(4, 0, 212, 32, 'Ingredients')
      self.contents.font.size = 14
      self.contents.draw_text(204, 0, 24, 32, 'need', 2)
      self.contents.draw_text(252, 0, 24, 32, 'held', 2)
      # Restore font size
      self.contents.font.size = font_size
      self.contents.draw_text(228, 0, 16, 32, '/', 1)
      return
    end
    @qty_req = []
    # Add items required
    for i in 2...@recipe.size
      case @recipe[i][0]
      when 0 # Item
        @data.push($data_items[@recipe[i][1]])
      when 1 # Weapon
        @data.push($data_weapons[@recipe[i][1]])
      when 2 # Armor
        @data.push($data_armors[@recipe[i][1]])
      end
      @qty_req.push(@recipe[i][2])
    end
    @item_max = @data.size
    # Resize ingredients list
    if Crafting::RESIZE_MENU
      self.height = @item_max * 32 + 64
      self.height = 416 if self.height > 416
    end
    # Draw items required
    self.contents = Bitmap.new(self.width - 32, @item_max * 32 + 32)
    for i in 0...@item_max
      draw_item(i)
    end
    # Memorize font size
    font_size = self.contents.font.size
    # Draw Header
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 212, 32, 'Ingredients')
    self.contents.font.size = 14
    self.contents.draw_text(204, 0, 24, 32, 'need', 2)
    self.contents.draw_text(252, 0, 24, 32, 'held', 2)
    # Restore font size
    self.contents.font.size = font_size
    self.contents.draw_text(228, 0, 16, 32, '/', 1)
  end
  #-------------------------------------------------------------------------
  # * Draw Ingredients
  #-------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    x = 4
    y = index * 32 + 32
    # get number of items held
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    self.contents.font.color = number >= @qty_req[index] ? 
                               normal_color : disabled_color
    rect = Rect.new(x, y, self.width - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name)
    self.contents.draw_text(x + 200, y, 24, 32, @qty_req[index].to_s, 2)
    self.contents.draw_text(x + 224, y, 16, 32, '/', 1)
    self.contents.draw_text(x + 248, y, 24, 32, number.to_s, 2)
  end
  #--------------------------------------------------------------------------
  # * Update Cursor Rectangle
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # If cursor position is less than 0
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # Get current row
    row = @index
    # If current row is before top row
    if row < self.top_row
      # Scroll so that current row becomes top row
      self.top_row = row
    end
    # If current row is more to back than back row
    if row > self.top_row + (self.page_row_max - 1)
      # Scroll so that current row becomes back row
      self.top_row = row - (self.page_row_max - 1)
    end
    # Calculate cursor width
    cursor_width = self.width - 32
    # Calculate cursor coordinates
    x = 0
    y = @index * 32 - self.oy + 32
    # Update cursor rectangle
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end
 
 
#============================================================================
# ** Window_Recipe
#----------------------------------------------------------------------------
#   This window displays recipes currently in possesion
#============================================================================
class Window_Recipe < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 64, 320, 416)
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Current Recipe
  #--------------------------------------------------------------------------
  def recipe
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Refresh Contents
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.clear
      self.contents = nil
    end
    @data = []
    # Add Recipes in possession
    for i in 0...Crafting::RECIPE.size
      recipe_id = Crafting::RECIPE[i][0]
      if $game_party.item_number(recipe_id) > 0
        @data.push(Crafting::RECIPE[i])
      end
    end
    @item_max = @data.size
    # Resize recipe window
    if Crafting::RESIZE_MENU
      self.height = @data[0] == nil ? 96 : @item_max * 32 + 64
      self.height = 416 if self.height > 416
    end
    # If Any recipes are possessed, draw them
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, @item_max * 32 + 32)
      for i in 0...@item_max
        draw_recipes(i)
      end
    else
      self.contents = Bitmap.new(width - 32, height - 32)
    end
    # Draw Header
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 268, 32, 'Recipes Held', 1)
  end
  #-------------------------------------------------------------------------
  # * Draw Recipes
  #-------------------------------------------------------------------------
  def draw_recipes(index)
    recipe = @data[index]
    x = 4
    y = index * 32 + 32
    # check if recipe is can be created
    self.contents.font.color = recipe_can_create?(recipe) ? 
                               normal_color : disabled_color
    rect = Rect.new(x, y, self.width - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon($data_items[recipe[0]].icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, $data_items[recipe[0]].name)
  end
  #--------------------------------------------------------------------------
  # * Can Recipe be Created
  #     recipe    : array with recipe data
  #--------------------------------------------------------------------------
  def recipe_can_create?(recipe)
    return false unless recipe
    for i in 2...recipe.size
      case recipe[i][0]
      when 0 # Item
        unless $game_party.item_number(recipe[i][1]) >= recipe[i][2]
          return false
        end
      when 1 # Weapon
        unless $game_party.weapon_number(recipe[i][1]) >= recipe[i][2]
          return false
        end
      when 2 # Armor
        unless $game_party.armor_number(recipe[i][1]) >= recipe[i][2]
          return false
        end
      end
    end
    return true
  end
  #--------------------------------------------------------------------------
  # * Update Cursor Rectangle
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # If cursor position is less than 0
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # Get current row
    row = @index
    # If current row is before top row
    if row < self.top_row
      # Scroll so that current row becomes top row
      self.top_row = row
    end
    # If current row is more to back than back row
    if row > self.top_row + (self.page_row_max - 1)
      # Scroll so that current row becomes back row
      self.top_row = row - (self.page_row_max - 1)
    end
    # Calculate cursor width
    cursor_width = self.width - 32
    # Calculate cursor coordinates
    x = 0
    y = @index * 32 - self.oy + 32
    # Update cursor rectangle
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    if self.recipe == nil
      item = nil
      @help_window.set_text('')
    else
      case self.recipe[1][0]
      when 0 # item
        item = $data_items[self.recipe[1][1]]
      when 1 # weapon
        item = $data_weapons[self.recipe[1][1]]
      when 2 # armor
        item = $data_armors[self.recipe[1][1]]
      end
      bitmap = RPG::Cache.icon(item.icon_name) if item != nil
      @help_window.set_text('Creates       ' + item.name) if item != nil
      @help_window.contents.blt(78, 4, bitmap, Rect.new(0, 0, 24, 24)) if item != nil
    end
  end
end
#============================================================================
# ** Scene_Crafting
#----------------------------------------------------------------------------
#    This scene handles the menu used for crafting new items
#============================================================================
class Scene_Crafting
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Draw map in background
    map = Spriteset_Map.new if Crafting::RESIZE_MENU
    # Create Windows
    @recipe_window = Window_Recipe.new
    @index = 0
    @material_index = 0
    @material_window = Window_Materials.new(@recipe_window.recipe)
    @help_window = Window_Help.new
    # Associate help window
    @material_window.help_window = @help_window
    @recipe_window.help_window = @help_window
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update Graphics
      Graphics.update
      # Update Input
      Input.update
      # Update Frame
      update
      # If scene has changed
      if $scene != self
        break
      end
    end
    # Dispose windows
    map.dispose if Crafting::RESIZE_MENU
    @recipe_window.dispose
    @material_window.dispose
    @help_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Update Frame
  #--------------------------------------------------------------------------
  def update
    # Update current window
    @help_window.update
    if @recipe_window.active
      @recipe_window.update
      @material_window.refresh(@recipe_window.recipe)
      update_recipe
      return
    else
      @material_window.update
      update_material
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Update Recipe Window
  #--------------------------------------------------------------------------
  def update_recipe
    # if B button is pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Return to main menu
      $scene = Scene_Menu.new(4)
      return
    end
    # if C button is pressed
    if Input.trigger?(Input::C)
      # Get recipe
      recipe = @recipe_window.recipe
      # check if recipe can be created
      if @recipe_window.recipe_can_create?(recipe)
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Prompt player
        create_item_prompt(recipe)
        return
      else
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
      end
      return
    end
    # if Right button is pressed
    if Input.trigger?(Input::RIGHT)
      # Play cursor SE
      $game_system.se_play($data_system.cursor_se)
      # Switch to materials window
      @index = @recipe_window.index
      @recipe_window.index = -1
      @recipe_window.active = false
      @material_window.active = true
      @material_window.index = @material_index
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Update Material Window
  #--------------------------------------------------------------------------
  def update_material
    # if B Button is pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Return to main menu
      $scene = Scene_Menu.new
      return
    end
    # if Left button is pressed
    if Input.trigger?(Input::LEFT)
      # Play cursor SE
      $game_system.se_play($data_system.cursor_se)
      # Switch to recipes window
      @material_index = @material_window.index
      @material_window.index = -1
      @material_window.active = false
      @recipe_window.index = @index
      @recipe_window.active = true
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Create Item Prompt
  #--------------------------------------------------------------------------
  def create_item_prompt(recipe)
    # Create item Prompt
    command = Window_Prompt.new
    # Deactivate recipe window
    @recipe_window.active = false
    # Loop until selection is made
    loop do
      # Update Graphics
      Graphics.update
      # Update input
      Input.update
      # Update commands
      command.update
      # if B button is pressed
      if Input.trigger?(Input::B)
        # Play cancel SE
        $game_system.se_play($data_system.cancel_se)
        # Return to recipe window
        break
      end
      # if C button is pressed
      if Input.trigger?(Input::C)
        case command.index
        when 0 # Create
          # Play create SE
          $game_system.se_play($data_system.equip_se)
          # Add item to inventory
          case recipe[1][0]
          when 0 # item
            $game_party.gain_item(recipe[1][1], 1)
          when 1 # weapon
            $game_party.gain_weapon(recipe[1][1], 1)
          when 2 # armor
            $game_party.gain_armor(recipe[1][1], 1)
          end
          # Remove ingredients
          for i in 2...recipe.size
            case recipe[i][0]
            when 0 # item
              # BREWMEISTER's MODIFICATION for consumable/non-consumable items
              if $data_items[recipe[i][1]].consumable   ##BREW
                $game_party.lose_item(recipe[i][1], recipe[i][2])
              end                                       ##BREW
              # END MODIFICATION
            when 1 # weapon
              $game_party.lose_weapon(recipe[i][1], recipe[i][2])
            when 2 # armor
              $game_party.lose_armor(recipe[i][1], recipe[i][2])
            end
          end
          # Refresh recipe window
          @recipe_window.refresh
          break
        when 1 # Cancel
          # Play cancel SE
          $game_system.se_play($data_system.cancel_se)
          # Return to recipe window
          break
        end
      end
    end
    command.dispose
    @recipe_window.active = true
  end
end



Utilisation
Pour le faire fonctionner, il vous faut d'abord un évènement (un coffre, par exemple) qui donne la recette et les matériaux.
Pour créer une recette, il faut l'ajouter dans le script "Crafting System" de cette manière :
Recipe x = [id_recette], [type_objet_resultat, id_objet_resultat], [type_ingredient1, id_ingredient1, quantite_ingedient1], [type_ingredient2, id_ingredient2, quantite_ingedient2]]
Où :
x : numéro de la recette, et définit donc l'ordre d'affichage de celles-ci.
id_recette : le numéro id de l'objet servant à dire que cette recette est connue.
type_objet_resultat, id_objet_resultat : le type d'objet qui en résulte (0 = Objets, 1 = Armes, 2 = Armures), et son numéro id
type_ingredient, id_ingredient, quantite_ingedient : le type d'objet de l'ingrédient (0, 1 ou 2), son numéro id dans la base de données et la quantité nécessaire. Vous pouvez avoir autant d'ingrédients que vous le souhaitez en répétant [type_ingredient1, id_ingredient1, quantite_ingedient1].

Pour faire appel à la forge, il suffit ensuite de faire un appel de script avec : $scene=Scene_Crafting.new






ray-yami2 - posté le 10/06/2024 à 01:49:59 (33 messages postés)

❤ 0

Si j'avais un exemple de projet, je pourrais peu être comprendre, mais la, je ne comprend pas, je veux bien de l'aide..

Suite à de nombreux abus, le post en invités a été désactivé. Veuillez vous inscrire si vous souhaitez participer à la conversation.

Haut de page

Merci de ne pas reproduire le contenu de ce site sans autorisation.
Contacter l'équipe - Mentions légales

Plan du site

Communauté: Accueil | Forum | Chat | Commentaires | News | Flash-news | Screen de la semaine | Sorties | Tests | Gaming-Live | Interviews | Galerie | OST | Blogs | Recherche
Apprendre: Visite guidée | RPG Maker 95 | RPG Maker 2003 | RPG Maker XP | RPG Maker VX | RPG Maker MV | Tutoriels | Guides | Making-of
Télécharger: Programmes | Scripts/Plugins | Ressources graphiques / sonores | Packs de ressources | Midis | Eléments séparés | Sprites
Jeux: Au hasard | Notre sélection | Sélection des membres | Tous les jeux | Jeux complets | Le cimetière | RPG Maker 95 | RPG Maker 2000 | RPG Maker 2003 | RPG Maker XP | RPG Maker VX | RPG Maker VX Ace | RPG Maker MV | Autres | Proposer
Ressources RPG Maker 2000/2003: Chipsets | Charsets | Panoramas | Backdrops | Facesets | Battle anims | Battle charsets | Monstres | Systems | Templates
Ressources RPG Maker XP: Tilesets | Autotiles | Characters | Battlers | Window skins | Icônes | Transitions | Fogs | Templates
Ressources RPG Maker VX: Tilesets | Charsets | Facesets | Systèmes
Ressources RPG Maker MV: Tilesets | Characters | Faces | Systèmes | Title | Battlebacks | Animations | SV/Ennemis
Archives: Palmarès | L'Annuaire | Livre d'or | Le Wiki | Divers