Jump to content

Bad argument @ 'getElementData' e 'setVehicleLocked'


Recommended Posts

Velocimetro\speedo_S.lua:97: Bad argument @ 'getElementData' [Expected element at argument 1]

Velocimetro\speedo_S.lua:104: Bad argument @ 'setVehicleLocked' [Expected element at argument 1]


function initCarLocks ()
	local players = getElementsByType ( "player" )
	for k,p in ipairs(players) do
		removeElementData ( p, "cl_ownedvehicle" )
		bindKey ( p, "l", "down", doToggleLocked )
	end
	local vehicles = getElementsByType ( "vehicle" )
	for k,v in ipairs(vehicles) do
		removeElementData ( v, "cl_vehicleowner" )
		removeElementData ( v, "cl_vehiclelocked" )
		removeElementData ( v, "cl_enginestate" )
		setVehicleLocked ( v, false )
		setVehicleOverrideLights ( v, 0 )
	end
end
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), initCarLocks )
addEventHandler ( "onResourceStop", getResourceRootElement ( getThisResource () ), initCarLocks )

function cl_PlayerJoin ( )
bindKey ( source, "l", "down", doToggleLocked )
bindKey ( source, "k", "down", switchEngine )

end
addEventHandler ( "onPlayerJoin", getRootElement(), cl_PlayerJoin )

function cl_PlayerQuit ( )
	local ownedVehicle = getElementData ( source, "cl_ownedvehicle" )
	if (ownedVehicle ~= false) then
		cl_RemoveVehicleOwner ( ownedVehicle )
	end
end
addEventHandler ( "onPlayerQuit", getRootElement(), cl_PlayerQuit )

function cl_PlayerWasted ( )
	local ownedVehicle = getElementData ( source, "cl_ownedvehicle" )
	if (ownedVehicle ~= false) then
		cl_RemoveVehicleOwner ( ownedVehicle )
	end
end
addEventHandler ( "onPlayerWasted", getRootElement(), cl_PlayerWasted )

function cl_VehicleStartEnter ( enteringPlayer, seat, jacked )
	local theVehicle = source
	local theOwner
	if ( getElementData ( theVehicle, "cl_vehiclelocked" ) == true ) then
		theOwner = getElementData ( theVehicle, "cl_vehicleowner" )
		if theOwner ~= false and theOwner ~= enteringPlayer then
		end
	 end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), cl_VehicleStartEnter )

function cl_PlayerDriveVehicle ( player, seat, jacked )
	if ( seat == 0 ) then
		oldVehicle = getElementData ( player, "cl_ownedvehicle" )
		if ( (cl_VehicleLocked(source) == true) and (cl_VehicleOwner(source) ~= player) ) then
			removePlayerFromVehicle( player )
			Err_Msg("este veículo está trancado.", player)
			return false
		end
		cl_SetVehicleOwner ( source, player )
	end
	return true
end
addEventHandler ( "onVehicleEnter", getRootElement(), cl_PlayerDriveVehicle )

function cl_VehicleRespawn ( exploded ) 
	cl_RemoveVehicleOwner ( source )
end
addEventHandler ( "OnVehicleRespawn", getRootElement(), cl_VehicleRespawn )

function cl_VehicleExplode ( )
	local theOwner = getElementData ( source, "cl_vehicleowner" )
	if ( theOwner ~= false ) then
		cl_RemoveVehicleOwner ( source )
	end
end
addEventHandler ( "onVehicleExplode", getRootElement(), cl_VehicleExplode )

function cl_SetVehicleOwner ( theVehicle, thePlayer )
	local oldVehicle = getElementData ( thePlayer, "cl_ownedvehicle" )
	if ( oldVehicle ~= false ) then	
		removeElementData ( oldVehicle, "cl_vehicleowner" )
		removeElementData ( oldVehicle, "cl_vehiclelocked" )
		removeElementData ( oldVehicle, "cl_enginestate" )
		setVehicleLocked ( oldVehicle, false ) 
	end
	setElementData ( theVehicle, "cl_vehicleowner", thePlayer )
	setElementData ( theVehicle, "cl_vehiclelocked", false )
	setElementData ( thePlayer, "cl_ownedvehicle", theVehicle )
	setElementData( theVehicle, "cl_enginestate", true )

end

function cl_RemoveVehicleOwner ( theVehicle )
	local theOwner = getElementData ( theVehicle, "cl_vehicleowner" )
	if ( theOwner ~= false ) then
		removeElementData ( theOwner, "cl_ownedvehicle" )
		removeElementData ( theVehicle, "cl_vehicleowner" )
		removeElementData ( theVehicle, "cl_vehiclelocked" )
		removeElementData ( owned, "cl_enginestate" )
	end
	setVehicleLocked ( theVehicle, false )

end

function cl_FlashLights ( thePlayer )
	setTimer ( doToggleLights, 300, 4, thePlayer, true )
end

function cl_FlashOnce ( thePlayer )
	setTimer ( doToggleLights, 300, 2, thePlayer, true )
end

function cl_VehicleOwner ( theVehicle )
	return getElementData( theVehicle, "cl_vehicleowner" )

end

function cl_VehicleLocked ( theVehicle )
	return getElementData( theVehicle, "cl_vehiclelocked" )
end

function Err_Msg ( strout, thePlayer )
	outputChatBox ( strout, thePlayer, 200, 0, 10 )
end

function Car_Msg ( strout, theVehicle )
	numseats = getVehicleMaxPassengers ( theVehicle )
	for s = 0, numseats do
		local targetPlayer = getVehicleOccupant ( theVehicle, s )
		if targetPlayer ~= false then
			outputChatBox ( strout, targetPlayer, 30, 144, 255 )
		end
	end
end

function Info_Msg ( strout, thePlayer )
	outputChatBox ( strout, thePlayer, 102, 205, 170 )
end

function doToggleLocked ( source )
	local theVehicle , strout
	if ( getElementType(source) == "vehicle" ) then
		theVehicle = source
	end
	if ( getElementType(source) == "player" ) then
		theVehicle = getElementData ( source, "cl_ownedvehicle" )
	end

	if ( theVehicle ) then
		local vehiclename = getVehicleName ( theVehicle )
		if ( getElementData ( theVehicle, "cl_vehiclelocked") == true ) then
			doUnlockVehicle ( source )
		else 
			doLockVehicle ( source )
		end
	else
		Err_Msg("Erro !!!! Volte a andar", source)
	end
end	

function doLockVehicle ( source )
	local theVehicle , strout
	if ( getElementType(source) == "vehicle" ) then
		theVehicle = source
	end
	if ( getElementType(source) == "player" ) then
		theVehicle = getElementData ( source, "cl_ownedvehicle" )
	end

	if ( theVehicle ) then
		local vehiclename = getVehicleName ( theVehicle )
		if ( getElementData ( theVehicle, "cl_vehiclelocked") == true ) then
			strout = "Aracın " .. vehiclename .. " Kiliti Acıldı" 
			Err_Msg(strout, source)
		else 
			setElementData ( theVehicle, "cl_vehiclelocked", true)
			setVehicleLocked ( theVehicle, true ) 
			Car_Msg( "Suanki Arac " .. vehiclename .. " İyi Oyunlar", theVehicle)
			Info_Msg ( "Suanki Arac " .. vehiclename .. " Aracınız Kitlendi", source )
			if ( getVehicleController ( theVehicle ) == false ) then
				cl_FlashLights ( source )
			end
		end
	else
		Err_Msg("3", source)
	end
end

function doUnlockVehicle ( source )
	local theVehicle, strout
	if ( getElementType(source) == "vehicle" ) then
		theVehicle = source
	end
	if ( getElementType(source) == "player" ) then
		theVehicle = getElementData ( source, "cl_ownedvehicle" )
	end
	if ( theVehicle ) then
	local vehiclename = getVehicleName ( theVehicle )
		if ( getElementData ( theVehicle, "cl_vehiclelocked") == false ) then
			strout = "Arac " .. vehiclename .. " Arac Calinabilir"
			Err_Msg(strout, source)
		else
			setElementData ( theVehicle, "cl_vehiclelocked", false)
			setVehicleLocked ( theVehicle, false )
			Car_Msg( "Suanki Arac " .. vehiclename .. " İyi Oyunlar", theVehicle )
			Info_Msg ( "Suanki Arac " .. vehiclename .. " Kiliti Acildi", source )
			if ( getVehicleController ( theVehicle ) == false ) then
				cl_FlashOnce ( source )
			end
		end
	else
		Err_Msg("2", source)
	end
