ID:166570
 
obj
hud
cweapon
name = "Current Weapon"
icon_state = usr.armr
screen_loc = "1,1"


At "cweapon", I'm wanting the icon_state to be the user's equipped weapon, but I'm not sure how to do this.

ANY help is appreciated.

~PAK~
You can't define the icon_state variable like that. What you should do is change it when you place it on the players screen and/or whenever he switches weapons.
Umm, I hope you know that icon_state will just use the name as the state in that particular icon file
... which is useless as I don't see the icon defined

One way you can do it is:
icon = usr.armr

or icon=usr.armr.icon [forgot if this works]

(Assuming that usr.armr holds the object itself and not the name or such)

- GhostAnime

EDIT: And listen to what super said, you should. prob. make a special proc that updates the screen whenver the weapon changes
obj
hud
cweapon
name = "Current Weapon"
icon_state = usr.armr // **Line 5**
screen_loc = "1,1"

Take a look at line 5. The compiler will not let you do this, and will return an error like 'Expected a constant expression'. This means when you set a variable of any sort at compile time it can't be a reference. What you can do is throw in something with your Equip() verb or whatever you use when you equip stuff to do this:
for(var/obj/hud/cweapon/X in usr.client.screen)
X.icon_state="usr.armr"


Like they said, best to do something that updates your screen, and that's how you'd do it. Hope that helps ~ AJ
In response to AJX
You mean
X.icon_state="[usr.armr]"
:P

obj/OMZ/HUZD
SIS//Some Icon Stat
name=":OOOOOO"
screen_loc=somewhere

mob/Login()
..()
UpdateHUDS()

mob/proc/UpdateHUDS()//WARNING: VERY INEFFICIENT CODE COMMING AHEAD
while(src.client)//while the player is logged in
for(var/tmp/obj/OMZ/HUZD/H in client.screen)
if(istype(H,/obj/OMZ/HUZD/SIS)) H.icon_state=src.armr
sleep(1)


- GhostAnime
In response to GhostAnime
Sorry for bringing such an old post back... but I'm having the same problem, and I didn't want to just make a new one because I just got distracted from this one >.>

mob/proc/hudupdate()
while(src.client)
for(var/tmp/obj/hud2/H in client.screen)
if(istype(H,/obj/hud2/wep1)) H.icon_state = src.meleewep
sleep(1)
obj
hud2
wep1
screen_loc = "5,5"

obj/weapon
melee
verb
Arm()
if(usr.meleewep == null)
suffix = "Armed"
usr.meleewep = src
usr.hudupdate()


That's what I have going right now, but it's not working. I'm not getting any compile errors, nor any errors in-game, besides the fact that it's not working, the weapon doesn't show up. What am I doing wrong?
In response to Pakbaum
mob
Login()
new/obj/hud2/wep1(src.client)

mob/proc/hudupdate()
while(src.client)
for(var/tmp/obj/hud2/H in client.screen)
if(istype(H,/obj/hud2/wep1)) H.icon_state = src.meleewep
sleep(1)

obj
hud2
wep1
icon='wtf.dmi' // everything with icon_state MUST have icon >.<
icon_state=""
layer=99
New(client/c)
screen_loc="5,5"
c.screen+=src

obj/weapon
melee
verb
Arm()
if(usr.meleewep == "")
src.suffix = "Armed"
usr.meleewep = "bla bla bla" // Put icon_state here >.< if you know what is icon_state
usr.hudupdate()

mob/var/meleewep=""

It works for me so I think it will work for you
In response to Kisioj
I tried doing what you did, no such luck though. Still not showing up.
mob
Login()
new/obj/hud2/wep1(src.client,5)
..()

mob/proc/hudupdate()//this should update only once :/
if(src!=null)//If we are still there
for(var/tmp/obj/hud2/H in src.client.screen)
if(istype(H,/obj/hud2/wep1))
if(!src.meleewep)return// jus in case our weapon suddenly wasnt there
H.icon=src.meleewep.icon//change its icon to our weapons icon so we may use this icon to change the hud to your weapons icon_state
H.icon_state = src.meleewep.icon_state//now we should be able to change it >:)
return
else return

obj/hud2
wep1
icon='Unknown.dmi'
icon_state="Unknown"
screen_loc="5,5"
New(client/c,layers)
if(layers)src.layer=layers
c.screen+=src
..()

obj/weapon/melee/verb
Arm()
var/mob/M=usr
if(!M.meleewep)
src.suffix = "Armed"
M.meleewep = src//so we have access to all the items variables, icon, icon states ect...
M.hudupdate()//now we update it
return

mob/var/obj/meleewep


I havnt tested it but that should work I thinkish :/.

- Dark Emrald
In response to Dark Emrald
sys.dm:139:error:if:undefined proc
sys.dm:138:error:src.meleewep:undefined type

mob/proc/hudupdate()
if(src!=null)
for(var/tmp/obj/hud2/H in client.screen)
if(istype(H,/obj/hud2/wep1)) H.icon_state = src.meleewep //sys.dm:138:error
if(!src.meleewep) return //sys.dm:139
H.icon = src.meleewep.icon
H.icon_state = src.meleewep.icon_state
return
else return
In response to Pakbaum
When you get an undefined proc message about if(), you have an indentation error. Hit Ctrl+T to see your tabs and spaces.

Lummox JR
In response to Lummox JR
Ah! You're right ^.^

Something's still wrong though, it's replacing ALL of my hud2 icons, so I'm going to give that a gander, I can fix that I think.

Anyways, thanks!