Jump to content

getPlayerName and destroyElement warning


Robis

Recommended Posts

Hello! Im newbie, so can anyone help me with these warnings?

Bad argument @ 'destroyElement' [Expected element at argument 1, got boolean]

and

Bad argument @ 'getPlayerName' [Expected element at argument 1, got boolean]

script:

triggerClientEvent ( "onRollMessageStart", getRootElement(),"#FFFFFF"..getPlayerName(source).." #FFFFFFwas killed by "..(getPlayerName(killer) or "unknown")..".",0,22,255, "died")
  destroyElement(getElementData(source, "playerCol"))

Dayz Gamemode! :)

Thanks!

Link to comment

Hey, the "destroyElement" destroys elements, and you're trying to destroy ElementData. Check this example taken from the wiki:

for i,v in ipairs(vehicles) do
	-- if the vehicle's ID is the one provided, destroy it
	if (getElementModel(v) == modelID) then
		destroyElement(v)
	end
end

In the above case the function "destroyElement" destroys the vehicle. It can also be used to destroy other elements but "ElementData" is not an element. If you want to remove it, you can use something like:

if getElementData(source, "playerCol") then
  setElementData(source, "playerCol", nil)
end

And about the getPlayerName, please post the full script so I can see what's wrong (killer can be undefined)

Edited by koragg
Link to comment

I don't think he is trying to destroy element data, I guess "playerCol" is some sort of a marker that's been stored in the element data. See the problem is, that we can't see where the "source" is coming from, can you also include the function that calls these 2 lines?

Link to comment

It's obvious that he's trying to destroy an element saved in the element data, also it's probably inside onPlayerWasted function (source, killer).

Problem is, getElementData(source, "playerCol") is not set.

You can get rid of these warnings using this (replace second line of your shown code with those lines):

local playerCol = getElementData(source, "playerCol")
if playerCol and isElement(playerCol) then
	destroyElement(playerCol)
end

But that doesn't change anything on fact, that you have to save your element to the element data first (using setElementData(thePlayer, "playerCol", YOUR_ELEMENT) on spawn or wherever you are creating "YOUR_ELEMENT").

EDIT: By the way koragg, easier way to remove element data is function named removeElementData.

Edited by Rataj
  • 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...