end

function doToggleLights ( source, beep )
	local theVehicle 
	if ( getElementType(source) == "vehicle" ) then
		theVehicle = source
	end
	if ( getElementType(source) == "player" ) then
		theVehicle = getElementData ( source, "cl_ownedvehicle" )
	end
	if ( theVehicle ) then
		-- if he was in one
		if ( getVehicleOverrideLights ( theVehicle ) ~= 2 ) then
            setVehicleOverrideLights ( theVehicle, 2 )
			if ( beep == true ) then
				local theElement = theVehicle
			end
        else
            setVehicleOverrideLights ( theVehicle, 1 )
        end
	else
		Err_Msg("1", source )
    end
end

addCommandHandler ( "lights", doToggleLights, false)
addCommandHandler ( "lock", doLockVehicle )
addCommandHandler ( "unlock", doUnlockVehicle )

 

Link to comment
function cl_RemoveVehicleOwner ( theVehicle )
	if not (theVehicle) or getElementType(theVehicle) ~= "vehicle" then return end
	
	local theOwner = getElementData ( theVehicle, "cl_vehicleowner" )
	if ( theOwner ~= false ) then
		removeElementData ( theOwner, "cl_ownedvehicle" )
		removeElementData ( theVehicle, "cl_vehicleowner" )
		removeElementData ( theVehicle, "cl_vehiclelocked" )
		removeElementData ( owned, "cl_enginestate" )
	end
	setVehicleLocked ( theVehicle, false )

end

Se esses erros não tiverem afetando o funcionamento do script, não é obrigatório corrigir, menos que esteja te incomodando no debug.

  • Like 2
Link to comment
  • Other Languages Moderators
function cl_RemoveVehicleOwner ( theVehicle )
	if isElement (theVehicle) then
		local theOwner = getElementData ( theVehicle, "cl_vehicleowner" )
		if ( theOwner ~= false ) then
			removeElementData ( theOwner, "cl_ownedvehicle" )
			removeElementData ( theVehicle, "cl_vehicleowner" )
			removeElementData ( theVehicle, "cl_vehiclelocked" )
			removeElementData ( owned, "cl_enginestate" )
		end
		setVehicleLocked ( theVehicle, false )
	end
end

 

  • Thanks 1
Link to comment

Velocimetro\speedo_S.lua:84: Bad argument @ 'removeElementData' [Expected element at argument 1]

Velocimetro\speedo_S.lua:85: Bad argument @ 'removeElementData' [Expected element at argument 1]

Velocimetro\speedo_S.lua:86: Bad argument @ 'removeElementData' [Expected element at argument 1]

Velocimetro\speedo_S.lua:87: Bad argument @ 'setVehicleLocked' [Expected element at argument 1]

Velocimetro\speedo_S.lua:103: Bad argument @ 'removeElementData' [Expected element at argument 1, got nil]

Link to comment
5 minutes ago, Lord Henry said:

Como está o código atual?


function initCarLocks ()
	local players = getElementsByType ( "player" )
	for k,p in ipairs(players) do
		removeElementData ( p, "cl_ownedvehicle" )
		bindKey ( p, "l", "down", doToggleLocked )
	end
	local vehicles = getElementsByType ( "vehicle" )
	for k,v in ipairs(vehicles) do
		removeElementData ( v, "cl_vehicleowner" )
		removeElementData ( v, "cl_vehiclelocked" )
		removeElementData ( v, "cl_enginestate" )
		setVehicleLocked ( v, false )
		setVehicleOverrideLights ( v, 0 )
	end
end
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), initCarLocks )
addEventHandler ( "onResourceStop", getResourceRootElement ( getThisResource () ), initCarLocks )

function cl_PlayerJoin ( )
bindKey ( source, "l", "down", doToggleLocked )
bindKey ( source, "k", "down", switchEngine )

end
addEventHandler ( "onPlayerJoin", getRootElement(), cl_PlayerJoin )

function cl_PlayerQuit ( )
	local ownedVehicle = getElementData ( source, "cl_ownedvehicle" )
	if (ownedVehicle ~= false) then
		cl_RemoveVehicleOwner ( ownedVehicle )
	end
