Dzsozi (h03) Posted June 11, 2014 Share Posted June 11, 2014 Hello guys! I have a question. How can I continue this script? I have no idea. I want to make the script work like if you are closer to Los Santos hospital then you will spawn there, but if you are closer to Blueberry hospital (in my server there is a custom hospital in blueberry) then you will spawn there. How can I make this? Please help me, I have no idea how to continue. local x,y,z = getElementPosition (thePlayer) local ls1 = getDistanceBetweenPoints3D (x,y,z,1183.291015625, -1323.033203125, 13.577140808105) local ls2 = getDistanceBetweenPoints3D (x,y,z,2034.080078125, -1404.7314453125, 17.251882553101) local montgomery = getDistanceBetweenPoints3D (x,y,z,1371.830078125, 405.94140625, 19.7578125) local blueberry = getDistanceBetweenPoints3D (x,y,z,207.50390625, -62.701171875, 1.5977957248688) Link to comment
cheez3d Posted June 11, 2014 Share Posted June 11, 2014 local HospitalPositions = { ["Los Santos 1"] = {1183.291015625,-1323.033203125,13.577140808105}, ["Los Santos 2"] = {2034.080078125,-1404.7314453125,17.251882553101}, Montgomery = {1371.830078125,405.94140625,19.7578125}, Blueberry = {207.50390625,-62.701171875,1.5977957248688}; }; addEventHandler("onPlayerWasted",root,function() local PlayerPosition,Distances = {getElementPosition(source)},{}; for _,v in pairs(HospitalPositions) do table.insert(Distances,{ Position = v, Distance = getDistanceBetweenPoints3D(PlayerPosition[1],PlayerPosition[2],PlayerPosition[3],v[1],v[2],v[3]); }); end; table.sort(Distances,function(a,b) return a.Distance end); local NearestHospital = {unpack(Distances[1].Position)}; spawnPlayer(source,NearestHospital[1],NearestHospital[2],NearestHospital[3]); end); Link to comment
Dzsozi (h03) Posted June 11, 2014 Author Share Posted June 11, 2014 The half of it works, but for some reason it sets everybody's skin to CJ. local theSkin = getPedSkin(thePlayer) local theTeam = getPlayerTeam(thePlayer) local PlayerPosition,Distances = {getElementPosition(thePlayer)},{}; for _,v in pairs(HospitalPositions) do table.insert(Distances,{ Position = v, Distance = getDistanceBetweenPoints3D(PlayerPosition[1],PlayerPosition[2],PlayerPosition[3],v[1],v[2],v[3]); }); end; table.sort(Distances,function(a,b) return a.Distance end); local NearestHospital = {unpack(Distances[1].Position)}; spawnPlayer(thePlayer,NearestHospital[1],NearestHospital[2],NearestHospital[3], theSkin, 0, 0, theTeam); Link to comment
Den. Posted June 11, 2014 Share Posted June 11, 2014 spawnPlayer(thePlayer,NearestHospital[1],NearestHospital[2],NearestHospital[3], theSkin, 0, 0, theTeam) Rotation comes before skin in the order of arguments in spawnPlayer, so correct it to: spawnPlayer(thePlayer,NearestHospital[1],NearestHospital[2],NearestHospital[3], 0, theSkin, 0, 0, theTeam) Link to comment
Dzsozi (h03) Posted June 11, 2014 Author Share Posted June 11, 2014 (edited) I have already tried it, but I still get CJ skin and I get respawned two times. EDIT: Fixed it, my mistake. Thank you for your help! EDIT 2: Could you help me in one more thing please? I want to add the rotations and camera positions (to set the camera position at the hospital before spawn) to the table as well, not just the positions. How can I do this? Edited June 13, 2014 by Guest Link to comment
Spajk Posted June 13, 2014 Share Posted June 13, 2014 local hospitalPositions = { --{name, x, y, z, r, cx, cy, cz} {"Los Santos 1", 1183.3, -1323, 13.58, 0, 1183.3, -1323, 18}, {"Los Santos 2", 2034.1, -1404.73, 17.25, 0, 2034.1, -1404.73, 22}, {"Montgomery", 1371.83, 405.94, 19.76, 0, 1371.83, 405.94, 25}, {"Blueberry", 207.5, -62.7, 1.6, 0, 207.5, -62.7, 7} }; addEventHandler("onPlayerWasted", root, function() local theSkin = getPedSkin(thePlayer) local theTeam = getPlayerTeam(thePlayer) local px, py, pz = getElementPosition(source) local nearest = 1 for k, v in pairs(hospitalPositions) do if(getDistanceBetweenPoints3D(v[2], v[3], v[4], px, py, pz) < getDistanceBetweenPoints3D(hospitalPositions[nearest][2], hospitalPositions[nearest][3], hospitalPositions[nearest][4], px, py, pz))then nearest = k end end setCameraMatrix(source, hospitalPositions[nearest][6], hospitalPositions[nearest][7], hospitalPositions[nearest][8], hospitalPositions[nearest][2], hospitalPositions[nearest][3], hospitalPositions[nearest][4]) setTimer( function() spawnPlayer(source, hospitalPositions[nearest][2], hospitalPositions[nearest][3], hospitalPositions[nearest][4], hospitalPositions[nearest][5], theSkin, 0, 0, theTeam) setCameraTarget(source) end, 5000, 1) end) Link to comment
Max+ Posted June 14, 2014 Share Posted June 14, 2014 local hospitalPositions = { --{name, x, y, z, r, cx, cy, cz} {"Los Santos 1", 1183.3, -1323, 13.58, 0, 1183.3, -1323, 18}, {"Los Santos 2", 2034.1, -1404.73, 17.25, 0, 2034.1, -1404.73, 22}, {"Montgomery", 1371.83, 405.94, 19.76, 0, 1371.83, 405.94, 25}, {"Blueberry", 207.5, -62.7, 1.6, 0, 207.5, -62.7, 7} }; addEventHandler("onPlayerWasted", root, function() local theSkin = getPedSkin(thePlayer) local theTeam = getPlayerTeam(thePlayer) local px, py, pz = getElementPosition(source) local nearest = 1 for k, v in pairs(hospitalPositions) do if(getDistanceBetweenPoints3D(v[2], v[3], v[4], px, py, pz) < getDistanceBetweenPoints3D(hospitalPositions[nearest][2], hospitalPositions[nearest][3], hospitalPositions[nearest][4], px, py, pz))then nearest = k end end setCameraMatrix(source, hospitalPositions[nearest][6], hospitalPositions[nearest][7], hospitalPositions[nearest][8], hospitalPositions[nearest][2], hospitalPositions[nearest][3], hospitalPositions[nearest][4]) setTimer( function() spawnPlayer(source, hospitalPositions[nearest][2], hospitalPositions[nearest][3], hospitalPositions[nearest][4], hospitalPositions[nearest][5], theSkin, 0, 0, theTeam) setCameraTarget(source) end, 5000, 1) end) thePlayer is not defined and getPedSkin This function is deprecated. use getElementModel insted Link to comment
Dzsozi (h03) Posted June 14, 2014 Author Share Posted June 14, 2014 Thank you very much for your help! You helped me alot! Thank you! Link to comment
Spajk Posted June 14, 2014 Share Posted June 14, 2014 @Max I just c/p-ed the code from above. Link to comment
Max+ Posted June 14, 2014 Share Posted June 14, 2014 @Max I just c/p-ed the code from above. I Know that , but i want you to be better than me , i really wish that , you Don't Need to Copy any one script , you can do it without them 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