Advertisement
XeroXipher2022

Loading Enemy Entity

Dec 6th, 2024
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #THIS IS MY MULTIPLE SCRIPTS... I THINK THEY WORK BUT I DON'T KNOW HOW TO CONNECT THEM TO MY BUTTON
  2.  
  3. #Entity.gd
  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.  
  29. #PLAYER.gd (NOT IMPORTANT, JUST SHOWING I USE THE SAME STATS FOR PLAYERS AND NPCs
  30.  
  31. extends Entity
  32.  
  33.  
  34. func _ready() -> void:
  35.        
  36.     Username = "Anon1990"
  37.     Country = "Canada"
  38.     IPAddress = "192.168.XXX.XXX"
  39.  
  40.     Money = 0
  41.     Level = 1
  42.     XP = 0
  43.     Nexp = 100
  44.    
  45.     CloudSpace = 200
  46.     Attack = 1
  47.     Penetration = 1
  48.     Defense = 1
  49.     Survellience = 1
  50.     Health = 100
  51.     Damage = 2
  52.  
  53.  
  54. var Faction = "None"
  55. var JoinDate = "December 3rd, 2024"
  56.  
  57. var is_data_loaded = false
  58.  
  59. #NPCs.gd (THIS I WHERE THE NPC's .JSON FILE IS DEFINED)
  60.  
  61. extends Entity
  62.  
  63. var enemy_data = []
  64.  
  65. func _ready() -> void:
  66.     load_enemy_data()
  67.     spawn_enemies()
  68.  
  69. func load_enemy_data():
  70.     var file = FileAccess.open("res://Game/Data/Enemies.json", FileAccess.READ)
  71.     if file:
  72.         var json_data = file.get_as_text()
  73.         enemy_data = JSON.parse_string(json_data).result
  74.         file.close()
  75.    
  76.     else:
  77.         print("Failed to Load Enemies.json")
  78.        
  79. func spawn_enemies():
  80.     var enemy_scene = preload("res://Game/Scenes/Enemy.tscn")
  81.     for enemy in enemy_data:
  82.         var new_enemy = enemy_scene.initiate()
  83.         new_enemy.initialiaze(enemy) #Initialize(enemy) is defined below
  84.         add_child(new_enemy)
  85.    
  86.  
  87. #EnemyScript.gd (#THIS IS WHERE THE INITIALIZE() CODE COME FROM FOR THE ABOVE (COMMENTED) CODE)
  88.  
  89. extends Entity
  90.  
  91. func initialize(enemy_data):
  92.     Username = enemy_data["Username"]
  93.     Country =  enemy_data["Country"]
  94.     IPAddress = enemy_data["IPAddress"]
  95.  
  96.     Money = enemy_data["Money"]
  97.     Level = enemy_data["Level"]
  98.     XP = enemy_data["XP"]
  99.     Nexp = enemy_data["Nexp"]
  100.    
  101.     CloudSpace = enemy_data["CloudSpace"]
  102.     Attack = enemy_data["Attack"]
  103.     Penetration = enemy_data["Penetration"]
  104.     Defense = enemy_data["Defense"]
  105.     Survellience = enemy_data["Survellience"]
  106.     Health = enemy_data["Health"]
  107.     Damage = enemy_data["Damage"]
  108.    
  109.     print("Enemy Username : " + enemy_data["Username"])
  110.  
  111. #FINALLY, AT THE BOTTOM OF THIS SCRIPT WHERE IT SAYS PRINT(SCANNING NPCs...) IS WHERE I WANT TO ATTACH ALL OF THIS CODE FOR FINDING AN ENEMY.
  112.  
  113. extends MenuBar
  114.  
  115. @export var Menu: PopupMenu
  116. @export var Hack: PopupMenu
  117. #ABOVE NOT NECCESSARY
  118.  
  119. @onready var menu_bar: MenuBar = %MenuBar
  120. @onready var menu: PopupMenu = %Menu
  121. @onready var hack: PopupMenu = %Hack
  122.  
  123.  
  124.  
  125.  
  126.  
  127. func _ready() -> void:
  128.     pass
  129.    
  130.  
  131.  
  132. func _on_menu_index_pressed(index: int) -> void:
  133.    
  134.     match index:
  135.        
  136.         0:
  137.             print(Menu.get_item_text(index))
  138.             get_tree().change_scene_to_packed(load("res://Game/Scenes/GameProfileScreen.tscn"))
  139.         1:
  140.             print(Menu.get_item_text(index))
  141.         2:
  142.             print(Menu.get_item_text(index))
  143.         3:
  144.             print(Menu.get_item_text(index))
  145.         4:
  146.             pass
  147.         5:
  148.             print(Menu.get_item_text(index))
  149.             SaveFile.saveGame()
  150.             get_tree().change_scene_to_packed(load("res://Game/Scenes/TiitleScreen.tscn"))
  151.         6:
  152.             print(Menu.get_item_text(index))
  153.             Player.Money += 125
  154.  
  155.  
  156. func _on_hack_index_pressed(index: int) -> void:
  157.     match index:
  158.         0:
  159.             print("Scanning IPs...")
  160.            
  161.         1:
  162.             pass
  163.         2:
  164.             pass
  165.         3:
  166.             pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement