Raised This Month: $64 Target: $400
 16% 

Is there a way to set random colours on tempents?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CliptonHeist
New Member
Join Date: Feb 2016
Old 11-06-2018 , 22:14   Is there a way to set random colours on tempents?
Reply With Quote #1

I'm trying to make a plugin that creates a bunch of props when another prop is broken and shoot them out everywhere with a randomly coloured beam following them.

This is how I'm creating the props:
PHP Code:
        int entNum GetRandomInt(520);

        for(
int i 0entNumi++)
        {
            
int ent CreateEntityByName("prop_physics_override");
            
DispatchKeyValue(ent"Health""0");
            
DispatchKeyValue(ent"Model""models/items/boxmrounds.mdl");
            
HookSingleEntityOutput(ent"OnPlayerUse"OnPlayerUsetrue);
            
            
int rgba[4] = { GetRandomInt(0255), GetRandomInt(0255), GetRandomInt(0255), 255 };
            
TE_SetupBeamFollow(entg_iLaserg_iHalo10.05.01.010rgba);
            
DispatchSpawn(ent);

            
float pos[3], velocity[3];
            
GetEntPropVector(victimProp_Send"m_vecOrigin"pos);
            
velocity[0] = GetRandomFloat(0.020.0);
            
velocity[1] = GetRandomFloat(0.020.0);
            
velocity[2] = GetRandomFloat(0.020.0);
            
TeleportEntity(entposNULL_VECTORvelocity);
            
TE_SendToAll();
        } 
And this is where I'm having trouble:
PHP Code:
            int rgba[4] = { GetRandomInt(0255), GetRandomInt(0255), GetRandomInt(0255), 255 };
            
TE_SetupBeamFollow(entg_iLaserg_iHalo10.05.01.010rgba); 
Every time I try to compile while setting the colour randomly I get an error of: error 008: must be a constant expression; assumed zero
I know I could just use a switch statement to pick colours but I'd much prefer being able to have it completely random.

Thanks in advance.
CliptonHeist is offline
nosoop
Senior Member
Join Date: Aug 2014
Old 11-06-2018 , 22:31   Re: Is there a way to set random colours on tempents?
Reply With Quote #2

As the error indicates, array initializers can't have non-constant values.

You'll have to assign each non-constant index manually, like so:

Code:
int rgba[4] = { 255, ... }; // set all values to 255 initially
rgba[0] = GetRandomInt(0, 255);
rgba[1] = GetRandomInt(0, 255);
rgba[2] = GetRandomInt(0, 255);
__________________
I do TF2, TF2 servers, and TF2 plugins.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH)
nosoop is offline
CliptonHeist
New Member
Join Date: Feb 2016
Old 11-06-2018 , 23:17   Re: Is there a way to set random colours on tempents?
Reply With Quote #3

Ah I see where I was getting confused now lol...

This works great, thanks very much.
CliptonHeist is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:53.


Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode