Jump to content

Problems with mapmanager resource


Recommended Posts

[EDIT] Problem solved.

Hey,

Can you tell me what's wrong with this?

[EDIT] This code below is outdated, changed code in follow-up posts

function loadMap(startedMap)
outputChatBox("SERVER: DEBUG: loadMap - called")
local mapRoot = getResourceRootElement(startedMap)
spawnpoints = getElementsByType("spawnpoint", mapRoot)
local markers = getElementsByType("marker", mapRoot)
local radarareas = getElementsByType("radararea", mapRoot)
for k,v in ipairs(markers) do
local marker = createMarker(getElementData(v, "posX"), getElementData(v, "posY"), getElementData(v, "posZ"))
setMarkerColor(marker, getElementData(v, "r"), getElementData(v, "g"), getElementData(v, "b"))
setElementData(marker, "id", getElementData(v, "id"))
outputChatBox("DEBUG: Marker created: " .. tostring(marker))
end
if spawnpoints then outputChatBox("spawnpoints loaded") else outputChatBox("spawnpoints aren't being loaded") end
for k, v in ipairs(spawnpoints) do
outputChatBox(getElementData(spawnpoint, "id"))
end
 
for k,v in ipairs(radarareas) do
	posX = getElementData(v, "posX")
	posY = getElementData(v, "posY")
	r = getElementData(v, "r")
	g = getElementData(v, "g")
	b = getElementData(v, "b")
local radararea = createRadarArea(posX - 20, posY - 20, 40, 40, r, g, b)
setElementData(radararea, "id", getElementData(v, "id"))
outputChatBox("DEBUG: Radararea created")
end
end
addEventHandler("onGamemodeMapStart", getRootElement(), loadMap)

and here's the map:

<map>
  <spawnpoint id="initspawn" posX="0" posY="0" posZ="3" rot="0" model="0"/>
  <marker id="cops" posX="50" posY="0" posZ="20" r="0" g="0" b="255" />
  <marker id="robbers" posX="-50" posY="0" posZ="20" r="255" g="0" b="0" />
  <radararea id="initspawn" posX"0" posY="0" r="200" g="200" b="0" />
</map>

It would appear that the tables inside the elements table are empty or something, because I'm not getting any errors, but I'm not seeing any elements being spawned either.

Thanks in advance.

P.S.

Oh and while you're at it, this isn't working either :?

function quitHandler(quitType)
local x, y, z = getElementPosition(source)
if x and y and z then
outputConsole(x .. y .. z)
executeSQLUpdate("accounts", "posX ='" .. x .. "', posY='" .. y .. "', posZ='" .. z .. "'")
local nick = getPlayerName(source)
outputChatBox("Player " .. nick .. "has left the game - " .. quitType .. ".")
end
end
addEventHandler("onPlayerQuit", getRootElement(), quitHandler)

Apparently executeSQLUpdate is getting an invalid argument, maybe x y z are boolean or something?

[EDIT] Boolean error is on line 62, in loginSpawn() not in the quit handler - my bad, should've been specific

Edited by Guest
Link to comment

Hey, thanks for the quick reply.

I'm getting "SERVER: DEBUG: loadMap - called"

and "spawnpoints loaded", which obviously isn't actually happening o.O

... because further in the program I do

function joinSpawn(ply)
outputChatBox("SERVER: DEBUG: joinSpawn - called")
local x = getElementData(ply, "lastX")
local y = getElementData(ply, "lastY")
local z = getElementData(ply, "lastZ")
if x and y and z then
outputChatBox("Welcome back!", ply)
fadeCamera(ply, true)
spawnPlayer(ply, x, y, z+1)
setCameraTarget(ply, ply)
else
outputChatBox("First time playing?", ply)
for k,v in pairs(spawnpoints) do
if getElementData(v, "id") == "initspawn" then
			loginpoint = v
end
outputChatBox(tostring(v))
end
local x = getElementData(loginpoint, "posX")
local y = getElementData(loginpoint, "posY")
local z = getElementData(loginpoint, "posZ")
fadeCamera(ply, true)
spawnPlayer(ply, math.random(x-20,x+20), math.random(y-20,y+20), z)
setCameraTarget(ply, ply)
end
end

and it says getElementData is being called with invalid arguments and also that I'm trying to run arithmetic on a boolean value x (in math.random)

[EDIT] Boolean error is on line 62, in loginSpawn() not in the quit handler - my bad, should've been specific

the only problem with the quithandler is "bad argument"

Edited by Guest
Link to comment

In the first script: Try replacing mapRoot with source. (which is the root element of the started map resource, in this case) I'm not sure if it'll work, but worth a try I guess.

In the second script: No, they can't be booleans. If they'd be booleans, you'd get an error at line 4. Your executeSQLUpdate is missing the last argument I think.

In your final script: I presume the function is triggered with onPlayerJoin? If it is, remove "ply" and replace it with "source".

Link to comment
In the first script: Try replacing mapRoot with source. (which is the root element of the started map resource, in this case) I'm not sure if it'll work, but worth a try I guess.

Done.

In the second script: No, they can't be booleans. If they'd be booleans, you'd get an error at line 4. Your executeSQLUpdate is missing the last argument I think.

I'm getting "ERROR: ...er/mods/deathmatch/resources/cnr/server/gamemode.lua:62 attempt to perform arithmetic on local 'x' (a boolean value)"

[EDIT - 15:11 UTC+2] The third argument is optional, but I just realized I DO need to have it.

Changed to: executeSQLUpdate("accounts", "posX ='" .. x .. "', posY='" .. y .. "', posZ='" .. z .. "'", "name='" .. getPlayerName(source) .. "'")

=> I still get "Bad argument @ 'executeSQLUpdate' - Line: 179"

In your final script: I presume the function is triggered with onPlayerJoin? If it is, remove "ply" and replace it with "source".

Well I was hoping not to post ALL of my gamemode in public like this, but meh..

The function joinSpawn() is being called by my custom event, called from a clientside GUI

addEvent("onGameJoin", true)
addEventHandler("onGameJoin", getRootElement(), joinSpawn)

clientside:

function onJoinButton()
outputChatBox("DEBUG: Join button pushed")
triggerServerEvent("onGameJoin", getLocalPlayer(), getLocalPlayer())
showCursor(false)
guiSetInputEnabled(false)
guiSetVisible(ControlPanel, false)
end

__________________________________________________________________

Final altered code (the parts relevant, anyway):

function loadMap(startedMap)
outputChatBox("SERVER: DEBUG: loadMap - called")
spawnpoints = getElementsByType("spawnpoint", source)
local markers = getElementsByType("marker", source)
local radarareas = getElementsByType("radararea", source)
--[[
	for k,v in ipairs(markers) do
		local marker = createMarker(getElementData(v, "posX"), getElementData(v, "posY"), getElementData(v, "posZ"))
		setMarkerColor(marker, getElementData(v, "r"), getElementData(v, "g"), getElementData(v, "b"))
		setElementData(marker, "id", getElementData(v, "id"))
		outputChatBox("DEBUG: Marker created: " .. tostring(marker))
	end
	--]]
if spawnpoints and spawnpoints ~= {} then outputChatBox("spawnpoints loaded") else outputChatBox("spawnpoints aren't being loaded") end
for k, v in pairs(spawnpoints) do
outputChatBox(getElementData(spawnpoint, "id"))
end
--[[
	for k,v in ipairs(radarareas) do
		posX = getElementData(v, "posX")
		posY = getElementData(v, "posY")
		r = getElementData(v, "r")
		g = getElementData(v, "g")
		b = getElementData(v, "b")
		local radararea = createRadarArea(posX - 20, posY - 20, 40, 40, r, g, b)
		setElementData(radararea, "id", getElementData(v, "id"))
		outputChatBox("DEBUG: Radararea created")
	end
	--]]
end
addEventHandler("onGamemodeMapStart", getRootElement(), loadMap)

(commented out some non-crucial stuff)

function joinSpawn(ply)
outputChatBox("SERVER: DEBUG: joinSpawn - called")
local x = getElementData(ply, "lastX")
local y = getElementData(ply, "lastY")
local z = getElementData(ply, "lastZ")
if x and y and z then
outputChatBox("Welcome back!", ply)
fadeCamera(ply, true)
spawnPlayer(ply, x, y, z+1)
setCameraTarget(ply, ply)
else
outputChatBox("First time playing, " .. getPlayerName(ply) .. "?", ply)
for k,v in pairs(spawnpoints) do
if getElementData(v, "id") == "initspawn" then
			loginpoint = v
end
outputChatBox(tostring(v))
end
local x = getElementData(loginpoint, "posX")
local y = getElementData(loginpoint, "posY")
local z = getElementData(loginpoint, "posZ")
fadeCamera(ply, true)
spawnPlayer(ply, math.random(x-20,x+20), math.random(y-20,y+20), z)
setCameraTarget(ply, ply)
end
end
addEvent("onGameJoin", true)
addEventHandler("onGameJoin", getRootElement(), joinSpawn)

(edited to "outputChatBox("First time playing, " .. getPlayerName(ply) .. "?", ply)" so I know ply exists, and it does)

ERRORS:

"WARNING: gamemode.lua: Bad argument @ 'getElementData' - Line : 58" ( = line 19 in this post, since I omitted parts of my code)

" < Same thing > - Line : 59"

" < Same thing > - Line : 60"

"ERROR: ...er/mods/deathmatch/resources/cnr/server/gamemode.lua:62: attempt to perform arithmetic on local 'x' (a boolean value)"

after I leave: "WARNING: gamemode.lua: Bad argument @ 'executeSQLUpdate' - Line: 179"

So basically, "local x = getElementData(loginpoint, "posX")" is getting a boolean value (false?) and my SQL query is somehow malformed. The SQL in it's current form:

executeSQLUpdate("accounts", "posX ='" .. x .. "', posY='" .. y .. "', posZ='" .. z .. "'", "name='" .. getPlayerName(source) .. "'")
... empty line to  get the horizontal scroll bar enabled
... (line numbers on/off is still broken)

Any ideas?

Thanks again

Link to comment

Anyone?

I must be misunderstanding the map system somehow, since I'm not getting the map data out of the file, or am I?

I can't figure out where I'm going wrong..

Any takers? thanks

[EDIT] outputChatBox(tostring(#spawnpoints)) prints out "0", so the table would appear to be empty, but why? o.O

[EDIT] Also did this:

mapRoot = getResourceRootElement(startedMap)
outputChatBox(tostring(mapRoot))

and it returns "userdata: 000000F3", so it's definately something, at least?

Link to comment

LMAO

Oh my god, lol, such a tiny mistake can make such a huge difference..

Laughed my ass off when I found it, it was in the .map file:

<map>
  <spawnpoint id="initspawn" posX="0" posY="0" posZ="3" rot="0" model="0"/>
  <marker id="cops" posX="50" posY="0" posZ="20" r="0" g="0" b="255" />
  <marker id="robbers" posX="-50" posY="0" posZ="20" r="255" g="0" b="0" />
  <radararea id="initspawn" posX"0" posY="0" r="200" g="200" b="0" />
</map>

fifth line, posX"0" xD

Thanks for the help, guys. :D

Mods may erase this thread for all I care.

[EDIT] Well there IS still that thing with my quithandler SQL thingy not working, but I'll figure that out...

[EDIT2] Yeah I fixed that too - apparently SQLite's datatypes differ a bit from MySQL (floatating point numbers are "REAL" etc.). Also changed "getPlayerName(source)" to correctly get the characters name, setting/getting metadata attached to the player. Thanks again for the input, people.

[ Go ahead and close this, if you want, mods ]

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...