Jump to content

Help needed with spawnpoints.


x86

Recommended Posts

Hi guys,

I wan't a .map spawnpoints script, but i have a error in my script.

This is the .map source:

<map>
<!-- San Fiero -->
<spawn airport="1" type="Plane" x="-1672.7258300781" y="-181.81211853027" z="14.064621925354" rotX="0" rotY="0" rotZ="315" />
<spawn airport="1" type="Plane" x="-1652.4603271484" y="-344.59637451172" z="14.06379699707" rotX="0" rotY="0" rotZ="7" />
<spawn airport="1" type="Plane" x="-1336.7585449219" y="-249.60957336426" z="14.853824615479" rotX="0" rotY="0" rotZ="-3" />
 
....(more and more)
</map>

This is my lua script:

local spawn = {}
function preloadXmlSpawns()
for _, value in ipairs(getElementsByType("spawn")) do
-- outputServerLog(tostring(name).."=>"..tostring(value)) -- Debug, results: int, userdata
local airport = getElementData(value, "airport")
local airplane = getElementData(value, "type")
 
if airport ~= nil or airplane ~= nil then
if not spawn[airplane] then spawn[airplane] = {} end
if not spawn[airplane][airport] then spawn[airplane][airport] = {} end
if not spawn[airplane][0] then spawn[airplane][airport][0] = {} end
 
			spawn[airplane][airport][#spawn[airplane][airport]+1] =
{
				x=getElementData(value, "x"),
				y=getElementData(value, "y"),
				z=getElementData(value, "z"),
				rotX=getElementData(value, "rotX"),
				rotY=getElementData(value, "rotY"),
				rotZ=getElementData(value, "rotZ")
}
end
 
end
end
 
-- Spawn script:
function spawnPilotFull(player, vehicleid, mode, airport) -- userdata, id, string, string
if player == nil then return end
local theType = getVehicleType(vehicleid) -- Plane
local data = spawn[theType][airport][math.random(1, #spawn[theType][airport])] -- << Error "?" nil value, what evah
outputServerLog(tostring(data))
	plane = createVehicle(vehicleid, data.x, data.y, data.z, data.rotX, data.rotY, data.rotZ)
end

Thank you.

Link to comment

Debug spawnPilotFull function to see what spawn[ theType ][ airport ] is.

BTW, line 11, tables start with 1 not 0. Of course you can make assign values to 0 but it will not be detected by ipairs(), pairs() and #.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...