Dzsozi (h03) Posted December 6, 2014 Share Posted December 6, 2014 Hello everybody! I have a little problem with my script. I don't know how to name the player who is in a spawned car. It's not working. I mean I've got this on server side: function missionFailed(thePlayer) if (isElement(Vehicles.car)) then triggerClientEvent(thePlayer, "mission:Failed", thePlayer) createRandomCar() toggleControl(thePlayer, "enter_exit", true) destroyElement(missionTimer) for i,v in pairs(Vehicles) do destroyElement(v) end for i,v in pairs(Markers) do destroyElement(v) end for i,v in pairs(Blips) do destroyElement(v) end end end And I have this error: Why? I've even tried source instead of thePlayer, but I always got this problem. Everything is fine except this. Car, marker and blip are being deleted, a new car is being spawned, but I don't get the mission failed client event (there's no problem on the client side) and I can't enter vehicles (enter_exit is still being disabled). Could someone help me in this? I never understand this thing on server side, how to name a player when there's no onMarkerHit event or something like this. Thank you in advance! Link to comment
Bssol Posted December 6, 2014 Share Posted December 6, 2014 The problem is in the 'thePlayer' variable, it's a 'nil' value You have to post your whole code so we can fix your problem Link to comment
Dzsozi (h03) Posted December 6, 2014 Author Share Posted December 6, 2014 Could you please explain why I have to post my full code if there's only problem within the function that I've posted? I'm just curious. Link to comment
Bssol Posted December 6, 2014 Share Posted December 6, 2014 Because it's clear that the variable 'thePlayer' is recived from another place in your code. Your posted code is fine, so the problem is coming from the caller of this function. Link to comment
Dzsozi (h03) Posted December 6, 2014 Author Share Posted December 6, 2014 Is it okay if we continue the conversation in PM? Link to comment
Dzsozi (h03) Posted December 7, 2014 Author Share Posted December 7, 2014 I've got this problem again with another script. I can't define the player, I've tried thePlayer, player, source, but nothing seems to work. Why? What's the problem? (full code) local hospitalPositions = { --{name, x, y, z, r, cx, cy, cz} {"Los Santos Market", 1178.291015625, -1324.1884765625, 14.112809181213, 270.10269165039, 1219.5555419922, -1350.3894042969, 15.35106754303}, {"Los Santos Jefferson", 2033.3256835938, -1407.6052246094, 17.178876876831, 155.35185241699, 1995.7249755859, -1463.2962646484, 17.878829956055}, {"Flint County", -595.72711181641, -1077.2752685547, 23.602161407471, 266.27713012695, -591.57257080078, -1131.4045410156, 41.221168518066}, {"Red County", -942.13061523438, -533.36236572266, 25.953638076782, 310.40444946289, -964.28985595703, -549.99957275391, 36.916095733643}, {"Santa Flora", -2656.9560546875, 631.52252197266, 14.453125, 180.42951965332, -2575.8940429688, 561.90728759766, 21.209178924561}, {"Angel Pine", -2202.5417480469, -2254.626953125, 30.681533813477, 216.4725189209, -2200.2456054688, -2275.5190429688, 38.479064941406}, {"Montgomery", 1244.2723388672, 331.79971313477, 19.5546875, 334.32315063477, 1272.0018310547, 345.42361450195, 30.568145751953}, {"Blueberry", 207.5835723877, -62.355804443359, 1.7481514215469, 179.15745544434, 231.66580200195, -91.108108520508, 18.604141235352}, {"Fort Carson", -318.32772827148, 1052.3748779297, 20.340259552002, 330.99075317383, -293.86444091797, 1075.7722167969, 20.491537094116}, {"Las Venturas Airport", 1604.7628173828, 1821.8123779297, 10.8203125, 352.52377319336, 1570.9233398438, 1859.9248046875, 11.351891517639}, {"Las Payasadas", -251.56652832031, 2602.4379882813, 62.858154296875, 311.32571411133, -226.53842163086, 2567.9504394531, 69.399459838867}, {"El Quebrados", -1515.0689697266, 2521.9731445313, 55.841911315918, 359.86227416992, -1506.4434814453, 2546.1689453125, 56.440139770508} }; function onWasted(totalAmmo, killer, killerWeapon, bodypart, stealth) if not( isGuestAccount (getPlayerAccount(source)) ) then local theSkin = getPedSkin(source) local theTeam = getPlayerTeam(source) local theWeapon = getPedWeapon (source) local weaponAmmo = getPedTotalAmmo (source) 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 fadeCamera(source, false, 2) setTimer( function() setCameraMatrix(source, hospitalPositions[nearest][6], hospitalPositions[nearest][7], hospitalPositions[nearest][8], hospitalPositions[nearest][2], hospitalPositions[nearest][3], hospitalPositions[nearest][4]) fadeCamera(source, true, 2) setTimer( function() fadeCamera(source, false, 2) end, 2000, 1) end, 2000, 1) setTimer( function() spawnPlayer(source, hospitalPositions[nearest][2], hospitalPositions[nearest][3], hospitalPositions[nearest][4], hospitalPositions[nearest][5], theSkin, 0, 0, theTeam) giveWeapon(source, theWeapon, weaponAmmo) setCameraTarget(source) end, 6000, 1) end end addEventHandler ("onPlayerWasted", root, onWasted) Link to comment
Anubhav Posted December 7, 2014 Share Posted December 7, 2014 local hospitalPositions = { --{name, x, y, z, r, cx, cy, cz} {"Los Santos Market", 1178.291015625, -1324.1884765625, 14.112809181213, 270.10269165039, 1219.5555419922, -1350.3894042969, 15.35106754303}, {"Los Santos Jefferson", 2033.3256835938, -1407.6052246094, 17.178876876831, 155.35185241699, 1995.7249755859, -1463.2962646484, 17.878829956055}, {"Flint County", -595.72711181641, -1077.2752685547, 23.602161407471, 266.27713012695, -591.57257080078, -1131.4045410156, 41.221168518066}, {"Red County", -942.13061523438, -533.36236572266, 25.953638076782, 310.40444946289, -964.28985595703, -549.99957275391, 36.916095733643}, {"Santa Flora", -2656.9560546875, 631.52252197266, 14.453125, 180.42951965332, -2575.8940429688, 561.90728759766, 21.209178924561}, {"Angel Pine", -2202.5417480469, -2254.626953125, 30.681533813477, 216.4725189209, -2200.2456054688, -2275.5190429688, 38.479064941406}, {"Montgomery", 1244.2723388672, 331.79971313477, 19.5546875, 334.32315063477, 1272.0018310547, 345.42361450195, 30.568145751953}, {"Blueberry", 207.5835723877, -62.355804443359, 1.7481514215469, 179.15745544434, 231.66580200195, -91.108108520508, 18.604141235352}, {"Fort Carson", -318.32772827148, 1052.3748779297, 20.340259552002, 330.99075317383, -293.86444091797, 1075.7722167969, 20.491537094116}, {"Las Venturas Airport", 1604.7628173828, 1821.8123779297, 10.8203125, 352.52377319336, 1570.9233398438, 1859.9248046875, 11.351891517639}, {"Las Payasadas", -251.56652832031, 2602.4379882813, 62.858154296875, 311.32571411133, -226.53842163086, 2567.9504394531, 69.399459838867}, {"El Quebrados", -1515.0689697266, 2521.9731445313, 55.841911315918, 359.86227416992, -1506.4434814453, 2546.1689453125, 56.440139770508} }; function onWasted(totalAmmo, killer, killerWeapon, bodypart, stealth) if not( isGuestAccount (getPlayerAccount(source)) ) then local theSkin = getPedSkin(source) local theTeam = getPlayerTeam(source) local theWeapon = getPedWeapon (source) local weaponAmmo = getPedTotalAmmo (source) 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 fadeCamera(source, false, 2) setTimer( function( source ) setCameraMatrix(source, hospitalPositions[nearest][6], hospitalPositions[nearest][7], hospitalPositions[nearest][8], hospitalPositions[nearest][2], hospitalPositions[nearest][3], hospitalPositions[nearest][4]) fadeCamera(source, true, 2) setTimer( function( source ) fadeCamera(source, false, 2) end, 2000, 1, source) end, 2000, 1, source) setTimer( function( source ) spawnPlayer(source, hospitalPositions[nearest][2], hospitalPositions[nearest][3], hospitalPositions[nearest][4], hospitalPositions[nearest][5], theSkin, 0, 0, theTeam) giveWeapon(source, theWeapon, weaponAmmo) setCameraTarget(source) end, 6000, 1, source) end end addEventHandler ("onPlayerWasted", root, onWasted) Link to comment
Dzsozi (h03) Posted December 7, 2014 Author Share Posted December 7, 2014 Oh my god, finally, thank you! I appreciate it! Link to comment
Anubhav Posted December 7, 2014 Share Posted December 7, 2014 Oh my god, finally, thank you! I appreciate it! No problem 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