Hi guys I have a small script, I have a system which allows an image to be displayed on the hud. But I want it to be random with other images which are slightly different. So this is what I am trying to do, but I isn't working and I am not sure what other methods could be used.
[code]
local killer = {"Headshot.png","Headshot1.png"} --Songs for when the player joins and they heir my lovely choice of music.
local killicon = {
duration = 1; -- Length of time to display image
color = Color( 225, 225, 225, 400 ); -- Color overlay of image; white = original color of image
--material = Material( "Headshot.png" ); -- Material to be used
material = Material( (killer[math.random(2,#killer)]) ); -- Material to be used
x = 1700; -- x coordinate for the material to be rendered ( mat is drawn from top left to bottom right )
y = 350; -- y coordinate for the material to be rendered ( mat is drawn from top left to bottom right )
w = 200; -- width of the material to span
h = 200; -- height of the material to span
};
[/code]
I then obviously set the image via a 'surface.SetMaterial' etc..
Any help is greatly appreciated.
Thanks.
Duby
One problem in your code might be this:
[code]material = Material( (killer[math.random(2,#killer)]) );[/code]
As far as I know, those second ()s shouldn't be there. Unless that's syntactic sugar, in which case I'm not sure.
[B]EDIT:
[/B]You also seem to state your math.random minimum value as 2 rather than 1. If you only have two images, you're guaranteed to get the same number every time.
I solved it now, I needed to move this table within a local function I was using. I also missed out a ',' by the number before the #
Sorry, you need to Log In to post a reply to this thread.