Advertisement
Caldryk

ent_medical_cabinet.lua

Mar 21st, 2025 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. ENT.Type = "anim"
  4. ENT.Base = "base_gmodentity"
  5. ENT.PrintName = "Armoire Médicale"
  6. ENT.Author = "Caldryk"
  7. ENT.Spawnable = true
  8. ENT.AdminOnly = false
  9. ENT.Category = "Custom Entities"
  10.  
  11. -- Liste des entités disponibles dans l'armoire
  12. ENT.AllowedItems = {
  13. ["kira_scanner_full"] = "Scanner avancé",
  14. ["kira_bandage"] = "Bandage",
  15. ["kira_bloodbag"] = "Poche de sang O-",
  16. ["kira_burn_ointment"] = "Baume pour brûlure",
  17. ["kira_splint"] = "Attelle",
  18. ["kira_surgery_kit"] = "Kit de suture",
  19. ["kira_syringe"] = "Morphine"
  20. }
  21.  
  22. ENT.CooldownTime = 5
  23.  
  24. function ENT:Initialize()
  25. self:SetModel("models/props_c17/FurnitureCupboard001a.mdl")
  26. self:PhysicsInit(SOLID_VPHYSICS)
  27. self:SetMoveType(MOVETYPE_VPHYSICS)
  28. self:SetSolid(SOLID_VPHYSICS)
  29.  
  30. local phys = self:GetPhysicsObject()
  31. if IsValid(phys) then phys:Wake() end
  32.  
  33. self.LastUse = {}
  34. end
  35.  
  36. function ENT:Use(_, ply)
  37. if not IsValid(ply) or not ply:IsPlayer() then return end
  38. if ply:Team() ~= TEAM_MED then
  39. ply:ChatPrint("Seuls les médecins peuvent utiliser cette armoire.")
  40. return
  41. end
  42.  
  43. net.Start("OpenMedicalCabinetMenu")
  44. net.WriteEntity(self)
  45. net.Send(ply)
  46. end
  47.  
  48. -- Réseau
  49. util.AddNetworkString("OpenMedicalCabinetMenu")
  50. util.AddNetworkString("RequestMedicalItem")
  51.  
  52. net.Receive("RequestMedicalItem", function(_, ply)
  53. local itemID = net.ReadString()
  54. local cabinet = net.ReadEntity()
  55.  
  56. local itemToEntity = {
  57. ["kira_bandage"] = "rapd_inventory_item_bandage",
  58. ["kira_syringe"] = "rapd_inventory_item_syringe",
  59. ["kira_bloodbag"] = "rapd_inventory_item_bloodbag",
  60. ["kira_burn_ointment"] = "rapd_inventory_item_burn_ointment",
  61. ["kira_surgery_kit"] = "rapd_inventory_item_surgery_kit",
  62. ["kira_scanner_full"] = "rapd_inventory_item_scanner_full",
  63. ["kira_splint"] = "rapd_inventory_item_splint",
  64. }
  65.  
  66. if not IsValid(ply) or not IsValid(cabinet) then return end
  67. if ply:Team() ~= TEAM_MED then return end
  68. if not cabinet.AllowedItems[itemID] then return end
  69.  
  70. if cabinet.LastUse[ply] and CurTime() < cabinet.LastUse[ply] then
  71. ply:ChatPrint("Veuillez patienter avant de prendre un autre objet.")
  72. return
  73. end
  74.  
  75. local sourceItem = RaPD_Items[itemID]
  76. if not sourceItem then
  77. ply:ChatPrint("Erreur : L’objet médical n’existe pas.")
  78. print("[ARMOIRE] Erreur : " .. itemID .. " introuvable dans RaPD_Items.")
  79. return
  80. end
  81.  
  82. local clone = table.Copy(sourceItem)
  83. clone.owner = ply
  84.  
  85. -- Patch temporaire si les dimensions ne sont pas définies
  86. if not clone.width then clone.width = 1 end
  87. if not clone.height then clone.height = 1 end
  88.  
  89. print("[ARMOIRE DEBUG] Tentative d’ajout de l’item : " .. itemID)
  90. PrintTable(clone)
  91.  
  92. if ply:RaPD_AddToInventory(clone) then
  93. ply:EmitSound("items/ammo_pickup.wav")
  94. ply:ChatPrint("✅ '" .. (clone.name or "Objet") .. "' a été ajouté à votre inventaire médical.")
  95. cabinet.LastUse[ply] = CurTime() + cabinet.CooldownTime
  96. else
  97. ply:ChatPrint("❌ Échec : inventaire plein ou objet mal formé.")
  98. print("[ARMOIRE DEBUG] Échec d’ajout de l’objet : " .. itemID)
  99. end
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement