Wumbaloo Posted July 12, 2015 Posted July 12, 2015 Hi! I'm french, learning lua and try to script in lua. I'm stuck for almost 5 hours on this problem: I make a script to setCamera on the center of L.S but when I want to change the camera to the player, I have some errors, it's my code: function cameraSwitch(player) setTimer ( function(player) local x, y, z = getElementPosition( player ) outputChatBox("Message à délais de 5 secondes.") outputChatBox("Un changement de caméra doit vous permettre de pouvoir jouer convenablement") setCameraPosition(player, x, y, z) setCameraTarget(player) end, 5000, 1 ) end And the MTAServer.exe said that: "WARNING: Bad argument 'getElementPosition' argument 1, got nill"ERROR: attempt to call global 'setCameraPosition' (a nil value) I tried with "thePlayer" but it didn't work Can you help me ? Thanks, I will give all of the code if you want
GTX Posted July 12, 2015 Posted July 12, 2015 It's setCameraMatrix, not setCameraPosition. Is this client-sided or server-sided script?
Sasu Posted July 13, 2015 Posted July 13, 2015 You have to pass 'player' argument to setTimer. function cameraSwitch(player) setTimer ( function(player) local x, y, z = getElementPosition( player ) outputChatBox("Message à délais de 5 secondes.") outputChatBox("Un changement de caméra doit vous permettre de pouvoir jouer convenablement") setCameraMatrix(player, x, y, z) setCameraTarget(player) end, 5000, 1, player ) -- Here end
Wumbaloo Posted July 13, 2015 Author Posted July 13, 2015 It's a server sided script It's the same warnings guys WARNING: Bad argument getElementPosition [Expected element at argument 1, got nil]WARNING: Bad argument setCameraMatrix [Expected element at argument 1, got nil] WARNING: Bad argument setCameraTarget [Expected element at argument 1, got nil]
GTX Posted July 13, 2015 Posted July 13, 2015 Those errors mean that player isn't defined. Pass a player element to cameraSwitch function. I guess this is not full code, therefore I can't help you further.
Wumbaloo Posted July 13, 2015 Author Posted July 13, 2015 Here's the full code function mainFunction() cameraSwitch() end function setCameraOnPlayerJoin() local x = 1544.0400390625 local y = -1649.0029296875 local z = 28.402114868164 spawnPlayer(source, x, y , z) setCameraTarget(source, source) setCameraMatrix(source, 1476.697265625, -1637.4736328125, 40.525096893311 , 1544.0400390625, -1649.0029296875, 28.402114868164, 0, 50) fadeCamera(source, true, 5) outputChatBox("Bienvenue sur le serveur de test!", source) mainFunction() end addEventHandler("onPlayerJoin", getRootElement(), setCameraOnPlayerJoin) function createVehicleForPlayer(thePlayer, commandName, vehicleModel) local x,y,z = getElementPosition(thePlayer) x = x + 5 local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z) if (createdVehicle == false) then outputChatBox("Erreur lors de la création du véhicule") end end addCommandHandler("veh", createVehicleForPlayer) function cameraSwitch(player) setTimer ( function(player) local x, y, z = getElementPosition(player) outputChatBox("Message à délais de 5 secondes.") outputChatBox("Un changement de caméra doit vous permettre de pouvoir jouer convenablement") setCameraMatrix(player, x, y, z) setCameraTarget(player) end, 5000, 1, player ) end
GTX Posted July 13, 2015 Posted July 13, 2015 function setCameraOnPlayerJoin() local x = 1544.0400390625 local y = -1649.0029296875 local z = 28.402114868164 spawnPlayer(source, x, y , z) setCameraTarget(source, source) setCameraMatrix(source, 1476.697265625, -1637.4736328125, 40.525096893311 , 1544.0400390625, -1649.0029296875, 28.402114868164, 0, 50) fadeCamera(source, true, 5) outputChatBox("Bienvenue sur le serveur de test!", source) setTimer(cameraSwitch, 5000, 1, source) end addEventHandler("onPlayerJoin", getRootElement(), setCameraOnPlayerJoin) function createVehicleForPlayer(thePlayer, commandName, vehicleModel) local x,y,z = getElementPosition(thePlayer) x = x + 5 local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z) if (createdVehicle == false) then outputChatBox("Erreur lors de la création du véhicule") end end addCommandHandler("veh", createVehicleForPlayer) function cameraSwitch(player) local x, y, z = getElementPosition(player) outputChatBox("Message à délais de 5 secondes.") outputChatBox("Un changement de caméra doit vous permettre de pouvoir jouer convenablement") setCameraMatrix(player, x, y, z) setCameraTarget(player) end
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