Forum

> > CS2D > Scripts > How to use imagecolor for same img in diff rounds
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch How to use imagecolor for same img in diff rounds

1 Antwort
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt How to use imagecolor for same img in diff rounds

Denisgrad
User Off Offline

Zitieren
So Im making character customization menu and I was thinking instead of having 10+ different files for different hair colours, to instead use imagecolor(id,255,255,0). It works but every round restart or new round the ids of images change even though I freeimage and set everything to nil everytime an image is removed.

So instead of making hair red, it makes another image red. Is there a way to customly set the id of each image? Or should I just make a separate file for each hair colour?

alt Re: How to use imagecolor for same img in diff rounds

DC
Admin Off Offline

Zitieren
Whenever you call cs2d lua cmd image CS2D assigns a new free image ID. You have to save this ID in an variable if you want to do additional things with the image like using cs2d lua cmd imagecolor for instance.

NEVER use fixed IDs when working with images. It will go wrong as you noticed. Multiple objects in CS2D are sharing that ID-space so depending on what happens in the game the IDs can and will be different.

× WRONG - that "1" (or any other fixed number) as ID is always bad.
1
2
image(....)
imagecolor(1,255,0,0)

√ RIGHT - save & use the ID that image returns!
1
2
local id = image(....)
imagecolor(id,255,0,0)

(of course you have to insert proper parameters for image instead of just "....")
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht