Jump to content

ERROR : Server triggered clientside event setTheObjectUnbreakable, but event is not added clientside


JanKy

Recommended Posts

Hello, i get this error in my script. "ERROR : Server triggered clientside event setTheObjectUnbreakable, but event is not added clientside".

It is a base-building script and i have some objects which are by default breakable, so i added a function to make them unbreakable, which looks like this

function setTheObjectUnbreakable(object)
	setObjectBreakable(object,false)
end
addEvent("setTheObjectUnbreakable",true)
addEventHandler("setTheObjectUnbreakable",root,setTheObjectUnbreakable)

and then i use the event to the server sided script, when an object is created

function createBuildObject(coords,model,id,health)
	if not coords or #coords ~= 6 or not model or not objectsList[model] or not id or idToObjects[id] then return true end
	if objectsList[model] then
		idToObjects[id] = {}
		local col = createColSphere(coords[1],coords[2],coords[3],2)
		colshapeElements[col] = id
		setElementData ( col, "build:shape", true )
		setElementData ( col, "build:model", model )
		setElementData ( col, "build:id", id )
		setElementData ( col, "build:health", health or objectsList[model].damageTreshold or 0 )
		for i, v in ipairs (objectsList[model].objects) do
			local obj = createObject(v.model,coords[1]+v.offset[1],coords[2]+v.offset[2],coords[3]+v.offset[3],coords[4]+v.offset[4],coords[5]+v.offset[5],coords[6]+v.offset[6])
			triggerClientEvent("setTheObjectUnbreakable",root,obj) -- Here it is
			setElementData ( obj, "build:model", model )
			setElementData ( obj, "build:id", id )
			setElementData ( obj, "build:num", i )
			setElementData ( obj, "build:object", true )
			setElementData ( obj, "build:parent", col )
			if v.scale then
				setObjectScale(obj,v.scale)
			end
			objectsElements[obj] = id
			table.insert(idToObjects[id],obj)
		end	
		return col
	end
end

Everything works fine, the objects are unbreakable.. until i restart the resource and i get that error.

The only part of the script which calls the createBuildObject function ( besides of course when the player starts building, but i am certain that has nothing to do with this ) is when the resource starts, the script loads the buildings from the database, and that makes sense, but i dont know why this is happening.

Here is that part of the script


	db = dbConnect("sqlite", "database.db")
	dbExec(db, "CREATE TABLE IF NOT EXISTS ObjectsList (ID INTEGER, model INTEGER, X REAL, Y REAL, Z REAL, RotX REAL, RotY REAL, RotZ REAL, inter INTEGER, dim INTEGER, additInfo1 TEXT, additInfo2 TEXT, additInfo3 TEXT, health INTEGER)")
	local data = dbPoll(dbQuery(db, "SELECT * FROM ObjectsList"), -1)
	for i, v in ipairs ( data ) do
		local col = createBuildObject({v.X,v.Y,v.Z,v.RotX,v.RotY,v.RotZ},v.model,v.ID,v.health) -- Here

 

 

Thank you in advance ^^

Link to comment

i recommend you to use this instead of executing on each client:

addEventHandler("onClientObjectDamage",root,function()
	if getElementData(source,"object:unbreakable") == true then
		cancelEvent()
	end
end)

And of course you should add this server-side

setElementData(obj,"object:unbreakable",true) -- obj - your object variable

or this client-side

setElementData(obj,"object:unbreakable",true,true) -- obj - your object variable. Last argument allows to read this information server-side

to make it everything work.

Anyway let's analize your problem.

The most common problem - you put server-side script above client-side script in meta.xml.

Another problem - you have another errors in client-side script, so you can't use it.

@JanKy

  • Thanks 1
Link to comment

Oh dude. Yes, that solved my problem, but i spent 5 minutes trying to notice what was i doing wrong because the debug script showed me this error "unexpected symbol near ' ", and it was pointing me to this line 

end)

And when i was replying to you i noticed that you inserted ( by mistake i may guess ) a weird invisible character.

Spoiler

9blbsSK.png?1

Anyway, thank you for your kind help ^^ Have a nice day

  • Like 1
Link to comment
9 minutes ago, JanKy said:

And when i was replying to you i noticed that you inserted ( by mistake i may guess ) a weird invisible character.

yeah, i've recently discovered that thing too. It appeares sometimes for no reason.

 

10 minutes ago, JanKy said:

Anyway, thank you for your kind help ^^ Have a nice day

Any time mate :BIG:

  • Like 1
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...