Hello Guys
I hope you can me Help
I have Write a Carrent System
And that system is not works
Please Help me:
Error:
[ERROR] gamemodes/darkrp/gamemode/modules/doorsystem/sv_doorvars.lua:35: table index is nil
1. addKeysDoorTeam - gamemodes/darkrp/gamemode/modules/doorsystem/sv_doorvars.lua:35
2. func - addons/carspawn/lua/autorun/server/sv_carmenu.lua:609
3. unknown - lua/includes/extensions/net.lua:32
And my Codeline:
util.AddNetworkString("RentVehicle")
net.Receive("RentVehicle", function(len, ply)local ent = net.ReadEntity()
local accept = net.ReadBool()
if !(IsValid(ent) && ply:GetVehicle() == ent && !ent.nonVirgin) thenreturnendif (accept && ply:canAfford(cars[ent.vehicleIndex].rentPrice)) then
ply:addMoney(-cars[ent.vehicleIndex].rentPrice)
ent:removeAllKeysDoorTeams()
ent:removeAllKeysExtraOwners()
ent:setKeysNonOwnable(false)
--ent:addKeysDoorOwner(ply)
ent:addKeysDoorTeam(t)
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent.nonVirgin = trueelse
ply:ExitVehicle()
endend)
and here is my Function:
function addKeysDoorTeam(t)
local doorData = self:getDoorData()
doorData.teamOwn = doorData.teamOwn or {}
doorData.teamOwn[t] = true
DarkRP.updateDoorData(self, "teamOwn")
end
ent:addKeysDoorTeam(t) -- line 35?
I can't see where you defined "t" in your code.
"t" is undefined. Hence the error.
You could have googled this and I found this old thread just by googling the error.
https://forum.facepunch.com/f/gmoddev/njcd/Team-table-index-is-nil/1/
Sorry I did not answer
We have Christmas in Germany right now
So I tried that!
But it does not work ..
I then see the team on the vehicle until it respawns and then the name is Unowned again!
Here is my whole line of code I hope that I can help
local cars = {}
local function addVehicle(t)
table.insert(cars, t)
end
function getDoorData() if not self:isKeysOwnable() then return {} end
self.DoorData = self.DoorData or {}
return self.DoorData
end
function setKeysNonOwnable(ownable)
self:getDoorData().nonOwnable = ownable
DarkRP.updateDoorData(self, "nonOwnable")
end
function setKeysTitle(title)
self:getDoorData().title = title
DarkRP.updateDoorData(self, "title")
end
function setDoorGroup(group)
self:getDoorData().groupOwn = group
DarkRP.updateDoorData(self, "groupOwn")
end
function addKeysDoorTeam(t) local doorData = self:getDoorData()
doorData.teamOwn = doorData.teamOwn or {}
doorData.teamOwn[t] = true
DarkRP.updateDoorData(self, "teamOwn")
end
function removeKeysDoorTeam(t) local doorData = self:getDoorData()
doorData.teamOwn = doorData.teamOwn or {}
doorData.teamOwn[t] = nil
if fn.Null(doorData.teamOwn) then
doorData.teamOwn = nilend
DarkRP.updateDoorData(self, "teamOwn")
end
end
local vehicle = {}
vehicle.map = "rp_newexton2_v4h"
vehicle.pos = {Vector(-11806, 6715, 1080), Angle(33, -138, 0)}
vehicle.rentPrice = 500
vehicle.respawnTime = 50
vehicle.color = Color(0, 0, 0)
vehicle.model = "models/tdmcars/cooper65.mdl"
vehicle.skin = 1
vehicle.class = "cooper65tdm"
vehicle.allowed = {TEAM_CHIEF}
vehicle.bodygroups = "000000000000000"
addVehicle(vehicle)
local meta = FindMetaTable("Entity")
local pmeta = FindMetaTable("Player")
local function respawnVehicle(id)
local v = cars[id]
if !v then return end
local Vehicle = DarkRP.getAvailableVehicles()[v.class]
if !Vehicle then print("ERROR LOADING VEHICLE: "..v.class.." not found!") return end
local ent = ents.Create(Vehicle.Class)
ent:SetPos(v.pos[1])
ent:SetAngles(v.pos[2])
ent:SetModel(v.model or Vehicle.Model)
ent:SetSkin(v.skin or 0)
ent.vehicleRespawnTime = v.respawnTime
ent:SetColor(v.color or Color(255, 255, 255, 255))
if Vehicle.KeyValues then
for k, v in pairs(Vehicle.KeyValues) do
ent:SetKeyValue(k, v)
end
end
ent.VehicleTable = Vehicle
if Vehicle.Members then
table.Merge(ent, Vehicle.Members)
end
ent.vehicleIndex = id
ent:Spawn()
ent:Activate()
if v.bodygroups then
ent:SetBodyGroups(v.bodygroups)
end
ent.ClassOverride = Vehicle.Class
ent:SetMoveType(MOVETYPE_NONE)
if v.allowed then
for _, t in pairs(v.allowed) do
ent:addKeysDoorTeam(t)
end
ent:keysLock()
else
ent:setKeysNonOwnable(true)
end
return ent
end
function isEmtpy(ent, ply)
if ent.VC_Script && ent.VC_SeatTable then
for k, v in pairs(ent.VC_SeatTable) do
if IsValid(v:GetDriver()) && v:GetDriver() != ply then
return false
end
end
end
return true
end
hook.Add("InitPostEntity", "SpawnCars", function()
for k, v in pairs(cars) do
if string.lower(v.map) != string.lower(game.GetMap()) then continue end
respawnVehicle(k)
end
end)
util.AddNetworkString("RentVehicle")
net.Receive("RentVehicle", function(len, ply)
local ent = net.ReadEntity()
local accept = net.ReadBool()
if !(IsValid(ent) && ply:GetVehicle() == ent && !ent.nonVirgin) then return end
if (accept && ply:canAfford(cars[ent.vehicleIndex].rentPrice)) then
ply:addMoney(-cars[ent.vehicleIndex].rentPrice)
ent:removeAllKeysDoorTeams()
ent:setKeysNonOwnable(false)
ent:addKeysDoorOwner(ply)
ent:getKeysDoorTeams()
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent.nonVirgin = true
else
ply:ExitVehicle()
end
end)
the Editor here is Fail:
I have that here on Pastebin
[Lua] Nato
I don't see any errors on the code but I believe you're not really setting the vehicle key groups in a correct way (you're missing steps)
Look at how DarkRP sets teams on vehicles/doors
So you see no error in the code ..
That means I did it!
However, I hope you can help me out
@Geferon
What can i Change
net.Receive("RentVehicle", function(len, ply)
local ent = net.ReadEntity()
local accept = net.ReadBool()
if !(IsValid(ent) && ply:GetVehicle() == ent && !ent.nonVirgin) then return end
if (accept && ply:canAfford(cars[ent.vehicleIndex].rentPrice)) then
ply:addMoney(-cars[ent.vehicleIndex].rentPrice)
ent:removeAllKeysDoorTeams()
ent:setKeysNonOwnable(false)
ent:addKeysDoorOwner(ply)
ent:getKeysDoorTeams()
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent.nonVirgin = true
else
ply:ExitVehicle()
end
end)
I just basically sent you the answer on my other post
Imma paste it here again in case you didn't notice it
Replicate this: DarkRP/sv_doors.lua at master · FPtje/DarkRP · GitHub
It's how DarkRP sets door teams, and you're missing quite a lot of it
No look my Complete Code!!
I have Set up this
local cars = {}
local function addVehicle(t)
table.insert(cars, t)
end
function getDoorData() if not self:isKeysOwnable() then return {} end
self.DoorData = self.DoorData or {}
return self.DoorData
end
function setKeysNonOwnable(ownable)
self:getDoorData().nonOwnable = ownable
DarkRP.updateDoorData(self, "nonOwnable")
end
function setKeysTitle(title)
self:getDoorData().title = title
DarkRP.updateDoorData(self, "title")
end
function setDoorGroup(group)
self:getDoorData().groupOwn = group
DarkRP.updateDoorData(self, "groupOwn")
end
function addKeysDoorTeam(t) local doorData = self:getDoorData()
doorData.teamOwn = doorData.teamOwn or {}
doorData.teamOwn[t] = true
DarkRP.updateDoorData(self, "teamOwn")
end
function removeKeysDoorTeam(t) local doorData = self:getDoorData()
doorData.teamOwn = doorData.teamOwn or {}
doorData.teamOwn[t] = nil
if fn.Null(doorData.teamOwn) then
doorData.teamOwn = nilend
DarkRP.updateDoorData(self, "teamOwn")
end
end
-- Vector(-6669.08203125, -7543.8583984375, 64.03125),
--Angle(0, 3.2482359409332, 0),
local vehicle = {}
vehicle.map = "rp_newexton2_v4h"
vehicle.pos = {Vector(-11806, 6715, 1080), Angle(33, -138, 0)}
vehicle.rentPrice = 500
vehicle.respawnTime = 50
vehicle.color = Color(0, 0, 0)
vehicle.model = "models/tdmcars/cooper65.mdl"
vehicle.skin = 1
vehicle.class = "cooper65tdm"
vehicle.allowed = {TEAM_CHIEF}
vehicle.bodygroups = "000000000000000"
addVehicle(vehicle)
local meta = FindMetaTable("Entity")
local pmeta = FindMetaTable("Player")
local function respawnVehicle(id)
local v = cars[id]
if !v then return end
local Vehicle = DarkRP.getAvailableVehicles()[v.class]
if !Vehicle then print("ERROR LOADING VEHICLE: "..v.class.." not found!") return end
local ent = ents.Create(Vehicle.Class)
ent:SetPos(v.pos[1])
ent:SetAngles(v.pos[2])
ent:SetModel(v.model or Vehicle.Model)
ent:SetSkin(v.skin or 0)
ent.vehicleRespawnTime = v.respawnTime
ent:SetColor(v.color or Color(255, 255, 255, 255))
if Vehicle.KeyValues then
for k, v in pairs(Vehicle.KeyValues) do
ent:SetKeyValue(k, v)
end
end
ent.VehicleTable = Vehicle
if Vehicle.Members then
table.Merge(ent, Vehicle.Members)
end
ent.vehicleIndex = id
ent:Spawn()
ent:Activate()
if v.bodygroups then
ent:SetBodyGroups(v.bodygroups)
end
ent.ClassOverride = Vehicle.Class
ent:SetMoveType(MOVETYPE_NONE)
if v.allowed then
for _, t in pairs(v.allowed) do
ent:addKeysDoorTeam(t)
end
ent:keysLock()
else
ent:setKeysNonOwnable(true)
end
return ent
end
function isEmtpy(ent, ply)
if ent.VC_Script && ent.VC_SeatTable then
for k, v in pairs(ent.VC_SeatTable) do
if IsValid(v:GetDriver()) && v:GetDriver() != ply then
return false
end
end
end
return true
end
hook.Add("InitPostEntity", "SpawnCars", function()
for k, v in pairs(cars) do
if string.lower(v.map) != string.lower(game.GetMap()) then continue end
respawnVehicle(k)
end
end)
util.AddNetworkString("RentVehicle")
net.Receive("RentVehicle", function(len, ply)
local ent = net.ReadEntity()
local accept = net.ReadBool()
if !(IsValid(ent) && ply:GetVehicle() == ent && !ent.nonVirgin) then return end
if (accept && ply:canAfford(cars[ent.vehicleIndex].rentPrice)) then
ply:addMoney(-cars[ent.vehicleIndex].rentPrice)
ent:removeAllKeysDoorTeams()
ent:setKeysNonOwnable(false)
ent:addKeysDoorOwner(ply)
ent:getKeysDoorTeams()
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent.nonVirgin = true
else
ply:ExitVehicle()
end
end)
hook.Add("PlayerDisconnect", "VehiclePlayerDisconnect", function(ply)
for k, v in pairs(ents.GetAll()) do
if v:IsVehicle() && v.vehicleIndex && v.vehicleRespawnTime && v:getDoorOwner() == ply then
v:Remove()
respawnVehicle(v.vehicleIndex)
end
end
end)
--hook.Add("playerSellVehicle", "vehicleDisallowSellVehicle", function(ply, ent)
--return !(ent.vehicleIndex && ent.vehicleRespawnTime), VLANGUAGE_CANT_SELL
--end)
hook.Add("PlayerEnteredVehicle", "CarsRemoveTimer", function(ply, ent, role)
if ent.vehicleIndex && ent.vehicleRespawnTime then
if !ent.nonVirgin then
if cars[ent.vehicleIndex].rentPrice != 0 then
net.Start("RentVehicle")
net.WriteEntity(ent)
net.WriteFloat(cars[ent.vehicleIndex].rentPrice)
net.Send(ply)
else
ent.nonVirgin = true
ent:SetMoveType(MOVETYPE_VPHYSICS)
end
else
timer.Remove("RemoveVehicle"..ent:EntIndex())
end
end
end)
hook.Add("EntityTakeDamage", "CarsEntityRemove", function(ent, dmg)
if ent:IsVehicle() && !ent.nonVirgin then
dmg:ScaleDamage(0)
end
end)
hook.Add("PlayerLeaveVehicle", "CarsRemoveTimer", function(ply, ent, role)
if IsValid(ent.VC_Parent) then ent = ent.VC_Parent end
if ent.vehicleIndex && ent.vehicleRespawnTime && isEmtpy(ent, ply) then
local i = ent.vehicleIndex
timer.Create("RemoveVehicle"..ent:EntIndex(), ent.vehicleRespawnTime, 1, function()
respawnVehicle(i)
SafeRemoveEntity(ent)
end)
end
end)
hook.Add("EntityRemoved", "CarsEntityRemove", function(ent)
if ent:IsVehicle() && ent.vehicleIndex && ent.vehicleRespawnTime && !ent.nonVirgin then
timer.Simple(5, function()
respawnVehicle(ent.vehicleIndex)
end)
end
end)
You're not reading what i'm saying.
First off, your code isn't exactly wrong but at the beginning you have some functions which shouldn't be there as they're from DarkRP, those functions are: getDoorData, setKeysNonOwnable, setKeysTitle, setDoorGroup, addKeysDoorTeam and removeKeysDoorTeam.
Then, as I said 2 times, when setting the teams of a door/vehicle, you're NOT doing what DarkRP does to set the team, what it does is here, but in case you don't understand this, i'm going to give you an example of what you're missing:
ent:setDoorGroup(nil)
DarkRP.storeDoorGroup(ent, nil)
ent:addKeysDoorTeam(team) -- Team goes here
DarkRP.storeTeamDoorOwnability(ent)
ent:keysUnOwn()
Which, you should add on your respawnVehicle function, where you check if v.allowed exists and add the teams from the table.
I am sorry
I've been trying for over 3 hours now
Seats for 1 week already ..
Whenever I get it that's only for Chiefs .. And then the vehicle respawns! is it again for everyone?
I do not know
I'll 1x that if I make this vehicle. Allow = TEAM_CHIEF enter that there only the police in
and I will when I enter vehicle.allowed = nil this anyone can buy
maybe it's a bit harder for me at the beginning .. I do not know either
I have been doing scripts for almost 4 weeks
@Geferon Sry that I have disappointed you
Okay now we're getting somewhere.
If you want to establish a person owner, you should do addKeysDoorOwner(ply), as you did, but not addKeysDoorTeam as that is for teams only, plus the t you're trying to use as a parameter isn't even defined in that context, it doesn't exist.
Then, keysUnOwn ONLY takes as a parameter a player, or being empty according to the DarkRP official wiki, so you shouldn't be calling it like ent:keysUnOwn(false), but like ent:keysUnOwn()
Ok wait!
@Geferon
When i Understand your Text!
I use that on Lines 9-21
local vehicle = {}
vehicle.map = "rp_newexton2_v4h"
vehicle.pos = {Vector(-12249, 6924, 1014), Angle( 0, -55, -0)}
vehicle.rentPrice = 10
vehicle.respawnTime = 120
vehicle.color = Color(0, 0, 0)
vehicle.model = "models/tdmcars/mini_clubman.mdl"
vehicle.skin = 0
vehicle.class = "clubmantdm"
vehicle.allowed = {TEAM_POLICE}
vehicle.bodygroups = "000000000000000"
addVehicle(vehicle)
and i know vehicle.allowed = Allow my Team Jobs that car!
Right?
And I would like to
allowed = t use by that I also mean for teams!
But only certain vehicles!
The other vehicles that I do not use with me should be purchasable
so also write i so
util.AddNetworkString("RentVehicle")
net.Receive("RentVehicle", function(len, ply)
local ent = net.ReadEntity()
local accept = net.ReadBool()
if !(IsValid(ent) && ply:GetVehicle() == ent && !ent.nonVirgin) then return end
if (accept && ply:canAfford(cars[ent.vehicleIndex].rentPrice)) then
ply:addMoney(-cars[ent.vehicleIndex].rentPrice)
ent:removeAllKeysDoorTeams()
ent:setKeysNonOwnable(true)
ent:addKeysDoorOwner(ply) // for Players
ent:addKeysDoorTeam() // for teams
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent.nonVirgin = true
else
ply:ExitVehicle()
endend)
So and that Vehicle is so
http://prntscr.com/lzfgp7
when my car is respawn is that so
http://prntscr.com/lzfh9v
I can not get it, the team is permanently there
Ok i hope so is works and Fine
@Geferon
local function respawnVehicle(id)
local v = cars[id]
if !v then return end
local Vehicle = DarkRP.getAvailableVehicles()[v.class]
if !Vehicle then print("ERROR LOADING VEHICLE: "..v.class.." not found!") return end
local ent = ents.Create(Vehicle.Class)
ent:SetPos(v.pos[1])
ent:SetAngles(v.pos[2])
ent:SetModel(v.model or Vehicle.Model)
ent:SetSkin(v.skin or 0)
ent.vehicleRespawnTime = v.respawnTime
ent:SetColor(v.color or Color(255, 255, 255, 255))
if Vehicle.KeyValues then
for k, v in pairs(Vehicle.KeyValues) do
ent:SetKeyValue(k, v)
end
end
ent.VehicleTable = Vehicle
if Vehicle.Members then
table.Merge(ent, Vehicle.Members)
end
ent.vehicleIndex = id
ent:Spawn()
ent:Activate()
if v.bodygroups then
ent:SetBodyGroups(v.bodygroups)
end
ent.ClassOverride = Vehicle.Class
ent:SetMoveType(MOVETYPE_NONE)
if type(v.allowed) == "table" and not table.HasValue(v.allowed, team.GetName()) then
for _, t in pairs(v.allowed) do
ent:addKeysDoorTeam(t)
end
DarkRP.notify(ply, 1, 4, string.format("Team Incorrect"))
ent:keysLock()
else
ent:setKeysNonOwnable(true)
DarkRP.notify(ply, 1, 4, string.format("Team Incorrect"))
end
return ent
end
I become not errors
and when the Vehicle is Respawned.. I become Unnowned
Sorry, you need to Log In to post a reply to this thread.