Nerses Posted June 20, 2014 Share Posted June 20, 2014 Can anyone tell what I did in this script generates an error in the console? [2014-06-20 14:29:49] WARNING: [gameplay]/bpcarlocks/car_locks_server.lua:116: Bad argument @ 'removeElementData' [Expected element at argument 1] [2014-06-20 14:29:49] WARNING: [gameplay]/bpcarlocks/car_locks_server.lua:117: Bad argument @ 'removeElementData' [Expected element at argument 1] [2014-06-20 14:29:49] WARNING: [gameplay]/bpcarlocks/car_locks_server.lua:118: Bad argument @ 'removeElementData' [Expected element at argument 1] [2014-06-20 14:29:49] WARNING: [gameplay]/bpcarlocks/car_locks_server.lua:119: Bad 'vehicle' pointer @ 'setVehicleLocked'(1) Here is the script itself -- player element data -- -- cl_ownedvehicle -- vehicle element data -- -- cl_vehicleowner -- cl_vehiclelocked -- cl_enginestate -- resource starts - ends function initCarLocks () -- Initilize Player Element Data local players = getElementsByType ( "player" ) for k,p in ipairs(players) do removeElementData ( p, "cl_ownedvehicle" ) end -- Initilize Vehicle Element Data 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 ) -- player joins function cl_PlayerJoin ( ) bindKey ( source, "l", "down", doToggleLocked ) bindKey ( source, "i", "down", doToggleLights ) bindKey ( source, "j", "down", doToggleEngine ) end addEventHandler ( "onPlayerJoin", getRootElement(), cl_PlayerJoin ) -- player quits function cl_PlayerQuit ( ) -- check for owned car local ownedVehicle = getElementData ( source, "cl_ownedvehicle" ) if (ownedVehicle ~= false) then cl_RemoveVehicleOwner ( ownedVehicle ) end end addEventHandler ( "onPlayerQuit", getRootElement(), cl_PlayerQuit ) -- player dies function cl_PlayerWasted ( ) -- check for owned car local ownedVehicle = getElementData ( source, "cl_ownedvehicle" ) if (ownedVehicle ~= false) then cl_RemoveVehicleOwner ( ownedVehicle ) end end addEventHandler ( "onPlayerWasted", getRootElement(), cl_PlayerWasted ) -- player tries to enter vehicle function cl_VehicleStartEnter ( enteringPlayer, seat, jacked ) local theVehicle = source local theOwner -- locked and not owner entering if ( getElementData ( theVehicle, "cl_vehiclelocked" ) == true ) then theOwner = getElementData ( theVehicle, "cl_vehicleowner" ) if theOwner ~= false and theOwner ~= enteringPlayer then -- make sure they dont enter --cancelEvent(); end end end addEventHandler ( "onVehicleStartEnter", getRootElement(), cl_VehicleStartEnter ) -- player enters a vehicle function cl_PlayerDriveVehicle ( player, seat, jacked ) -- Driver Enter if ( seat == 0 ) then oldVehicle = getElementData ( player, "cl_ownedvehicle" ) -- not entering player's own owned vehicle if ( (cl_VehicleLocked(source) == true) and (cl_VehicleOwner(source) ~= player) ) then removePlayerFromVehicle( player ) Err_Msg("Автомобиль закрыт.", player) return false end -- set element data for vehicle and owner cl_SetVehicleOwner ( source, player ) end return true end addEventHandler ( "onVehicleEnter", getRootElement(), cl_PlayerDriveVehicle ) -- vehicle respawns function cl_VehicleRespawn ( exploded ) cl_RemoveVehicleOwner ( source ) end addEventHandler ( "OnVehicleRespawn", getRootElement(), cl_VehicleRespawn ) -- vehicle explosion function cl_VehicleExplode ( ) local theOwner = getElementData ( source, "cl_vehicleowner" ) if ( theOwner ~= false ) then cl_RemoveVehicleOwner ( source ) end end addEventHandler ( "onVehicleExplode", getRootElement(), cl_VehicleExplode ) -- set vehicle owner function cl_SetVehicleOwner ( theVehicle, thePlayer ) local oldVehicle = getElementData ( thePlayer, "cl_ownedvehicle" ) if ( oldVehicle ~= false ) then -- unlock old car removeElementData ( oldVehicle, "cl_vehicleowner" ) removeElementData ( oldVehicle, "cl_vehiclelocked" ) removeElementData ( oldVehicle, "cl_enginestate" ) setVehicleLocked ( oldVehicle, false ) -- set vars for new car 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 -- flash the lights twice function cl_FlashLights ( thePlayer ) setTimer ( doToggleLights, 300, 4, thePlayer, true ) end -- flash once function cl_FlashOnce ( thePlayer ) setTimer ( doToggleLights, 300, 2, thePlayer, true ) end -- get vehicle owner ( according to vehicle's element data ) function cl_VehicleOwner ( theVehicle ) return getElementData( theVehicle, "cl_vehicleowner" ) end -- is vehicle locked ( according to vehicle's element data ) function cl_VehicleLocked ( theVehicle ) return getElementData( theVehicle, "cl_vehiclelocked" ) end -- messaging functions -- send red error message function Err_Msg ( strout, thePlayer ) outputChatBox ( strout, thePlayer, 200, 0, 10 ) end -- send message to all occupants of vehicle 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 -- send aquamarine message to player function Info_Msg ( strout, thePlayer ) outputChatBox ( strout, thePlayer, 102, 205, 170 ) end -- commands 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 ) -- already locked if ( getElementData ( theVehicle, "cl_vehiclelocked") == true ) then doUnlockVehicle ( source ) else doLockVehicle ( source ) end else Err_Msg("Вы должны быть в автомобиле, что бы закрыть или открыть его..", 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 ) -- already locked if ( getElementData ( theVehicle, "cl_vehiclelocked") == true ) then strout = "Вы снова закрыли " .. vehiclename .. "" Err_Msg(strout, source) else setElementData ( theVehicle, "cl_vehiclelocked", true) setVehicleLocked ( theVehicle, true ) Car_Msg( "Автомобиль " .. vehiclename .. " закрыт.", theVehicle) if ( getVehicleController ( theVehicle ) == false ) then cl_FlashLights ( source ) end end else Err_Msg("Вы должны находится в автомобтле.", 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 = "Вы " .. vehiclename .. " сново открыли." Err_Msg(strout, source) else setElementData ( theVehicle, "cl_vehiclelocked", false) setVehicleLocked ( theVehicle, false ) Car_Msg( "Автомобиль " .. vehiclename .. " открыт.", theVehicle ) if ( getVehicleController ( theVehicle ) == false ) then cl_FlashOnce ( source ) end end else Err_Msg("Вы должны находится в автомобиле.", source) end end Link to comment
Mr.unpredictable. Posted June 20, 2014 Share Posted June 20, 2014 -- Initilize Vehicle Element Data 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 what is this ? Link to comment
_DrXenon Posted June 20, 2014 Share Posted June 20, 2014 oldVehicle is not an element. I don't really think that the return of the function "getElementData" can be an element D: Link to comment
_DrXenon Posted June 20, 2014 Share Posted June 20, 2014 oldVehicle is not an element. I don't really think that the return of the function "getElementData" can be an element D: Link to comment
Nerses Posted June 20, 2014 Author Share Posted June 20, 2014 oldVehicle is not an element.I don't really think that the return of the function "getElementData" can be an element D: what to do? Link to comment
Mr_Moose Posted June 20, 2014 Share Posted June 20, 2014 The lines doesn't seems to match but your error may be in this function, at line 3, the if statement let's it pass as long oldVehicle is not false, if getElementData fails the value will be nil and therefore nil is an accepted value. However nil is not an element and that's why you'll get those errors. function cl_SetVehicleOwner ( theVehicle, thePlayer ) local oldVehicle = getElementData ( thePlayer, "cl_ownedvehicle" ) if ( oldVehicle ~= false ) then -- unlock old car removeElementData ( oldVehicle, "cl_vehicleowner" ) removeElementData ( oldVehicle, "cl_vehiclelocked" ) removeElementData ( oldVehicle, "cl_enginestate" ) setVehicleLocked ( oldVehicle, false ) -- set vars for new car end setElementData ( theVehicle, "cl_vehicleowner", thePlayer ) setElementData ( theVehicle, "cl_vehiclelocked", false ) setElementData ( thePlayer, "cl_ownedvehicle", theVehicle ) setElementData( theVehicle, "cl_enginestate", true ) end The solution is to replace the if statement to this: if isElement( oldVehicle ) then Link to comment
Nerses Posted June 20, 2014 Author Share Posted June 20, 2014 The lines doesn't seems to match but your error may be in this function, at line 3, the if statement let's it pass as long oldVehicle is not false, if getElementData fails the value will be nil and therefore nil is an accepted value. However nil is not an element and that's why you'll get those errors. function cl_SetVehicleOwner ( theVehicle, thePlayer ) local oldVehicle = getElementData ( thePlayer, "cl_ownedvehicle" ) if ( oldVehicle ~= false ) then -- unlock old car removeElementData ( oldVehicle, "cl_vehicleowner" ) removeElementData ( oldVehicle, "cl_vehiclelocked" ) removeElementData ( oldVehicle, "cl_enginestate" ) setVehicleLocked ( oldVehicle, false ) -- set vars for new car end setElementData ( theVehicle, "cl_vehicleowner", thePlayer ) setElementData ( theVehicle, "cl_vehiclelocked", false ) setElementData ( thePlayer, "cl_ownedvehicle", theVehicle ) setElementData( theVehicle, "cl_enginestate", true ) end The solution is to replace the if statement to this: if isElement( oldVehicle ) then what to do now? how to fix me? I just don't really understand English, sorry Link to comment
kevenvz Posted June 20, 2014 Share Posted June 20, 2014 He means this: function cl_SetVehicleOwner ( theVehicle, thePlayer ) local oldVehicle = getElementData ( thePlayer, "cl_ownedvehicle" ) if isElement(oldVehicle) then -- unlock old car removeElementData ( oldVehicle, "cl_vehicleowner" ) removeElementData ( oldVehicle, "cl_vehiclelocked" ) removeElementData ( oldVehicle, "cl_enginestate" ) setVehicleLocked ( oldVehicle, false ) -- set vars for new car end setElementData ( theVehicle, "cl_vehicleowner", thePlayer ) setElementData ( theVehicle, "cl_vehiclelocked", false ) setElementData ( thePlayer, "cl_ownedvehicle", theVehicle ) setElementData( theVehicle, "cl_enginestate", true ) end Link to comment
Nerses Posted June 21, 2014 Author Share Posted June 21, 2014 He means this: function cl_SetVehicleOwner ( theVehicle, thePlayer ) local oldVehicle = getElementData ( thePlayer, "cl_ownedvehicle" ) if isElement(oldVehicle) then -- unlock old car removeElementData ( oldVehicle, "cl_vehicleowner" ) removeElementData ( oldVehicle, "cl_vehiclelocked" ) removeElementData ( oldVehicle, "cl_enginestate" ) setVehicleLocked ( oldVehicle, false ) -- set vars for new car end setElementData ( theVehicle, "cl_vehicleowner", thePlayer ) setElementData ( theVehicle, "cl_vehiclelocked", false ) setElementData ( thePlayer, "cl_ownedvehicle", theVehicle ) setElementData( theVehicle, "cl_enginestate", true ) end Thank you, one problem has disappeared in this script. How to fix it? Trying to do, but not as failed. [2014-06-21 12:50:45] WARNING: [gameplay]/bpcarsystem/s.lua:36: Bad 'ped' pointer @ 'getPedOccupiedVehicle'(1) local carFuel = {}; local gasStations = {}; local gasStationsBlip = {}; local gasStationsMarkers = {}; addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() local xml = xmlLoadFile("carData.xml"); local xmlNodes = xmlNodeGetChildren(xml); for i,node in ipairs(xmlNodes) do carFuel[tonumber(xmlNodeGetAttribute(node,'id'))] = tonumber(xmlNodeGetAttribute(node,'fuel')); end xmlUnloadFile(xml); local xml = xmlLoadFile("garageData.xml"); local xmlNodes = xmlNodeGetChildren(xml); for i,node in ipairs(xmlNodes) do local name = xmlNodeGetAttribute(node,'name'); local x = tonumber(xmlNodeGetAttribute(node,'x')); local y = tonumber(xmlNodeGetAttribute(node,'y')); local z = tonumber(xmlNodeGetAttribute(node,'z')); gasStationsBlip[name] = createBlip(x,y,z,51,0,0,0,0,0,0,450); local moreKids = xmlNodeGetChildren(node); gasStationsMarkers[name] = {}; for i,v in ipairs(moreKids) do local mx = tonumber(xmlNodeGetAttribute(v,'x')); local my = tonumber(xmlNodeGetAttribute(v,'y')); local mz = tonumber(xmlNodeGetAttribute(v,'z')); gasStationsMarkers[name][i] = createMarker(mx,my,mz,'corona',3,128,128,0,128); setElementData(gasStationsMarkers[name][i],'gasStation',true); end end xmlUnloadFile(xml); end ) function fuelUse(p) local vehicle = getPedOccupiedVehicle(p); if vehicle then setTimer(fuelUse,1000,1,p); if getVehicleType(vehicle) ~= 'Automobile' and getVehicleType(vehicle) ~= 'Bike' and getVehicleType(vehicle) ~= 'Monster Truck' and getVehicleType(vehicle) ~= 'Quad' then return end if getVehicleController(vehicle) ~= p then return end --### if getVehicleEngineState(vehicle) == false then return end --### local fuel = getCarFuel(vehicle) if fuel == 0 then setVehicleEngineState(vehicle,false); return end --### --[[local speedX, speedY, speedZ = getElementVelocity(vehicle); vel = (speedX^2 + speedY^2 + speedZ^2)^(0.5)+(math.random(100,1000)/25000);]] local newX,newY,newZ = getElementPosition(vehicle); local oldX = getElementData(vehicle,'oldX') or newX; local oldY = getElementData(vehicle,'oldY') or newY; local oldZ = getElementData(vehicle,'oldZ') or newZ; local vel = (getDistanceBetweenPoints2D(oldX,oldY,newX,newY)/70)+(math.random(100,1000)/50000); local oldX = setElementData(vehicle,'oldX',newX); local oldY = setElementData(vehicle,'oldY',newY); local oldZ = setElementData(vehicle,'oldZ',newZ) --if vel < 0.01 then return end --### local remainingFuel = takeCarFuel(vehicle,vel); if remainingFuel < 0.001 then remainingFuel = 0; outputChatBox('',v); setVehicleEngineState(vehicle,false); end end end function startFuelUse(p,seat,jacked) if getVehicleType(source) ~= 'Automobile' and getVehicleType(source) ~= 'Bike' and getVehicleType(source) ~= 'Monster Truck' and getVehicleType(source) ~= 'Quad' then return end if seat ~= 0 then return end if getCarFuel(source) <= 0 then setVehicleEngineState(source,false); end setTimer(fuelUse,1000,1,p); end addEventHandler("onVehicleEnter",getRootElement(),startFuelUse) function switchEngine(playerSource) local theVehicle = getPedOccupiedVehicle(playerSource); if theVehicle and getVehicleController(theVehicle) == playerSource then local state = getVehicleEngineState(theVehicle) if state then setVehicleEngineState(theVehicle, false); outputChatBox('Car engine turned off.',playerSource); else if getCarFuel(theVehicle) <= 0 then return end setVehicleEngineState(theVehicle, true); outputChatBox('Car engine turned on.',playerSource); end end end addCommandHandler("engine",switchEngine); addEvent('pedSyphonVehicle',true); function pedSyphon(v) if getCarFuel(source) >= carFuel[-1] then outputChatBox("You are holding as much fuel as you can carry.",source); return end local n = math.random(100,200)/1000; local left = takeCarFuel(v,n); local total = addCarFuel(source,n); if left <= 0 then outputChatBox("That car has no more fuel left.",source); return end triggerClientEvent("onPedSyphonFuel",source); end addEventHandler('pedSyphonVehicle',getRootElement(),pedSyphon); addEvent('pedRefuelVehicle',true); function pedSyphon(v) if getCarFuel(source) <= 0 then outputChatBox("You have no more fuel left.",source); return end local maxFuel = carFuel[0]; if carFuel[getElementModel(v)] then maxFuel = getFuel[getElementModel(v)]; end if getCarFuel(v) >= maxFuel then outputChatBox("That car is fully refueled.",source); return end local n = math.random(100,200)/1000; local left = takeCarFuel(source,n); local total = addCarFuel(v,n); triggerClientEvent("onPedReFuel",source); end addEventHandler('pedRefuelVehicle',getRootElement(),pedSyphon); addEvent('onVehicleRefuel',true); function vehicleRefuel(v,m) if not getElementData(m,'gasStation') then return end if getElementType(v) ~= 'vehicle' then return end if getVehicleType(v) ~= 'Automobile' and getVehicleType(v) ~= 'Bike' and getVehicleType(v) ~= 'Monster Truck' and getVehicleType(v) ~= 'Quad' then return end local driver = getVehicleOccupants(v); if not driver[0] then return end if not isElementWithinMarker(v,m) then return end --### local maxFuel = carFuel[0]; if getPlayerMoney(driver[0]) < 25 then outputChatBox("",p); return end if carFuel[getElementModel(v)] then maxFuel = carFuel[getElementModel(v)]; end if getCarFuel(v) >= maxFuel then return end addCarFuel(v,15); takePlayerMoney(driver[0],25); if getCarFuel(v) >= maxFuel then outputChatBox("",p); takeCarFuel(v,getCarFuel(v)-maxFuel); return end setTimer(vehicleRefuel,500,1,v,m); end addEventHandler('onVehicleRefuel',getRootElement(),vehicleRefuel); function hitTheMarker(e) setTimer(vehicleRefuel,1500,1,e,source); end addEventHandler('onMarkerHit',getRootElement(),hitTheMarker); function getCarFuel(v) if getElementType(v) == 'vehicle' then if getVehicleType(v) == 'Automobile' or getVehicleType(v) == 'Bike' or getVehicleType(v) == 'Monster Truck' or getVehicleType(v) == 'Quad' then local fuel = getElementData(v,'fuel'); local model = getElementModel(v); if not carFuel[model] then model = 0; end if not fuel then if carFuel[model] then fuel = carFuel[model]; setElementData(v,'fuel',carFuel[model]); else fuel = carFuel[0]; setElementData(v,'fuel',carFuel[0]); end end return fuel; end elseif getElementType(v) == 'player' then local fuel = getElementData(v,'fuel'); if not fuel then setElementData(v,'fuel',0); return 0; end return fuel; end end function addCarFuel(v,a) if getElementType(v) == 'vehicle' then if getVehicleType(v) == 'Automobile' or getVehicleType(v) == 'Bike' or getVehicleType(v) == 'Monster Truck' or getVehicleType(v) == 'Quad' then local fuel = getElementData(v,'fuel'); local model = getElementModel(v); if not carFuel[model] then model = 0; end if not fuel then if carFuel[model] then fuel = carFuel[model]; setElementData(v,'fuel',carFuel[model]); else fuel = carFuel[0]; setElementData(v,'fuel',carFuel[0]); end end fuel = fuel + a; if fuel > carFuel[model] then fuel = carFuel[model]; end setElementData(v,'fuel',fuel); return fuel; end elseif getElementType(v) == 'player' then local fuel = getElementData(v,'fuel'); if not fuel then fuel = 0; end fuel = fuel + a; if fuel > carFuel[-1] then fuel = carFuel[-1]; end setElementData(v,'fuel',fuel); return fuel; end end function takeCarFuel(v,a) if getElementType(v) == 'vehicle' then if getVehicleType(v) == 'Automobile' or getVehicleType(v) == 'Bike' or getVehicleType(v) == 'Monster Truck' or getVehicleType(v) == 'Quad' then local fuel = getElementData(v,'fuel'); local model = getElementModel(v); if not carFuel[model] then model = 0; end if not fuel then if carFuel[model] then fuel = carFuel[model]; setElementData(v,'fuel',carFuel[model]); else fuel = carFuel[0]; setElementData(v,'fuel',carFuel[0]); end end fuel = fuel - a; if fuel < 0 then fuel = 0; end setElementData(v,'fuel',fuel); return fuel; end elseif getElementType(v) == 'player' then local fuel = getElementData(v,'fuel'); if not fuel then fuel = 0; end fuel = fuel - a; if fuel < 0 then fuel = 0; end setElementData(v,'fuel',fuel); return fuel; end end addEvent('giveVehicleFuelOnSpawn',true); addEventHandler('giveVehicleFuelOnSpawn',getRootElement(),function() getCarFuel(source); end); function onVehicleRespawn(exploded) if getElementType(source) ~= 'vehicle' then return end local model = getElementModel(source); if not carFuel[model] then model = 0; end if not fuel then if carFuel[model] then setElementData(source,'fuel',carFuel[model]); else setElementData(source,'fuel',carFuel[0]); end Link to comment
Nerses Posted June 21, 2014 Author Share Posted June 21, 2014 Just come here these errors [2014-06-21 13:01:31] WARNING: [gameplay]/bpcarlocks/car_locks_server.lua:130: Bad argument @ 'getElementData' [Expected element at argument 1] [2014-06-21 13:01:31] WARNING: [gameplay]/bpcarlocks/car_locks_server.lua:137: Bad 'vehicle' pointer @ 'setVehicleLocked'(1) [2014-06-21 13:01:31] WARNING: [gameplay]/bpcarsystem/s.lua:36: Bad 'ped' pointer @ 'getPedOccupiedVehicle'(1) Link to comment
kevenvz Posted June 21, 2014 Share Posted June 21, 2014 They are warnings, not so important. The script should still work so why bothering fixing it? Link to comment
Nerses Posted June 21, 2014 Author Share Posted June 21, 2014 They are warnings, not so important. The script should still work so why bothering fixing it? well I just wanted to correct that purpose to the server is not any inhibition was not Link to comment
Mr_Moose Posted June 21, 2014 Share Posted June 21, 2014 They are warnings, not so important. The script should still work so why bothering fixing it? It is pretty important too, having a log full of warnings isn't funny and the players may wonder why something isn't working. When you'll get a warning like that you must check the object type and inform the user with some kind of GUI response. Otherwise the players will consider the server as "bugged" and meanwhile he continues to try the feature that isn't working your logs get full of spam. The thing is that lua variables isn't always declared as a certain objects like in other languages such as C where you write string tmp = ""; to declare a string and int i = 0; for an int etc... In lua a variable can be pretty much anything. You can't always be 100% sure what the function argument 'p' is and due to that you need to verify what it is, by using an if statement like this: if p and isElement(p) and ( getElementType(p) == "ped" or getElementType(p) == "player" then end Inside your functions which use arguments that must be an certain object. Link to comment
Nerses Posted June 21, 2014 Author Share Posted June 21, 2014 They are warnings, not so important. The script should still work so why bothering fixing it? It is pretty important too, having a log full of warnings isn't funny and the players may wonder why something isn't working. When you'll get a warning like that you must check the object type and inform the user with some kind of GUI response. Otherwise the players will consider the server as "bugged" and meanwhile he continues to try the feature that isn't working your logs get full of spam. The thing is that lua variables isn't always declared as a certain objects like in other languages such as C where you write string tmp = ""; to declare a string and int i = 0; for an int etc... In lua a variable can be pretty much anything. You can't always be 100% sure what the function argument 'p' is and due to that you need to verify what it is, by using an if statement like this: if p and isElement(p) and ( getElementType(p) == "ped" or getElementType(p) == "player" then end Inside your functions which use arguments that must be an certain object. where and what to fix? Link to comment
TIGS98 Posted October 31, 2015 Share Posted October 31, 2015 function cl_SetVehicleOwner ( theVehicle, thePlayer ) local oldVehicle = getElementData ( thePlayer, "cl_ownedvehicle" ) for k,v in ipairs(getElementsByType ( "vehicle" )) do if ( oldVehicle ~= false and oldVehicle == v ) then removeElementData ( oldVehicle, "cl_vehicleowner" ) removeElementData ( oldVehicle, "cl_vehiclelocked" ) removeElementData ( oldVehicle, "cl_enginestate" ) setVehicleLocked ( oldVehicle, false ) outputDebugString("REMOVE DATA") end end outputDebugString("UPDATE DATA") setElementData ( theVehicle, "cl_vehicleowner", thePlayer ) setElementData ( theVehicle, "cl_vehiclelocked", false ) setElementData ( thePlayer, "cl_ownedvehicle", theVehicle ) setElementData( theVehicle, "cl_enginestate", true ) end Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now