end
addEventHandler ( "onPlayerQuit", getRootElement(), cl_PlayerQuit )

function cl_PlayerWasted ( )
	local ownedVehicle = getElementData ( source, "cl_ownedvehicle" )
	if (ownedVehicle ~= false) then
		cl_RemoveVehicleOwner ( ownedVehicle )
	end
end
addEventHandler ( "onPlayerWasted", getRootElement(), cl_PlayerWasted )

function cl_VehicleStartEnter ( enteringPlayer, seat, jacked )
	local theVehicle = source
	local theOwner
	if ( getElementData ( theVehicle, "cl_vehiclelocked" ) == true ) then
		theOwner = getElementData ( theVehicle, "cl_vehicleowner" )
		if theOwner ~= false and theOwner ~= enteringPlayer then
		end
	 end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), cl_VehicleStartEnter )

function cl_PlayerDriveVehicle ( player, seat, jacked )
	if ( seat == 0 ) then
		oldVehicle = getElementData ( player, "cl_ownedvehicle" )
		if ( (cl_VehicleLocked(source) == true) and (cl_VehicleOwner(source) ~= player) ) then
			removePlayerFromVehicle( player )
			Err_Msg("este veículo está trancado.", player)
			return false
		end
		cl_SetVehicleOwner ( source, player )
	end
	return true
end
addEventHandler ( "onVehicleEnter", getRootElement(), cl_PlayerDriveVehicle )

function cl_VehicleRespawn ( exploded ) 
	cl_RemoveVehicleOwner ( source )
end
addEventHandler ( "OnVehicleRespawn", getRootElement(), cl_VehicleRespawn )

function cl_VehicleExplode ( )
	local theOwner = getElementData ( source, "cl_vehicleowner" )
	if ( theOwner ~= false ) then
		cl_RemoveVehicleOwner ( source )
	end
end
addEventHandler ( "onVehicleExplode", getRootElement(), cl_VehicleExplode )

function cl_SetVehicleOwner ( theVehicle, thePlayer )
	local oldVehicle = getElementData ( thePlayer, "cl_ownedvehicle" )
	if ( oldVehicle ~= false ) then	
		removeElementData ( oldVehicle, "cl_vehicleowner" )
		removeElementData ( oldVehicle, "cl_vehiclelocked" )
		removeElementData ( oldVehicle, "cl_enginestate" )
		setVehicleLocked ( oldVehicle, false ) 
	end
	setElementData ( theVehicle, "cl_vehicleowner", thePlayer )
	setElementData ( theVehicle, "cl_vehiclelocked", false )
	setElementData ( thePlayer, "cl_ownedvehicle", theVehicle )
	setElementData( theVehicle, "cl_enginestate", true )

end

function cl_RemoveVehicleOwner ( theVehicle )
	if isElement (theVehicle) then
		local theOwner = getElementData ( theVehicle, "cl_vehicleowner" )
		if ( theOwner ~= false ) then
			removeElementData ( theOwner, "cl_ownedvehicle" )
			removeElementData ( theVehicle, "cl_vehicleowner" )
			removeElementData ( theVehicle, "cl_vehiclelocked" )
			removeElementData ( owned, "cl_enginestate" )
		end
		setVehicleLocked ( theVehicle, false )
	end
end

function cl_FlashLights ( thePlayer )
	setTimer ( doToggleLights, 300, 4, thePlayer, true )
end

function cl_FlashOnce ( thePlayer )
	setTimer ( doToggleLights, 300, 2, thePlayer, true )
end

function cl_VehicleOwner ( theVehicle )
	return getElementData( theVehicle, "cl_vehicleowner" )

end

function cl_VehicleLocked ( theVehicle )
	return getElementData( theVehicle, "cl_vehiclelocked" )
end

function Err_Msg ( strout, thePlayer )
	outputChatBox ( strout, thePlayer, 200, 0, 10 )
end

function Car_Msg ( strout, theVehicle )
	numseats = getVehicleMaxPassengers ( theVehicle )
	for s = 0, numseats do
		local targetPlayer = getVehicleOccupant ( theVehicle, s )
		if targetPlayer ~= false then
			outputChatBox ( strout, targetPlayer, 30, 144, 255 )
		end
	end
end

function Info_Msg ( strout, thePlayer )
	outputChatBox ( strout, thePlayer, 102, 205, 170 )
end

function doToggleLocked ( source )
	local theVehicle , strout
	if ( getElementType(source) == "vehicle" ) then
		theVehicle = source
	end
	if ( getElementType(source) == "player" ) then
		theVehicle = getElementData ( source, "cl_ownedvehicle" )
	end

	if ( theVehicle ) then
		local vehiclename = getVehicleName ( theVehicle )
		if ( getElementData ( theVehicle, "cl_vehiclelocked") == true ) then
			doUnlockVehicle ( source )
		else 
			doLockVehicle ( source )
		end
	else
		Err_Msg("Erro: Entre em um Veículo Para poder trancar!", source)
	end
end	

function doLockVehicle ( source )
	local theVehicle , strout
	if ( getElementType(source) == "vehicle" ) then
		theVehicle = source
	end
	if ( getElementType(source) == "player" ) then
		theVehicle = getElementData ( source, "cl_ownedvehicle" )
	end

	if ( theVehicle ) then
		local vehiclename = getVehicleName ( theVehicle )
		if ( getElementData ( theVehicle, "cl_vehiclelocked") == true ) then
			strout = "Aracın " .. vehiclename .. " Kiliti Acıldı" 
			Err_Msg(strout, source)
		else 
			setElementData ( theVehicle, "cl_vehiclelocked", true)
			setVehicleLocked ( theVehicle, true ) 
			Car_Msg( "Veículo " .. vehiclename .. " Trancou", theVehicle)
			Info_Msg ( "Veículo " .. vehiclename .. " Você Trancou seu carro.", source )
			if ( getVehicleController ( theVehicle ) == false ) then
				cl_FlashLights ( source )
			end
		end
	else
		Err_Msg("3", source)
	end
end

function doUnlockVehicle ( source )
	local theVehicle, strout
	if ( getElementType(source) == "vehicle" ) then
		theVehicle = source
	end
	if ( getElementType(source) == "player" ) then
		theVehicle = getElementData ( source, "cl_ownedvehicle" )
	end
	if ( theVehicle ) then
	local vehiclename = getVehicleName ( theVehicle )
		if ( getElementData ( theVehicle, "cl_vehiclelocked") == false ) then
			strout = "Arac " .. vehiclename .. " Arac Calinabilir"
			Err_Msg(strout, source)
		else
			setElementData ( theVehicle, "cl_vehiclelocked", false)
			setVehicleLocked ( theVehicle, false )
			Car_Msg( "Veículo " .. vehiclename .. " Destrancou", theVehicle )
			Info_Msg ( "Veículo " .. vehiclename .. " Você destrancou o carro.", source )
			if ( getVehicleController ( theVehicle ) == false ) then
				cl_FlashOnce ( source )
			end
		end
	else
		Err_Msg("2", source)
	end
end

function doToggleLights ( source, beep )
	local theVehicle 
	if ( getElementType(source) == "vehicle" ) then
		theVehicle = source
	end
	if ( getElementType(source) == "player" ) then
		theVehicle = getElementData ( source, "cl_ownedvehicle" )
	end
	if ( theVehicle ) then
		-- if he was in one
		if ( getVehicleOverrideLights ( theVehicle ) ~= 2 ) then
            setVehicleOverrideLights ( theVehicle, 2 )
			if ( beep == true ) then
				local theElement = theVehicle
			end
        else
            setVehicleOverrideLights ( theVehicle, 1 )
        end
	else
		Err_Msg("1", source )
    end
end

addCommandHandler ( "lights", doToggleLights, false)
addCommandHandler ( "lock", doLockVehicle )
addCommandHandler ( "unlock", doUnlockVehicle )

 

Link to comment
  • Other Languages Moderators

Na linha 103 está dando erro pq owned nem existe.

Nas outras linhas é só vc fazer a mesma coisa que vc fez na outra função, verificar se é um elemento ou não.

  • Thanks 1
Link to comment
1 hour ago, Lord Henry said:

Na linha 103 está dando erro pq owned nem existe.

Nas outras linhas é só vc fazer a mesma coisa que vc fez na outra função, verificar se é um elemento ou não.

Na linha 103 coloco assim?

			removeElementData ( theOwner, "cl_enginestate" )

 

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