lemme gees?
you got that idea of the bail out addon :P???
- ejectSeat(): Useful for making a quick escape, ejectSeat() unwelds the seat and launches it upwards.
I was building a spaceship the other day -- i just spawn a prop, weld on a seat and stick an E2 on it. That's pretty hard, right? I figured that I shouldn't have to go through all the trouble of spawning a seat. So, I wrote these functions for the community:
- spawnSeat(): Spawns a seat above the E2 chip.
- spawnSeat(E): Spawns a seat above the E2 chip and welds it to the specified entity for support.
- despawnSeat(): Removes the seat. Because, I shouldn't have to go through the trouble of getting out the remover tool, right?
- getSeat(): Returns the seat entity.
- ejectSeat(): Useful for making a quick escape, ejectSeat() unwelds the seat and launches it upwards.
Anyway, here is the code:
[highlight=Lua]registerCallback( 'destruct', function( context )
if context.entity.seat and context.entity.seat:IsValid() then context.entity.seat:Remove() end
end )
local function spawnSeat( chip, support )
if chip.seat and chip.seat:IsValid() then return end
local seat = ents.Create( 'prop_vehicle_prisoner_pod' )
seat:SetModel( 'models/Nova/airboat_seat.mdl' )
seat:SetPos( chip:GetPos() + chip:GetUp() )
seat:SetAngles( chip:GetAngles() )
seat:Spawn( )
constraint.Weld( chip, seat )
if support and support:IsValid() then
constraint.Weld( support, seat )
end
chip.seat = seat
end
registerFunction( 'getSeat', '', 'e', function( self, args )
if self.entity.seat and self.entity.seat:IsValid() then return self.entity.seat end return nil
end )
registerFunction( 'spawnSeat', '', 'e', function( self, args )
spawnSeat( self.entity )
end )
registerFunction( 'spawnSeat', 'e', 'e', function( self, args )
local support = args[2][1]( self, args[2] )
spawnSeat( self.entity, support )
end )
registerFunction( 'despawnSeat', '', '', function( self, args )
if self.entity.seat and self.entity.seat:IsValid() then self.entity.seat:Remove() end
end )
registerFunction( 'ejectSeat', '', '', function( self, args )
if !(self.entity.seat and self.entity.seat:IsValid()) then return end
constraint.RemoveConstraints( self.entity.seat, 'Weld' )
local phys = self.entity.seat:GetPhysicsObject()
phys:SetVelocity( self.entity:GetUp() * 100000 )
end )[/highlight]
Here is the code pastebinned for easy copying-and-pasting: http://ilovee2.pastebin.com/f60624d7e
Last edited by Azrael; 03-12-2009 at 03:53 PM. Reason: OOPS
lemme gees?
you got that idea of the bail out addon :P???
- ejectSeat(): Useful for making a quick escape, ejectSeat() unwelds the seat and launches it upwards.
Youtube :http://www.youtube.com/user/oen2oen
Cant you make it simpler?
Good job, but can you make it so that you can select the model of the seat?
does it fly the ship too? That'd be great if it could.
why bother with spawning a prop? Just change the model of the e2 gate with the console command. I think its something like wire_expression2_model modelpath.mdl
For the spawning ones, instead of storing the entity in the E2 entity why not just return it when created? You already have it set to return an entity, why not make it true?
That way people can create and store the entity with one line of code:Code:local function spawnSeat( chip, support ) if chip.seat and chip.seat:IsValid() then return end local seat = ents.Create( 'prop_vehicle_prisoner_pod' ) seat:SetModel( 'models/Nova/airboat_seat.mdl' ) seat:SetPos( chip:GetPos() + chip:GetUp() ) seat:SetAngles( chip:GetAngles() ) seat:Spawn( ) constraint.Weld( chip, seat ) if support and support:IsValid() then constraint.Weld( support, seat ) end chip.seat = seat return seat end registerFunction( 'spawnSeat', '', 'e', function( self, args ) return spawnSeat( self.entity ) end ) registerFunction( 'spawnSeat', 'e', 'e', function( self, args ) local support = args[2][1]( self, args[2] ) return spawnSeat( self.entity, support ) end )
[highlight=e2]
@persist Seat:entity
if(first()){
Seat = spawnSeat(entity())
}
[/highlight]
Against stupidity the Gods themselves contend in vain.
-Friedrich Schiller
The flame puts me in the mood to "Do it!".
-Dart, Legend of Dragoon
man, welding stuff together sure is hard work!
not to mention opening the vehicles page and clicking a seat!
My god, the pain in my hands are overwhelming!
this is Pyro-Fire's temporary account till i get my other computer running... cant remember the randomly generated password & don't wanna reset it again, so yeah.
No, as you can see I didn't change the rest of the code.
I just made it so the function returns the entity immediately.
It's more convenience than necessity. I didn't mean to delete the other functions I just didn't feel like copy pasting something I didn't edit at all.
Against stupidity the Gods themselves contend in vain.
-Friedrich Schiller
The flame puts me in the mood to "Do it!".
-Dart, Legend of Dragoon
Bookmarks