Scripts / Hide and show randomly?

Author
Message
Honkeyboy
3D Media Maker
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 14th May 2021 19:14
Hey all, how would I hide and show an entity randomly? I know we have the mathrandom command but how would you use it to get an entity to randomly hide and show using a percentage chance?
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 14th May 2021 21:47
math.random() returns a random value in the range 0-1, simply compare it to your chosen 'chance' value in an if:

if math.random() < 0.2 then .... end

That would basically trigger roughly 20% of the time.

Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 14th May 2021 21:51 Edited at: 14th May 2021 21:54

Edit: Amen answered quicker!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 14th May 2021 21:52 Edited at: 14th May 2021 21:54
Edit: Amen answered it quicker!!
PM
Honkeyboy
3D Media Maker
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 15th May 2021 01:15 Edited at: 15th May 2021 01:35
ahh ok thanks just did this but on a timer apposed to a random event


It does work although i need to know how the directions work so i can get the snowfall right e.g, the snow works but i need it to just fall(if you get me) I've been going through AM's instructions as to what does what but would like a bit better instruction... I have to take a day off mapping to get into scripting if i do one then try the otherwise i just get confused. It's hard doing 200 things at once tbh i normally build all the levels then do the scripting I'm just getting ahead of myself ....although i nearly have re done both the highland isles and the eastern isles will post on the WIP
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 15th May 2021 05:44
'if' falls straight down on it's partners 'end'??

Since I haven't looked at the particles commands for a good bit... went and looked.

First line is to activate particles...
2nd line = Offsets... (min-all // max-all) -- what area / volume does emitter ejection cover?
3rd line = Scales... -- how big are particles?
4th line = Movement Speeds...(min-all // max-all)
5th line = Rotate Speed (Z)

Maybe you want to modify 4th line.....? I think you want 'Y' to be a faster negative, while a couple other parameters where tweaked. Ended up with:
ParticlesAddEmitterEx( emitter, 1/4, 1,
-100, 0, -100, 200, 300, 300, -- offsets
500, 1000, 500, 1000, -- scale
-0, -1, -0, 0, -1.8, 0, -- movement
-0.02, 0.1, -- rotate speed
1400, 1400, -- life
55, 99, 55, 99, -- alpha start/ end
77, -1, 0, imageFile, 16 ) -- spawn vigor, etc
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 15th May 2021 08:06 Edited at: 15th May 2021 08:16
StartParticleEmitter(e) and StopParticleEmitter(e) are legacy commands and have no effect over the emitters created with ParticlesAddEmitterEx.

To control an emitter properly you need to use the 'particles' commands:

ParticlesSpawnParticle( emitterId, xPos, yPos, zPos ) -- forces the emitter to spawn a particle at the specified position
ParticlesSetFrames( emitterId, animationSpeed, startFrame, endFrame )
ParticlesSetSpeed( emitterId, movementSpeedMinX, movementSpeedMinY, movementSpeedMinZ,
movementSpeedMaxX, movementSpeedMaxY, movementSpeedMaxZ )
ParticlesSetOffset( emitterId, offsetMinX, offsetMinY, offsetMinZ,
offsetMaxX, offsetMaxY, offsetMaxZ )
ParticlesSetScale( emitterId, scaleStartMin, scaleStartMax, scaleEndMin, scaleEndMax )
ParticlesSetAlpha( emitterId, alphaStartMin, alphaStartMax, alphaEndMin, alphaEndMax )
ParticlesSetAngle( emitterId, xAngle, yAngle, zAngle ) - Euler angles

-- the '0' parameters below are not yet fully implemented in the engine, basically they are placeholders for the future
ParticlesSetRotation: ParticlesSetRotation( emitterId, 0, 0, rotateSpeedMinZ, 0, 0, rotateSpeedMaxZ )
ParticlesSetLife: ParticlesSetLife( emitterId, frequency, lifeMin, lifeMax, maxParticles, 0, maxPerFrame )
-- maxParticles default is 100, maxPerFrame default is 50

-- This command mimics a basic wind effect, all particles will be effected by this ..
ParticlesSetWindVector: ParticlesSetWindVector( windX, windZ ) -- values are X & Z units per frame
-- unless specifically omitted sith this command
ParticlesSetNoWind( emitterId ) -- All particles created by the specified emitter will not be affected by wind.

-- This command mimics a basic gravity component
ParticlesSetGravity( emitterId, startG, endG ) -- values are Y units per frame

** Note that the ParticlesSetLife description in global.lua is missing the frequency parameter, I've corrected that above.

So for example if you wanted to 'turn off' an emitter temporarily you should use:
ParticlesSetLife( emitterId, 0, 0, 0, 0, 0, 0 )

And to turn it back on again:
ParticlesSetLife( emitterId, frequency, lifeMin, lifeMax, maxParticles, 0, maxPerFrame )

The parameters are:
frequency - the number of milliseconds between each 'spawn' event, example; 50 would spawn new particles every 1/20th of a second. Set this to 15 to get particles spawning every frame.

lifeMin - the minimum 'life' for particles spawned in milliseconds, if set to 500 for example all particles would liver for a minimum of 1/2 a second.

lifeMax - the maximum time in milliseconds a particle can live for, if set to 2000 for example all particles die after a maximum of 2 seconds.
The actual life of any individual particle will be a random value within the range of lifeMin .. lifeMax

maxParticles - the maximum number of particles this emitter is allowed to spawn in total

maxPerFrame - the maximum particles that can be spawned by this emitter in one spawn event, for example if you have frequency set to 100, maxParticles set to 500 and maxPerframe set to 10 then this emitter would spawn 100 particles a second until 500 particles have been spawned, after that it will only be able to spawn new particles after existing ones have died.
Been there, done that, got all the T-Shirts!
PM
Honkeyboy
3D Media Maker
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 15th May 2021 15:26 Edited at: 15th May 2021 16:36
Ahh that's why it wasn't stopping Thanks AM much clearer now and cheers GB

Edit: Ok emitterId ? how's that work? i have no emitterId or do i?
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 15th May 2021 17:14
Quote: "emitterId ? how's that work? i have no emitterId or do i?"

it's what gets returned when you first create the emitter
i.e.
local emitter = ParticlesGetFreeEmitter()
if emitter == -1 then return end
ParticlesAddEmitterEx( emitter, .....)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Login to post a reply

Server time is: 2024-04-24 06:26:09
Your offset time is: 2024-04-24 06:26:09