Ace_Gambit Posted May 20, 2008 Share Posted May 20, 2008 Here is an alternative (maybe cleaner) method to prevent vehicle from being catapulted into the air. Your method works as well but could cause problems on slow computers. I have noticed that the catapulting is related to the streaming of world objects. When objects are not fully streamed in the vehicle is catapulted more often. What happens on slow computers is that the camera is not close enough to the vehicle when your method unfreezes it. The following code may prevent that from happening. client function trackcam(vehicle) local x, y, z = getElementPosition(vehicle) local cx, cy, cz = getCameraPosition() local dist = getDistanceBetweenPoints3D(x, y, z, cx, cy, cz) if (dist < 25.0) then setVehicleFrozen(vehicle, false) else setTimer(trackcam, 50, 1, vehicle) end end function yourtpfunc() -- teleport the vehicle trackcam(vehicle) end But i have a quick question in scripting: whats the opposite from isPlayerInVehicle? i searched in the wiki but found nothing like isPlayerNotInVehicle or isPlayerOnfoot. Can anybody help me? Why do you need a function that says you are not in a vehicle when that is exactly what the isPlayerInVehicle function does? Link to comment
XetaQuake Posted May 20, 2008 Author Share Posted May 20, 2008 Yea thanks Ace_Gambit!!!! Why do you need a function that says you are not in a vehicle when that is exactly what the isPlayerInVehicle function does? You mean this?: if not isPlayerInVehicle then ... I already tried it but it don´t works No warnings or so, or is "if not" not correct in lua? But i think its correct Link to comment
XetaQuake Posted May 20, 2008 Author Share Posted May 20, 2008 Yea thanks Ace_Gambit!!!! Why do you need a function that says you are not in a vehicle when that is exactly what the isPlayerInVehicle function does? You mean this?: if not isPlayerInVehicle then... I already tried it but it don´t works No warnings or so, or is "if not" not correct in lua? But i think its correct Link to comment
Ace_Gambit Posted May 20, 2008 Share Posted May 20, 2008 Yes, the logical operator is correct. However your syntax is wrong (parentheses is missing). It should be: client if not isPlayerInVehicle() then -- end server if not isPlayerInVehicle(player) then -- end Link to comment
Ace_Gambit Posted May 20, 2008 Share Posted May 20, 2008 Yes, the logical operator is correct. However your syntax is wrong (parentheses is missing). It should be: client if not isPlayerInVehicle() then -- end server if not isPlayerInVehicle(player) then -- end Link to comment
XetaQuake Posted May 20, 2008 Author Share Posted May 20, 2008 Thanks but don´t work, i want a teleporter to go back to the real world, but i only want to allow teleporting back when the player is not in a vehicle. here a the code: function backBeamer( player ) if not isPlayerInVehicle ( player ) then setElementInterior ( player, 0, 1109.8060302734, 1721.865234375, 10.8203125 ) end end any ideas pleas Link to comment
XetaQuake Posted May 20, 2008 Author Share Posted May 20, 2008 Thanks but don´t work, i want a teleporter to go back to the real world, but i only want to allow teleporting back when the player is not in a vehicle. here a the code: function backBeamer( player ) if not isPlayerInVehicle ( player ) then setElementInterior ( player, 0, 1109.8060302734, 1721.865234375, 10.8203125 ) end end any ideas pleas Link to comment
Ace_Gambit Posted May 20, 2008 Share Posted May 20, 2008 Thanks but don´t work, i want a teleporter to go back to the real world, but i only want to allow teleporting back when the player is not in a vehicle.here a the code: function backBeamer( player ) if not isPlayerInVehicle ( player ) then setElementInterior ( player, 0, 1109.8060302734, 1721.865234375, 10.8203125 ) end end any ideas pleas Strange, because that should work. Maybe you must add brackets? ... if (not isPlayerInVehicle ( player )) then ... Link to comment
Ace_Gambit Posted May 20, 2008 Share Posted May 20, 2008 Thanks but don´t work, i want a teleporter to go back to the real world, but i only want to allow teleporting back when the player is not in a vehicle.here a the code: function backBeamer( player ) if not isPlayerInVehicle ( player ) then setElementInterior ( player, 0, 1109.8060302734, 1721.865234375, 10.8203125 ) end end any ideas pleas Strange, because that should work. Maybe you must add brackets? ... if (not isPlayerInVehicle ( player )) then ... Link to comment
50p Posted May 21, 2008 Share Posted May 21, 2008 Maybe you try to use it in client-side script? Link to comment
50p Posted May 21, 2008 Share Posted May 21, 2008 Maybe you try to use it in client-side script? Link to comment
XetaQuake Posted May 21, 2008 Author Share Posted May 21, 2008 No i use it server side, i describe it better what happens: When i use this code i posted befor the player _AND_ the CAR gets teleported, and by the way the interior NOT changes But i want that i only teleports when i am not in a vehicle, but the "filter" (if not) don´t work. Here is the code again: function backBeamer( player ) if not isPlayerInVehicle ( player ) then setElementInterior ( player, 0, 1109.8060302734, 1721.865234375, 10.8203125 ) end end PS: Strange, because that should work. Maybe you must add brackets?... if (not isPlayerInVehicle ( player )) then ... Don´t work, its still the same Link to comment
XetaQuake Posted May 21, 2008 Author Share Posted May 21, 2008 No i use it server side, i describe it better what happens: When i use this code i posted befor the player _AND_ the CAR gets teleported, and by the way the interior NOT changes But i want that i only teleports when i am not in a vehicle, but the "filter" (if not) don´t work. Here is the code again: function backBeamer( player ) if not isPlayerInVehicle ( player ) then setElementInterior ( player, 0, 1109.8060302734, 1721.865234375, 10.8203125 ) end end PS: Strange, because that should work. Maybe you must add brackets?... if (not isPlayerInVehicle ( player )) then ... Don´t work, its still the same Link to comment
50p Posted May 21, 2008 Share Posted May 21, 2008 What event have you attached backBeamer function to? Or where do you call it? Link to comment
50p Posted May 21, 2008 Share Posted May 21, 2008 What event have you attached backBeamer function to? Or where do you call it? Link to comment
XetaQuake Posted May 21, 2008 Author Share Posted May 21, 2008 function markerExit(name) if name ~= getThisResource() then return else local marker = createMarker ( -1401.2969970703, -261.7790222168, 1043.65625, "cylinder", 2, 225, 200, 0, 100 ) end end Col = createColSphere ( -1401.2969970703, -261.7790222168, 1043.65625, 2 ) addEventHandler ( "onColShapeHit", Col, [b][color=#FF4040]backBeamer[/color][/b] ) addEventHandler ( "onResourceStart", getRootElement(), markerExit) Link to comment
XetaQuake Posted May 21, 2008 Author Share Posted May 21, 2008 function markerExit(name) if name ~= getThisResource() then return else local marker = createMarker ( -1401.2969970703, -261.7790222168, 1043.65625, "cylinder", 2, 225, 200, 0, 100 ) end end Col = createColSphere ( -1401.2969970703, -261.7790222168, 1043.65625, 2 )addEventHandler ( "onColShapeHit", Col, [b][color=#FF4040]backBeamer[/color][/b] ) addEventHandler ( "onResourceStart", getRootElement(), markerExit) Link to comment
50p Posted May 21, 2008 Share Posted May 21, 2008 Have you tried to enter the colshape using a car? If you "hit colshape" with a car, the vehicle element will be passed to that function and what the function thinks is do is check if "vehicle element" is in vehicle. Just do a check, like: function backBeamer( player ) if getElementType( player ) == "player" and not isPlayerInVehicle ( player ) then setElementInterior ( player, 0, 1109.8060302734, 1721.865234375, 10.8203125 ) end end Link to comment
50p Posted May 21, 2008 Share Posted May 21, 2008 Have you tried to enter the colshape using a car? If you "hit colshape" with a car, the vehicle element will be passed to that function and what the function thinks is do is check if "vehicle element" is in vehicle. Just do a check, like: function backBeamer( player ) if getElementType( player ) == "player" and not isPlayerInVehicle ( player ) then setElementInterior ( player, 0, 1109.8060302734, 1721.865234375, 10.8203125 ) end end Link to comment
XetaQuake Posted May 21, 2008 Author Share Posted May 21, 2008 Ah that was the problem Hehe, I have not thought so far ^^ thanks 50p, works perfect, thread a finish! Link to comment
XetaQuake Posted May 21, 2008 Author Share Posted May 21, 2008 Ah that was the problem Hehe, I have not thought so far ^^ thanks 50p, works perfect, thread a finish! Link to comment
XetaQuake Posted May 21, 2008 Author Share Posted May 21, 2008 Here is an alternative (maybe cleaner) method to prevent vehicle from being catapulted into the air. Your method works as well but could cause problems on slow computers. I have noticed that the catapulting is related to the streaming of world objects. When objects are not fully streamed in the vehicle is catapulted more often. What happens on slow computers is that the camera is not close enough to the vehicle when your method unfreezes it. The following code may prevent that from happening.client function trackcam(vehicle) local x, y, z = getElementPosition(vehicle) local cx, cy, cz = getCameraPosition() local dist = getDistanceBetweenPoints3D(x, y, z, cx, cy, cz) if (dist < 25.0) then setVehicleFrozen(vehicle, false) else setTimer(trackcam, 50, 1, vehicle) end end function yourtpfunc() -- teleport the vehicle trackcam(vehicle) end But i have a quick question in scripting: whats the opposite from isPlayerInVehicle? i searched in the wiki but found nothing like isPlayerNotInVehicle or isPlayerOnfoot. Can anybody help me? Why do you need a function that says you are not in a vehicle when that is exactly what the isPlayerInVehicle function does? You are right, sometimes i falling down because the interior not loading so fast or so. So i tried your tip: function unfrozen( player ) local playerVehicle = getPlayerOccupiedVehicle ( player ) local x, y, z = getElementPosition(playerVehicle) local cx, cy, cz = getCameraPosition() local dist = getDistanceBetweenPoints3D(x, y, z, cx, cy, cz) if (dist < 25.0) then setVehicleFrozen(playerVehicle, false) else setTimer(unfrozen, 50, 1, player) end end But the vehicle don´t get unfrozen. any ideas? And a error: .lua:196: attempt to call global 'getCameraPosition' (a nil value) I tries also getCameraPosition' (player) and getCameraPosition' (playerVehicle) but i get the same error (PS: sorry for doppelpost but i think its ok because i found a problem and now i have a question... ^^) Link to comment
XetaQuake Posted May 21, 2008 Author Share Posted May 21, 2008 Here is an alternative (maybe cleaner) method to prevent vehicle from being catapulted into the air. Your method works as well but could cause problems on slow computers. I have noticed that the catapulting is related to the streaming of world objects. When objects are not fully streamed in the vehicle is catapulted more often. What happens on slow computers is that the camera is not close enough to the vehicle when your method unfreezes it. The following code may prevent that from happening.client function trackcam(vehicle) local x, y, z = getElementPosition(vehicle) local cx, cy, cz = getCameraPosition() local dist = getDistanceBetweenPoints3D(x, y, z, cx, cy, cz) if (dist < 25.0) then setVehicleFrozen(vehicle, false) else setTimer(trackcam, 50, 1, vehicle) end end function yourtpfunc() -- teleport the vehicle trackcam(vehicle) end But i have a quick question in scripting: whats the opposite from isPlayerInVehicle? i searched in the wiki but found nothing like isPlayerNotInVehicle or isPlayerOnfoot. Can anybody help me? Why do you need a function that says you are not in a vehicle when that is exactly what the isPlayerInVehicle function does? You are right, sometimes i falling down because the interior not loading so fast or so. So i tried your tip: function unfrozen( player ) local playerVehicle = getPlayerOccupiedVehicle ( player ) local x, y, z = getElementPosition(playerVehicle) local cx, cy, cz = getCameraPosition() local dist = getDistanceBetweenPoints3D(x, y, z, cx, cy, cz) if (dist < 25.0) then setVehicleFrozen(playerVehicle, false) else setTimer(unfrozen, 50, 1, player) end end But the vehicle don´t get unfrozen. any ideas? And a error: .lua:196: attempt to call global 'getCameraPosition' (a nil value) I tries also getCameraPosition' (player) and getCameraPosition' (playerVehicle) but i get the same error (PS: sorry for doppelpost but i think its ok because i found a problem and now i have a question... ^^) Link to comment
Ace_Gambit Posted May 21, 2008 Share Posted May 21, 2008 The getCameraPosition function is purely client sided. You will have to teleport the vehicle server side and tell the client to start the camera check timer. Link to comment
Ace_Gambit Posted May 21, 2008 Share Posted May 21, 2008 The getCameraPosition function is purely client sided. You will have to teleport the vehicle server side and tell the client to start the camera check timer. 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