mob/AI/proc/AI_Equipment()
for(var/obj/O in src.contents)
if(O.Equipable && O.Equipped == 0)
var/Slot
if(O.Core == "Item" || O.Core == "Weapon")
if(O.Slot == 2 && src.Weapons["Left Back"] == null && src.Weapons["Right Back"] == null)
Slot = "Left Back"
else if(O.Slot == 1)
var/list/List = list("Left Waist", "Right Waist", "Left Back", "Right Back")
if(src.Weapons["Left Back"] != null)
List.Remove("Left Back")
if(src.Weapons["Right Back"] != null)
List.Remove("Right Back")
Slot = pick(List)
else
Slot = O.Type
O.Holder = src
O.Equip(Slot)
for(var/x=1; x<=5; x++)
var/obj/Armour/A = pick(typesof(/obj/Armour) - /obj/Armour)
if(prob(50))
if(src.Armour[A:Type] == null)
A = new(src)
A.Equip(A:Type)
obj/proc/Equip(var/Slot)
if(src.Equipable && Slot != null)
var/mob/M = src.Holder
switch(src.Core)
if("Item")
if(src.Equipped == 1)
src.Equipped = 0
src.icon_state = ""
M.overlays.Remove(src)
M.Weapons[Slot] = null
else
if(M.Weapons[Slot] != null)
var/obj/O = M.Weapons[Slot]
O.Equip(Slot)
src.Equip(Slot)
else
src.Equipped = 1
src.icon_state = "[src.Type] - [Slot]"
M.overlays.Add(src)
M.Weapons[Slot] = src
if("Armour")
if(src.Type == "Head" && M.Clothing["Head"] != null)
M.client.sound_system.PlaySound('Notification Alert.ogg', null, 0)
M << output("<font color=red>Game System: </font>You cannot have Equipment in both Clothing and \
Armour for your Head Slot. It must be either one or the other.", "System Output")
else
if(src.Equipped == 1)
src.Equipped = 0
src.icon_state = ""
M.overlays.Remove(src)
M.Armour[Slot] = null
else
if(M.Armour[Slot] != null)
var/obj/O = M.Armour[Slot]
O.Equip(Slot)
src.Equip(Slot)
else
src.Equipped = 1
src.icon_state = Slot
M.overlays.Add(src)
M.Armour[Slot] = src
if("Weapon")
if(src.Equipped > 0)
src.Equipped = 0
src.icon_state = ""
M.overlays.Remove(src)
if(src.Slot == 1)
M.Weapons[Slot] = null
else if(src.Slot == 2)
if(Slot == "Left Back")
M.Weapons["Right Back"] = null
else if(Slot == "Right Back")
M.Weapons["Left Back"] = null
else
if(M.Weapons[Slot] != null)
var/obj/O = M.Weapons[Slot]
O.Equip(Slot)
src.Equip(Slot)
else
src.Equipped = 1
if(src.Slot == 1)
src.icon_state = Slot
M.overlays.Add(src)
M.Weapons[Slot] = src
else if(src.Slot == 2)
if(findtext(Slot, "Back"))
src.icon_state = "Full | Back"
M.Weapons["Left Back"] = src
M.Weapons["Right Back"] = src
M.overlays.Add(src)
else
M.client.sound_system.PlaySound('Notification Alert.ogg', null, 0)
M << output("<font color=red>Game System: </font>Two-Handed Weapons can only \
be Equipped on your back", "System Output")
if("Clothing" || "Treasure")
if(src.Type == "Head" && M.Armour["Head"] != null)
M.client.sound_system.PlaySound('Notification Alert.ogg', null, 0)
M << output("<font color=red>Game System: </font>You cannot have Equipment in both Clothing and \
Armour for your Head Slot. It must be either one or the other.", "System Output")
else
if(src.Equipped == 1)
src.Equipped = 0
if(src.Core == "Clothing")
src.icon_state = ""
else
src.icon_state = src.name
M.overlays.Remove(src)
M.Clothing[Slot] = null
else
if(M.Clothing[Slot] != null)
var/obj/O = M.Clothing[Slot]
O.Equip(Slot)
src.Equip(Slot)
else
src.Equipped = 1
if(src.Core == "Clothing")
src.icon_state = Slot
else
src.icon_state = "[src.name] - [Slot]"
M.overlays.Add(src)
M.Armour[Slot] = src
Problem description:
I'm currently trying to create a function which will equip my AIs automatically without me having to go through each of them and add the choicest of armour and weapons for them. The "weapons" work easily because I had already went ahead and add a few of those to each of my AIs, but I seem to be having problems trying to create armour.
I have changed the armour-piece of the code numerous times in an attempt to see what's being done, and outputted the results to the screen. On a few occasions, I noticed that somehow, it was adding a null object of type armour to the contents, and failing to equip the armour (which would be a given, since the armour's Type variable would be null).
Weirder yet, I tried to output what the list of armour objects that would be referenced when using typesof in the for-loop and got a blank screen.
Any ideas what's going on here or what I'm doing wrong?
So, the corrected version:
If this is something you are doing a lot, I'd recommend using references to global object prototypes, so you aren't creating new armor objects each time that proc is called.