Forum

> > CS2D > Scripts > How to use imagecolor for same img in diff rounds
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to use imagecolor for same img in diff rounds

1 reply
To the start Previous 1 Next To the start

old How to use imagecolor for same img in diff rounds

Denisgrad
User Off Offline

Quote
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?

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

DC
Admin Off Offline

Quote
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 "....")
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview