Why does this crash? I'm making a headcrab canister, making a seat inside the canister then forcing players to enter the seat but the last loop causes the game to crash to desktop.
local canister = ents.Create( "env_headcrabcanister" )
canister:SetPos( Vector(v.x,v.y,v.z) )
canister:SetAngles( Angle(-45,0,0) )
canister:SetKeyValue( "FlightSpeed", 2500 )
canister:SetKeyValue( "FlightTime", 10 )
canister:SetKeyValue( "Damage", math.random(50,90) )
canister:SetKeyValue( "DamageRadius", math.random(300,512) )
canister:SetKeyValue( "SmokeLifetime", math.random(5,10) )
canister:SetKeyValue( "StartingHeight", 1000 )
canister:SetKeyValue( "spawnflags", 2 )
canister:Spawn()
canister:Fire("FireCanister")
local pod = ents.Create( "prop_vehicle_prisoner_pod" )
pod:SetParent(canister)
pod:SetKeyValue("vehiclescript","scripts/vehicles/prisoner_pod.txt")
pod:SetModel( "models/nova/airboat_seat.mdl" )
pod:SetPos(Vector(0,0,20))
pod:SetAngles( Angle(0,0,0) )
pod:Spawn()
local seat = nil
for _, v in pairs ( ents.FindByClass( "prop_vehicle_prisoner_pod" ) ) do
seat = v
end
--[[ CRASH!!
for _, v in pairs ( player.GetAll() ) do
if ( !v:InVehicle() ) then
v:EnterVehicle( seat )
end
end--]]
IGModAudioChannel:Stop(). Untested but inside your callback with station, you can do:
hook.Add("Think", station, function(s)
if not LocalPlayer():Alive() then s:Stop() end
end)
This callback will automatically get removed when the station is stopped, thanks to the hook system.
Quick question,
JobInfo.Think = function()
JobInfo:SetText(v.Name.." ("..GAMEMODE.Limit[k].."/"..numPlayers..")")
end
this doesn't get updated does anyone know why?
Try using self:
function JobInfo:Think()
self:SetText(v.Name.." ("..GAMEMODE.Limit[k].."/"..numPlayers..")")
end
Not really sure if that's how it works, I've never messed with DarkRP?
It's not DarkRP hahaha but thanks I'll try that
Vehicle might not be initialized. Try waiting a frame before putting the player in.
You're causing all players to enter the same seat.
That would make sense but even in controlled settings with one player, one seat and numerous if checks the game still crashes. Here's the full function for retrospect, the loadsave/currsave thing is just a table of vectors.
concommand.Add("tast_test_canisters",function( ply )
if ply:IsSuperAdmin() then
if file.Exists( "tast/"..game.GetMap().."_pspawn"..".txt", "DATA" ) then
loadsave = file.Read( "tast/"..game.GetMap().."_pspawn"..".txt", "DATA" )
currsave = util.JSONToTable(loadsave)
for k,v in pairs(currsave) do
local canister = ents.Create( "env_headcrabcanister" )
canister:SetPos( Vector(v.x,v.y,v.z) )
canister:SetAngles( Angle(-45,0,0) )
canister:SetKeyValue( "FlightSpeed", 2500 )
canister:SetKeyValue( "FlightTime", 10 )
canister:SetKeyValue( "Damage", math.random(50,90) )
canister:SetKeyValue( "DamageRadius", math.random(300,512) )
canister:SetKeyValue( "SmokeLifetime", math.random(5,10) )
canister:SetKeyValue( "StartingHeight", 1000 )
canister:SetKeyValue( "spawnflags", 1 + 2 )
canister:Spawn()
canister:Fire("FireCanister")
local pod = ents.Create( "prop_vehicle_prisoner_pod" )
pod:SetParent(canister)
pod:SetKeyValue("vehiclescript","scripts/vehicles/prisoner_pod.txt")
pod:SetModel( "models/nova/airboat_seat.mdl" )
pod:SetPos(Vector(0,0,20))
pod:SetAngles( Angle(0,0,0) )
pod:Spawn()
end
local seat = nil
for _, v in pairs ( ents.FindByClass( "prop_vehicle_prisoner_pod" ) ) do
seat = v -- Add all pods to the variable seat
end
for _, v in pairs ( player.GetAll() ) do
if IsValid(v) and seat:IsValidVehicle() then -- Valid checks
if !v:InVehicle() and seat:GetDriver() == NULL then -- If the player is NOT in a vehicle and the targeted vehicle is NOT occupied
v:EnterVehicle( seat ) -- THIS LINE CAUSES THE GAME TO CRASH!! D:
end
end
end
end
end
end)
Make sure to check if v is valid inside the loop since time passed..
Already doing so like this
for _, v in pairs ( player.GetAll() ) do
if IsValid(v) and seat:IsValidVehicle() then -- Valid checks
if !v:InVehicle() and seat:GetDriver() == NULL then -- If the player is NOT in a vehicle and the targeted vehicle is NOT occupied
timer.Simple(1,function() -- DON'T CRASH
v:EnterVehicle( seat )
end)
end
end
end
I meant inside the loop, but there are a host of optimisations that can be made to your code:
if (seat:IsValidVehicle() and not seat:GetDriver():IsValid()) then
local tPlayers = player.GetAll()
for i = 1, #tPlayers do
local pPlayer = tPlayers[i]
timer.Simple(0, function()
if (pPlayer:IsValid() and not pPlayer:InVehicle()) then
pPlayer:EnterVehicle(seat)
end
end)
end
end
Also, I still have no idea what your goal effect is; why are you making all players enter the same seat? The driver won't be invalid by the time all of the players enter it at the same time.
I'm not trying to make everyone enter the same seat, honestly I have no idea what I'm doing. I had an idea for an effect for my game mode but can't find any examples so I've been trying to make it myself with no guidance. What I've managed to do (after finding obscure examples on the Valve wiki of all places) is properly create the env_headcrabcanister and make it fly into the map from the sky box. This was hard figuring out because I wasn't able to find any references to making vehicles on the wiki. So the canister is done, it looks great and the KeyValues are set! What I then tried to do was attempt to make a vehicle seat and parent it to the canister entity, then force each player per canister that exists into a separate seat so that they would be riding the canister into the map. (although I can't find any help on what exactly the keyvalue "limitview" does because changing the bool does nothing). The end goal is literally a spawn effect where players fly into the map on head crab canisters. As for optimizations I'm trying to use as little loops and if statements as possible since this is all server side code.
Head crab canisters are created based on how many keys are in a local table which contain vector values, this part works wonderfully and is used already when spawning weapons into the map. I'm trying to create this system to be modular and not dependent on the map, I have a dev tool swep I made to create these spawn positions and save them as data tables for reference later when creating entities: this makes the game mode compatible with any map thus not having to make a custom map.
Hey I am trying to make a target spectate himself in a sense, that he can see himself but cant move around or do anything - since he is in spectating mode.
My code, which doesnt work, cuz it turns me invisible is this
target:Spectate( OBS_MODE_CHASE )
target:SpectateEntity( target )
can somebody tell me how I should do this? I tried CalcView but didnt succeed either
Post your CalcView code.
Does anyone by any chance have a modified 'Sprops' LUA Spawnlist that supports Skingroups upon spawning?
I have a modified version working but can't seem to get the skingroup and bodygroup features to take effect.
At the moment I'm using the alternative spawnmenu.AddPropCategory , but I'm unable to get parent ids and branches to work. Also people are telling me that this method is more likely to cause issues.
So I used a PreDrawEffects hook to draw laser sights from multiple weapons in different situations. I used LocalPlayer() so I think I already know the answer to my question but... if player A has a laser but player B does not... will player B see player A's laser? Will the laser come from player A's gun, or from the LocalPlayer()'s gun?
tiny snippet:
local ply = LocalPlayer()
local wep = ply:GetActiveWeapon()
No, you'll have to loop over all players and draw their respective lasers.
local function DecCalcView(ply, pos, angles, fov)
local view = {}
view.origin = pos-(angles:Forward() * 1000)
view.angles = angles
view.fov = fov
view.drawviewer = true
print("test print")
return view
end
I hooked this inside my function which gets run whenever I run my command, it is in shared tho
Can you post the code that adds the hook?
function ulx.commandtest( calling_ply, target_plys)
for _, target in ipairs( target_plys ) do
hook.Add( "CalcView", "DecCalcView", DecCalcView )
for i = 1, 5 do
local effectdata = EffectData()
effectdata:SetOrigin(target:GetPos())
util.Effect( "BloodImpact", effectdata)
end
/*timer.Simple(3,function()
target:Kill()
target:Spawn()
end)*/
end
end
its for ulx as you can see, might be because of that I suppose
You are running client code on the server. Lookup networking.
You should just add the CalcView hook from the beginning and return if the user has a variable set on them which you can network.
Is there a way to pre-load audio files? because freezing on my own pc (and anyone who does not have a fast pc and/or withotu a fast drive) is bad enough to break flow of something. Is there a way to pre load so the freezing when the audio is played the the "first" time is minimized? It stops freezing after its played at least once but it be kind of jank to play all 20 sounds and then stop them (which could result in a millisecond of earrape)
util.PrecacheSound
i googled everything but precache. good job me
So Entity:Fire is for entity inputs but what is for entity outputs?
How to enter the coordinates of getpos and getangles?
i need getpos and getangles to automatically adjust said positions of something which is attached to a prop, only issue is that it is off by 90 degrees on some axles.
vgui.Start3D2D( self:GetPos(), self:GetAngles(), 0.2 )
Use GetUp, GetForward and GetRight
would i also be able to use this?
tv_pos = self:GetPos()
tv_ang = self:GetAngles()
vgui.Start3D2D( Vector(tv_pos.x + 10, tv_pos.y - 30, tv_pos.z), Angle(tv_ang.x, tv_ang.y + 90, tv_ang.z + 90), 0.10)
sampleFrame:Paint3D2D()
vgui.End3D2D()
Only way I've found to do this is to use the `AddOutput` (https://developer.valvesoftware.com/wiki/AddOutput) input on the given entity (env_headcrabcanister in this case). You'll have to make this target a custom entity of yours which defines a ENTITY(AcceptInput) so you can receive it in Lua.
Sorry, you need to Log In to post a reply to this thread.