Hi guys!
I'm having some issues with setting the position of an entity (a car) with another entity (point entity put in by Hammer). Before I try and spawn my car, it works completely fine when I try to print out the position of the point entity. But when I try to set the position of the car with the point entity, it tells me that the point entity is NULL.
Code:
--carSpawnIn is players that got into a car. If it isn't equal to all the point entities plus 1, then it dosen't call the function.
function GM:ShowSpare2( ply )
--LINE 448 ONE BELOW:
carspawn = carSpawns[1]:GetPos()
print(carspawn) --THIS WORKS BEFORE "SpawnCar1" IS CALLED
if carSpawnIn != table.Count(carSpawns) + 1 then
SpawnCar1( ply, carspawn )
carSpawnIn = carSpawnIn + 1
end
function SpawnCar1( ply, pos )
local car = ents.Create("prop_vehicle_jeep_old")
car:SetModel("buggy.mdl")
car:SetKeyValue("vehiclescript","jeep_test.txt")
car:SetPos(loc)
car:SetAngles(Angle(0,90,0))
car:Spawn()
ply:EnterVehicle(car)
end
Printing Before:
--pressing f4 3 times
1024.000000 768.000000 0.000000
1024.000000 768.000000 0.000000
1024.000000 768.000000 0.000000
Error:
[Race] gamemodes/hardcoreracing/gamemode/init.lua:448: Tried to use a NULL entity!
1. GetPos - [C]:-1
2. unknown - gamemodes/hardcoreracing/gamemode/init.lua:448
If I could get any help, that would be awesome!
Thanks!
Wait a frame before putting the player in the vehicle. You can use a 0-second timer to achieve this.
That dosen't seem to work... still gives me the same error
Here's one thing I see right off the bat:
car:SetPos(loc)
loc doesn't exist, you'll need to use pos.
Otherwise, it looks like whatever entities you're referencing in carSpawns are being removed or overwritten at some point.
Hey, figured out that I didn't exclude my entities from a game.CleanUpMap function. Thank you for helping guys!
(btw, I'm new to the new format of this fourm, where's the "solved" button?)
if you offer a 'bounty' for your question you can't mark it as solved unfortunatly... Thats why i'm always at least giving 1 coin as bounty for any question ^^
Sorry, you need to Log In to post a reply to this thread.