STEAM GROUP
Star Wars Vehicles: Redux SWV:R
Membership by invitation only
STEAM GROUP
Star Wars Vehicles: Redux SWV:R
0
IN-GAME
4
ONLINE
Founded
18 July, 2018
 This topic has been pinned, so it's probably important
dhkatz 27 Jul, 2018 @ 1:57pm
The Event System
What an Event System Is

If you've worked with Javascript or other languages in the past, you may be familiar with event systems.

Star War Vehicles: Redux is designed to be an event driven framework. This means your code will be reactive instead of proactive. You do things based on an event that just happened. The base itself takes care of making sure you react to the correct event.

What Events are there?

The current list of events are as follows:

  • OnFire(group, seat) - Triggers whenever any of the ship's weapon groups are fired.
  • OnOverheat(group, seat) - Triggers whenever any of the ship's weapon groups overheat.
  • OnOverheatReset(group, seat) - Triggers whenever any of the ship's weapon groups reset.
  • OnShieldsDown() - Triggers when the shields go down.
  • OnCollision(damage) - Triggers when the ship makes a physics collision (and shields are down)
  • OnCritical() - Triggers when the ship enters the critical threshhold.
  • OnEnter(player) - Triggers when a player enters the ship (pilot or passenger).

What can I do with these Events?

Well an important thing to note is that these events get called on the server and the client! This is so you can be as flexible as possible with what you do with the events. Let's do an example.

Say you want to let the player know in chat when their shields go down. Chat functions are clientside so we need to add this event on the client.

So, when initializing your ship add the event:

self:AddEvent("OnShieldsDown", function() if LocalPlayer():GetNWEntity("Ship") ~= self then return end -- On people in the ship! chat.AddText(Color(255, 0, 0), "[WARNING] ", Color(255, 255, 255), "SHIELDS OFFLINE") end)

This would print "[WARNING] SHIELDS OFFLINE" to all players inside the ship. If you wanted only the pilot to know then you could add further checks.

You can see it in action here: https://www.youtube.com/watch?v=lsvjaC7cjxk

This event system is already used internally for default events such as the overheating noises:

self:AddEvent("OnFire", function(group, seat) if LocalPlayer():GetNWEntity("Ship") ~= self then return end if LocalPlayer():GetNWString("SeatName") ~= seat then return end if (group.Overheat >= group.OverheatMax - 10) then self:EmitSound("vehicles/shared/swvr_overheat_ping.wav", 75, 100, math.Clamp(math.exp(math.pow(group.Overheat / group.OverheatMax * 0.98, 7)) - 1, 0, 1)) end end)

Here's how that looks: https://www.youtube.com/watch?v=WjSAp63O51M

If you want to add the default events to your ship, you can simply call self:SetupDefaults() or configure it as follows.

self:SetupDefaults({ OnShieldsDown = false })

Setting an event to false stops the default from running (so you can override it with your own). You can add as many events as you want, even multiple of the same event and they will all be called automatically.
Last edited by dhkatz; 27 Jul, 2018 @ 2:08pm
< >
Showing 1-3 of 3 comments
Syphadias 27 Jul, 2018 @ 5:44pm 
These events are looking pretty good! They will be a nice addition to the ships for sure :physgun:
Cody Evans 28 Jul, 2018 @ 12:48am 
Looking great!
Any news:)?
< >
Showing 1-3 of 3 comments
Per page: 1530 50