Hey, I'm having a bit of trouble here. I'm trying to spawn my entities through a loop table, but it shows this even. And I'm completely lost at what I'm supposed to do. I have an idea of what it might be, but if it is. Then FML lol
ps. All help is appreciated!
// Long way, complicated, but works i guess
local EntitiesToLoad = {}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
// Setup Car Menu, Parking Pad, and Display Menu in SPAWN AREA
EntitiesToLoad[1] = { ent = "ent_cardisplay", Position = Vector(1902.757080, -4302.500488, -417.600372), Angle = Angle( 0, -90, 0 ) }
EntitiesToLoad[2] = { ent = "ent_carpad", Position = Vector(2021.114258, -4042.938721, -487.297058), Angle = Angle( 0, 133, 0 ) }
EntitiesToLoad[3] = { ent = "ent_parkingpad", Position = Vector(1788.661255, -3933.751709, -502.968750), Angle = Angle( 0, 357, 0 ) }
EntitiesToLoad[4] = { ent = "ent_parkingpad", Position = Vector(2516.215088, -2963.837891, -502.968750), Angle = Angle( 0, 90, 0 ) }
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
EntitiesToLoad[5] = { ent = "hobo_dumpsters", Position = Vector(1928.519775, -4678.809570, -470.457977), Angle = Angle( 0, 180, 0 ) }
EntitiesToLoad[6] = { ent = "hobo_dumpsters", Position = Vector(-802.875061, -4513.098145, -466.446930), Angle = Angle( 0, 45, 0 ) }
EntitiesToLoad[7] = { ent = "hobo_dumpsters", Position = Vector(1191.986938, -1476.089233, -477.632568), Angle = Angle( 0, 0, 0 ) }
EntitiesToLoad[8] = { ent = "hobo_dumpsters", Position = Vector(-660.850830, -198.374359, -466.347748), Angle = Angle( 0, 0, 0 ) }
EntitiesToLoad[9] = { ent = "hobo_dumpsters", Position = Vector(-3357.808838, -2961.264648, -470.298615), Angle = Angle( 0, 60, 0 ) }
EntitiesToLoad[10] = { ent = "hobo_dumpsters", Position = Vector(-3445.499756, -2947.715576, -470.414734), Angle = Angle( 0, 95, 0 ) }
EntitiesToLoad[11] = { ent = "hobo_dumpsters", Position = Vector(-1813.603882, -1454.204590, -478.376709), Angle = Angle( 0, -180, 0 ) }
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
EntitiesToLoad[12] = { ent = "farmingmod_shop", Position = Vector(1367.574463, -2127.023926, -498.842255), Angle = Angle( 0, 270, 0 ) }
EntitiesToLoad[13] = { ent = "itemstore_bank", Position = Vector(1939.119629, -3110.618652, -468.530548), Angle = Angle( 0, 90, 0 ) }
EntitiesToLoad[14] = { ent = "pd_npcshop", Position = Vector(575.363586, -3281.065430, -446.357361), Angle = Angle( 0, 0, 0 ) }
EntitiesToLoad[15] = { ent = "rp_bailmachine", Position = Vector(682.042419, -3493.524658, -419.425812), Angle = Angle( 0, 90, 0 ) }
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
local function LoadAllEntities()
local SpawnedButton
for k, v in pairs(EntitiesToLoad) do
SpawnedButton = ents.Create( v.ent )
//if !IsValid( SpawnedButton ) then continue end // Check whether we successfully made an entity, if not - bail
SpawnedButton:SetPos( v.Position )
SpawnedButton:SetAngles( v.Angle )
SpawnedButton:Spawn()
SpawnedButton:Activate()
local phys = SpawnedButton:GetPhysicsObject()
if phys and phys:IsValid() then
phys:EnableMotion(false)
end
end
end
local function LoadAllEntities()
local SpawnedButton
for k, v in pairs(EntitiesToLoad) do
SpawnedButton = ents.Create( v.ent )
//if !IsValid( SpawnedButton ) then continue end // Check whether we successfully made an entity, if not - bail
SpawnedButton:SetPos( v.Position )
SpawnedButton:SetAngles( v.Angle )
SpawnedButton:Spawn()
SpawnedButton:Activate()
local phys = SpawnedButton:GetPhysicsObject()
if phys and phys:IsValid() then
phys:EnableMotion(false)
end
end
end
When do you call this? Also should be:
local function LoadAllEntities()
for k, v in ipairs(EntitiesToLoad) do
local SpawnedButton = ents.Create(v.ent)
SpawnedButton:SetPos(v.Position)
SpawnedButton:SetAngles(v.Angle)
SpawnedButton:Spawn()
SpawnedButton:Activate()
local phys = SpawnedButton:GetPhysicsObject()
if phys and phys:IsValid() then
phys:EnableMotion(false)
end
end
end
This way is better, but I don't even think I should be setting the variable inside the function when I should be making the variable i outside the function then assigning it for each loop.. Anyway back on track,
I'm calling it via InitPostEntity. It's currently placed inside my darkrp_modules folder. While I'm in-game, I'm testing again using a timer.simple ( considering everyone's already loaded on the map ) and it continues to gives the same error. #RipMe #Help
but I don't even think I should be setting the variable inside the
function when I should be making the variable i outside the function
then assigning it for each loop
no, do my way.
and it continues to gives the same error
would help a lot if you tell us what the error is.
I'm not going to be doing it that way, it's slower to make a new local variable for each loop. This is lua, not C++.
I care deeply about performance and would do anything to get the best performance, even if the results are very little.
Anyway, back on TRACK.
sv_devtest_jsons.lua was something else. :b This script was supposed to be for something else, but I ended up just making an Entity Spawning script that I'm getting an error out of.
[ERROR] gamemodes/darkrp/gamemode/modules/workarounds/sh_workarounds.lua:129: attempt to call field 'GetEdictCount' (a nil value)
1. Create - gamemodes/darkrp/gamemode/modules/workarounds/sh_workarounds.lua:129
2. LoadAllEntities - addons/rp_modification/lua/darkrp_modules/rp_json_stuff/sv_devetest_jsons.lua:43
3. unknown - addons/rp_modification/lua/darkrp_modules/rp_json_stuff/sv_devetest_jsons.lua:57
Make sure your server is updated to the latest version - ents.GetEdictCount was added a fee updates ago.
Turns out you're right. :O I misread something online. I went to go re-read after what you said. I wish the guy above told me "why" I should be doing what he suggests. ;-; Would've helped instead of my cockiness fighting back. Also, My server is up to date. I'm running on Retributionv2, it was working at some point but I think I edited it at some random time and it just broke on me ever since. The error line points to ents.Create( v.Name )
Is there a chance I'm not getting the entity string from the table for ents.Create correctly?
The problem is you're calling ents.Create client-side; the incorrect error came from this.
I'm not calling it client side. Also, my problem was solved. Pretty funny though what the issue was. I forgot to remove an entity that doesn't exist in my Server anymore. Lol I didn't even notice it was still there even though there's only 13 indexs. ;-; Rip me.
ps. Should ask if I was running client-side before saying I'm running it via Client Side. :P :P
You're right; looking at the operation order now, I see that couldn't have been the case. Regardless, the error you posted above means ents.GetEdictCount doesn't exist on your server for some reason.
Sorry, you need to Log In to post a reply to this thread.