Discord
Steam
/
General Discussion
/
Problem with b..
Login/Join
Event Log
Problem with boat vehicle.
0 replies, posted
Search
In This Thread
Hello, my problem is that in the code is a problem that prevents the player who correctly leave the scripted vehicle. Everything works pretty well except when the player presses E to leave the boat, he finds himself teleporter as it should and the camera is well disable except that the player still remains to control the boat and the only way to leave and delete it. No error message is visible and it works very well solo but not on my server. I put some of the code, I think the error is in it. AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') ENT.Model = "models/blackflag/ships/pirate/pirate_frigate.mdl" //Speed Limits ENT.MaxVelocity = 500 ENT.MinVelocity = -500 // How much the plane will rotate around the Z axis when turning. Lower Value = More Angle. Recomended = 2.5 for super sonic jets, 3.5 to 4 for larger stuff. ENT.BankingFactor = 10.0 ENT.InitialHealth = 25000 ENT.HealthVal = nil ENT.Destroyed = false ENT.Burning = false ENT.Speed = 0 ENT.DeathTimer = 0 // Timers ENT.LastPrimaryAttack = 0 ENT.LastSecondaryAttack = 0 ENT.LastFireModeChange = 0 ENT.FlareCooldown = 15 ENT.FlareCount = 5 ENT.MaxFlares = 8 // Equipment ENT.MachineGunModel = "models/h500_gatling.mdl" ENT.MachineGunOffset = Vector( 255, 0, 67 ) ENT.CrosshairOffset = 67 ENT.NumRockets = nil ENT.PrimaryCooldown = 0.03 function ENT:SpawnFunction( ply, tr, class ) local SpawnPos = tr.HitPos + tr.HitNormal * 100 local ent = ents.Create( class ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() return ent end function ENT:Initialize() self.HealthVal = self.InitialHealth --self:SetColor(Color(0,0,0,0)) --self:SetRenderMode( RENDERMODE_TRANSALPHA ) self:SetNetworkedInt( "health",self.HealthVal) self:SetNetworkedInt( "HudOffset", self.CrosshairOffset ) self:SetNetworkedInt( "MaxHealth",self.InitialHealth) self:SetNetworkedInt( "MaxSpeed",self.MaxVelocity) self.LastAttackKeyDown = 0 self.LastReminder = 0 self.LastAttack = CurTime() self.LoopSound = CreateSound( self, "vehicles/diesel_loop2.wav" ) self:SetUseType( SIMPLE_USE ) self.IsFlying = false self.Pilot = NULL self.CannonIndex = 1 self.CannonPositions = { { Vector( 1040, -171, 0 ), Vector( 1040, 0, 0 ), Vector( 1040, 171, 0 ) }; { Vector( -1047, 203, 0 ), Vector( -1047, -203, 0 ) }; { Vector( 640, -422, -2 ), Vector( 468, -422, -2 ), Vector( 147, -422, -2 ), Vector( -101, -422, -2 ) }; { Vector( 640, 422, -2 ), Vector( 468, 422, -2 ), Vector( 147, 422, -2 ), Vector( -101, 422, -2 ) }; } // Misc self:SetModel( self.Model ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self.PhysObj = self:GetPhysicsObject() self.BuoyancyRatio = 0.01 if ( self.PhysObj:IsValid() ) then self.PhysObj:Wake() self.PhysObj:SetMass( 10000 ) self.PhysObj:SetBuoyancyRatio( self.BuoyancyRatio ) end self.KeepUp = ents.Create("prop_physics") self.KeepUp:SetModel("models/props_wasteland/cargo_container01.mdl") self.KeepUp:SetPos( self:GetPos() + Vector( 0, 0, -20 ) ) self.KeepUp:SetAngles(self:GetAngles()+Angle(0, -90, 0)); self.KeepUp:Spawn() self.KeepUp:Activate() self.PhysObjB = self.KeepUp:GetPhysicsObject() if ( self.PhysObjB:IsValid() ) then self.PhysObjB:SetMass( 150 ) end local weld = constraint.Weld( self.KeepUp, self, 0, 0, 0, true ) local keepup = constraint.Keepupright( self.KeepUp, Angle( 0,-90,0 ), 0, 999999999999999999999999 ) self:StartMotionController() end function ENT:ShootCannonBall( i ) local tab = self.CannonPositions[self.CannonIndex] local norm if( self.CannonIndex == 1 ) then norm = self:GetForward() elseif( self.CannonIndex == 2 ) then norm = self:GetForward()*-1 elseif( self.CannonIndex == 3 ) then norm = self:GetRight() else norm = self:GetRight()*-1 end self.PrimaryAmmo = self.PrimaryAmmo or "prop_physics" -- local normal = ( self:GetPos() - self:LocalToWorld( pos[i] ) ):Normalize() local cannonball = ents.Create( self.PrimaryAmmo ) cannonball:SetPos( self:LocalToWorld( tab[i] ) ) cannonball:SetPhysicsAttacker( self.Pilot ) cannonball:SetModel( "models/roller_old.mdl" ) cannonball:Spawn() cannonball.MinDamage = 4500 cannonball.MaxDamage = 8500 cannonball.Radius = 750 cannonball:SetOwner( self ) cannonball:GetPhysicsObject():SetMass( 50 ) cannonball:GetPhysicsObject():ApplyForceCenter( norm * 200000000 ) cannonball:Fire("kill","",7) cannonball.Owner = self.Pilot cannonball:EmitSound("ambient/explosions/explode_"..math.random(7,9)..".wav", 511, math.random( 80, 110 ) ) for j=1,10 do local fx = EffectData() fx:SetOrigin( self:LocalToWorld( tab[i] ) + norm * ( j * math.random(110,120) ) ) fx:SetStart( self:LocalToWorld( tab[i] ) + norm * ( j * math.random(110,120) ) ) fx:SetNormal( norm ) fx:SetScale( 10 * j ) util.Effect( "Firecloud", fx ) util.Effect( "Launch2", fx ) end end function ENT:OnRemove() if ( IsValid( self.Pilot ) ) then self.camera:Remove() self:EjectPilotSpecial() end self:Remove() self.KeepUp:Remove() self.LoopSound:Stop() end function ENT:PhysicsCollide( data, physobj ) if ( data.Speed > self.MaxVelocity * 0.5 && data.DeltaTime > 0.2 ) then self.HealthVal = math.floor( self.HealthVal - ( data.Speed / 4 ) ) self:SetNetworkedInt( "health", self.HealthVal ) end end function ENT:Use(ply,caller) if ( !self.IsFlying && !IsValid( self.Pilot ) ) then self.LastUse = CurTime() + 1 self.camera = ents.Create("prop_dynamic") self.camera:SetModel("models/props_borealis/bluebarrel001.mdl") self.camera:SetPos( self:GetPos() + Vector( -1550, 0, 750 ) ) self.camera:SetAngles(self:GetAngles()+Angle(0, 0, 0)) self.camera:SetParent(self.KeepUp) self.camera:Spawn() self:GetPhysicsObject():Wake() self:GetPhysicsObject():EnableMotion(true) self.IsFlying = true self.Pilot = ply self.Owner = ply self:SetOwner( ply ) ply:Spectate( OBS_MODE_CHASE ) ply:SpectateEntity(self.camera) ply:DrawViewModel( false ) ply:DrawWorldModel( false ) ply:StripWeapons() ply:SetScriptedVehicle( self ) ply:SetNetworkedBool("InFlight", true) ply:SetNetworkedEntity( "Plane", self ) self:SetNetworkedEntity("Pilot", ply ) self.LoopSound:PlayEx(511,100) end end function ENT:EjectPilotSpecial() if ( !IsValid( self.Pilot ) ) then return end self.Pilot:UnSpectate() self.Pilot:DrawViewModel( true ) self.Pilot:DrawWorldModel( true ) self.Pilot:Spawn() self.Pilot:SetNetworkedBool( "InFlight", false ) self.Pilot:SetNetworkedEntity( "Plane", NULL ) self:SetNetworkedEntity( "Pilot", NULL ) self:SetOwner( NULL ) self.Pilot:SetPos( self:GetPos() + self:GetForward() * 0 + self:GetUp() * 150 ) self.Pilot:SetAngles( Angle( 0, self:GetAngles().y,0 ) ) self.Owner = NULL self.Pilot:SetScriptedVehicle( NULL ) self.Speed = 0 self.IsFlying = false self.Pilot = NULL self:NextThink( CurTime() + 2 ) self.LoopSound:Stop() return end function ENT:OnTakeDamage( dmginfo ) end function ENT:Think() if (self:GetNWInt("health") <= 0) then self:Remove() end if(self:GetAngles().x < -20) then self:SetAngles(Angle(-0, self:GetAngles().y, self:GetAngles().z)); end if(self:GetAngles().x >20) then self:SetAngles(Angle(0, self:GetAngles().y, self:GetAngles().z)); end if(self:GetAngles().z < -20) then self:SetAngles(Angle(self:GetAngles().x, self:GetAngles().y, -0)); end if(self:GetAngles().z > 20) then self:SetAngles(Angle(self:GetAngles().x, self:GetAngles().y, 0)); end if ( self.Destroyed ) then self.DeathTimer = self.DeathTimer + 1 self.BuoyancyRatio = self.BuoyancyRatio - 0.0001--1.0025 self.PhysObj:SetBuoyancyRatio( self.BuoyancyRatio ) if self.DeathTimer < 200 then local effectdata = EffectData() effectdata:SetOrigin( self:GetPos() + self:GetRight() * math.random(-62,62) + self:GetForward() * math.random(-62,62) ) util.Effect( "immolate", effectdata ) if self.BuoyancyRatio < 0.0022 then self.BuoyancyRatio = 0.0022 end end if self.DeathTimer > 200 then if self.BuoyancyRatio < 0.0021 then self.BuoyancyRatio = 0.0021 end end if self.DeathTimer > 400 then self:EjectPilotSpecial() self.BuoyancyRatio = 0.0020 end if self.DeathTimer > 425 then self:Remove() end end if ( self.IsFlying && IsValid( self.Pilot ) ) then local vel = self:GetVelocity():Length() self.LoopSound:ChangePitch( math.Clamp( 90 + ( vel / 30 ), 90, 155 ), 0.1 ) if( self.Pilot == NULL ) then return end self.Pilot:SetPos( self:GetPos() + self:GetUp() * 120 ) if( self.Pilot:KeyDown( IN_ATTACK ) && self.LastAttack + 5.0 <= CurTime() ) then self.LastAttack = CurTime() for i=1,#self.CannonPositions[self.CannonIndex] do timer.Simple( i, function() if( IsValid( self ) ) then self:ShootCannonBall( i ) end end ) end end if( self.Pilot:KeyDown( IN_USE ) && self.LastUse + 1.0 <= CurTime() ) then self.camera:Remove() self.Pilot:UnSpectate() self:EjectPilotSpecial() return end // Firemode if ( self.Pilot:KeyDown( IN_RELOAD ) && self.LastFireModeChange + 0.5 <= CurTime() ) then self.LastFireModeChange = CurTime() self.CannonIndex = self.CannonIndex + 1 if( self.CannonIndex > 4 ) then self.CannonIndex = 1 end local messages = { "Canon avant", "Canons arrière", "Canons côté droit", "Canons du côté gauche" } self.Pilot:PrintMessage( HUD_PRINTCENTER, messages[self.CannonIndex] ) end self:NextThink( CurTime() ) else self:NextThink( CurTime() + 1 ) end return true end function ENT:PhysicsSimulate( phys, deltatime ) self.PhysObj:SetBuoyancyRatio( self.BuoyancyRatio ) phys:Wake() if ( self.IsFlying && self:WaterLevel() > 0 && !self.Destroyed ) then local p = { { Key = IN_FORWARD, Speed = 3.5 }; { Key = IN_BACK, Speed = -1.5 }; } -- local angvel = -0.7 for k,v in ipairs( p ) do if ( self.Pilot:KeyDown( v.Key ) ) then self.Speed = math.Approach( self.Speed, v.Speed * 50, v.Speed ) if( v.Key == IN_FORWARD ) then angvel = 0.95 end -- self.PhysObj:AddAngleVelocity( Vector( 0, -0.7 * angvel, 0 ) ) else self.Speed = math.Approach( self.Speed, 0, 0.25 ) end end -- //if( self.Speed > 10 ) then -- self.PhysObj:AddAngleVelocity( Vector( 0, -0.7, 0 ) ) -- //end local t = { { Key = IN_MOVERIGHT, Speed = 1 }; { Key = IN_MOVELEFT, Speed = -1 } } if( self:GetVelocity():Length() > 50 ) then for k,v in ipairs( t ) do if( self.Pilot:KeyDown( v.Key ) ) then self.PhysObj:AddAngleVelocity( Vector( 0, 0, -v.Speed/4 ) ) self.PhysObj:ApplyForceCenter( self:GetRight() * ( v.Speed * 150 ) ) end end end self.Speed = math.Clamp( self.Speed, self.MinVelocity, self.MaxVelocity ) self:GetPhysicsObject():ApplyForceCenter( self:GetForward() * ( self.Speed * 150 ) ) end end
Sorry, you need to
Log In
to post a reply to this thread.