Advertisement
XeroXipher2022

Help in GoDot from Alice

Dec 6th, 2024
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Hi Alice, this is my Code, I hope you can help: ##
  2.  
  3. ## Entity.gd ## ALL NPCs AND PLAYERS SHARE THIS TEMPLATE ##
  4.  
  5. extends Node
  6.  
  7. class_name Entity
  8.  
  9.  
  10.  
  11. var Username: String
  12. var Country: String
  13. var IPAddress: String
  14.  
  15. var Money: int
  16. var Level: int
  17. var XP: int
  18. var Nexp: int
  19.  
  20. var CloudSpace: int
  21. var Attack: int
  22. var Penetration: int
  23. var Defense: int
  24. var Survellience: int
  25. var Health: int
  26. var Damage: int
  27.  
  28. ## NPCs.gd ## ALL NPC DATA IS BEING SETUP ##
  29.  
  30. extends Entity
  31.  
  32. var enemy_data = []
  33.  
  34. func _ready() -> void:
  35.     load_enemy_data()
  36.     spawn_enemies()
  37.  
  38. func load_enemy_data():
  39.     var file = FileAccess.open("res://Game/Data/Enemies.json", FileAccess.READ)
  40.     if file:
  41.         var json_data = file.get_as_text()
  42.         enemy_data = JSON.parse_string(json_data)
  43.         file.close()
  44.    
  45.     else:
  46.         print("Failed to Load Enemies.json")
  47.        
  48. func spawn_enemies(enemy_data_array : Array):
  49.     var enemy_scene = preload("res://Game/Scenes/EnemyScript.gd")
  50.     for enemy_data in enemy_data_array:
  51.         var enemy_instance = enemy_scene.instance()
  52.         add_child(enemy_instance)
  53.         enemy_instance.initialize(enemy_data)
  54.    
  55.  
  56. ## Enemies.json ## THIS IS A JSON FILE WITH 2 ENEMIES AND THEIR STATS ##
  57.  
  58. [
  59.         {
  60.             "Username" : "Anon22310001",
  61.             "Country" : "United States",
  62.             "IPAddress" : "192.168.XXX.XXX",
  63.  
  64.             "Money" : 495,
  65.             "Level" : 1,
  66.             "XP" : 0,
  67.             "Nexp" : 100,
  68.            
  69.             "CloudSpace" : 200,
  70.             "Attack" : 9,
  71.             "Penetration" : 4,
  72.             "Defense" : 9,
  73.             "Survellience" : 1,
  74.             "Health" : 225,
  75.             "Damage" : 8
  76.  
  77.         },
  78.         {
  79.             "Username" : "Anon22002193",
  80.             "Country" : "United Kingdom",
  81.             "IPAddress" : "192.168.XXX.XXX",
  82.  
  83.             "Money" : 750,
  84.             "Level" : 2,
  85.             "XP" : 0,
  86.             "Nexp" : 100,
  87.            
  88.             "CloudSpace" : 200,
  89.             "Attack" : 11,
  90.             "Penetration" : 5,
  91.             "Defense" : 11,
  92.             "Survellience" : 2,
  93.             "Health" : 270,
  94.             "Damage" : 11
  95.  
  96.         }
  97.     ]
  98.  
  99. ## EnemyScript.gd ## THIS CODE IS SUPPOSED TO TAKE ALL OF THE JSON INFORMATION AND TURN IT BACK INTO VARIABLES
  100.  
  101. extends Entity
  102.  
  103. func initialize(enemy_data):
  104.     Username = enemy_data["Username"]
  105.     Country =  enemy_data["Country"]
  106.     IPAddress = enemy_data["IPAddress"]
  107.  
  108.     Money = enemy_data["Money"]
  109.     Level = enemy_data["Level"]
  110.     XP = enemy_data["XP"]
  111.     Nexp = enemy_data["Nexp"]
  112.    
  113.     CloudSpace = enemy_data["CloudSpace"]
  114.     Attack = enemy_data["Attack"]
  115.     Penetration = enemy_data["Penetration"]
  116.     Defense = enemy_data["Defense"]
  117.     Survellience = enemy_data["Survellience"]
  118.     Health = enemy_data["Health"]
  119.     Damage = enemy_data["Damage"]
  120.    
  121.     print("Enemy Username : " + enemy_data["Username"])
  122.  
  123. ## AND THIS IS WHERE I AM TRYING TO CALL THE SCRIPT BUT I DON'T THINK IT RELEVENT: ##
  124.  
  125. extends MenuBar
  126.  
  127. const NPCs = preload("res://Scripts/Entities/NPCs.gd")
  128.  
  129. @export var Menu: PopupMenu
  130. @export var Hack: PopupMenu
  131. #ABOVE NOT NECCESSARY
  132.  
  133. @onready var menu_bar: MenuBar = %MenuBar
  134. @onready var menu: PopupMenu = %Menu
  135. @onready var hack: PopupMenu = %Hack
  136.  
  137.  
  138.  
  139.  
  140.  
  141. func _ready() -> void:
  142.     pass
  143.    
  144.  
  145.  
  146. func _on_menu_index_pressed(index: int) -> void:
  147.    
  148.     match index:
  149.        
  150.         0:
  151.             print(Menu.get_item_text(index))
  152.             get_tree().change_scene_to_packed(load("res://Game/Scenes/GameProfileScreen.tscn"))
  153.         1:
  154.             print(Menu.get_item_text(index))
  155.         2:
  156.             print(Menu.get_item_text(index))
  157.         3:
  158.             print(Menu.get_item_text(index))
  159.         4:
  160.             pass
  161.         5:
  162.             print(Menu.get_item_text(index))
  163.             SaveFile.saveGame()
  164.             get_tree().change_scene_to_packed(load("res://Game/Scenes/TiitleScreen.tscn"))
  165.         6:
  166.             print(Menu.get_item_text(index))
  167.             Player.Money += 125
  168.  
  169.  
  170. func _on_hack_index_pressed(index: int) -> void:
  171.     match index:
  172.         0:
  173.             print("Scanning IPs...")
  174.             var npc_manager = NPCs.new()
  175.             npc_manager.load_enemy_data()
  176.             npc_manager.spawn_enemies()
  177.            
  178.         1:
  179.             pass
  180.         2:
  181.             pass
  182.         3:
  183.             pass
  184.        
  185.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement