• Car system, trying to remove car, if car isvalid?
    1 replies, posted
Hey, i tired alot, and can't figure this out. How can i get the spawned car, and then remove it, if the player spawns a new one? [code] function SpawnCar(ply, cmd, args) if (args[1]) then if args[2] == "car1" then local PlyHasCar = false if !ply:GetNetworkedInt("car1") == 1 then return end for k, v in pairs(ents.GetAll()) do if v = v:GetNWInt("vehicleID", Car1:EntIndex(), ply:SteamID())) then v:Remove() end end local Vehicles = 0 DarkRP.notify(ply, 1, 4,"You're jeep has spawned! ".. Vehicles) local Car1 = ents.Create("prop_vehicle_jeep_old") Car1:SetModel("models/buggy.mdl") Car1:SetKeyValue("vehiclescript", "scripts/vehicles/jeep_test.txt") Car1:SetPos(Vector(59.891289, -964.276733, -112.143753)) Car1:SetAngles(Angle(0, 0, 0)) Car1:addKeysDoorOwner(ply) Car1:CPPISetOwner(ply) Vehicles = Vehicles + 1 Car1:Spawn() Car1:Activate() Car1:SetNWInt("vehicleID", Car1:EntIndex(), ply:SteamID()) end end end concommand.Add("SpawnCar", SpawnCar) [/code]
[code] function SpawnCar(ply, cmd, args) if (args[1] && args[1] == "car1") then if ( IsValid( ply.Car ) ) then ply.Car:Remove() end DarkRP.notify(ply, 1, 4,"Your jeep has spawned! ".. Vehicles) local Car1 = ents.Create("prop_vehicle_jeep_old") Car1:SetModel("models/buggy.mdl") Car1:SetKeyValue("vehiclescript", "scripts/vehicles/jeep_test.txt") Car1:SetPos(Vector(59.891289, -964.276733, -112.143753)) Car1:SetAngles(Angle(0, 0, 0)) Car1:addKeysDoorOwner(ply) Car1:CPPISetOwner(ply) Car1:Spawn() Car1:Activate() ply.Car = Car1 end end concommand.Add("SpawnCar", SpawnCar)[/code]
Sorry, you need to Log In to post a reply to this thread.