Hero192 Posted September 9, 2015 Share Posted September 9, 2015 (edited) Hey guys, today im making transport marker and i want make the price be as distance between player Position and markers Position Also i want the distance price shows on the gridlist i tried that but doesn't works anymore.. Please guys help me out Please try to help me i really stuck here --Server side: local markers = { --Markers table [1]={x=2220.43, y=2469.49, z=10.82, bx=2221.24, by=2468.76, blip=8, dim=0, int=0}, [2]={x=1625.00, y=1850.43, z=10.82, bx=1625.00, by=1850.43, blip=8, dim=0, int=0}, [3]={x= 1718.26, y=1484.68, z=10.82, bx=1718.26, by=1484.68, blip=8, dim=0, int=0}, [4]={x=1214.07, y=-1316.54, z=13.56, bx=1214.07, by=-1316.54, blip=8, dim=0, int=0}, } local moneyTable = { [1]={1111}, -- How to remplace the argument [1] in theTable by distance numbers as price [2]={1111}, [3]={1111}, [4]={1111}, } addEventHandler("onResourceStart",resourceRoot, function () for index, data in pairs(markers) do local zx, zy = getElementPosition(source) distance = getDistanceBetweenPoints2D(zx, zy, data.x, data.y) -- i tried but i failed local busmarker = createMarker(data.x, data.y, data.z-1, "cylinder", 1.5, 247,187, 7, 120) addEventHandler("onMarkerHit",busmarker,onMarkerHit) end end) addEvent ("warpplayer",true) addEventHandler ("warpplayer",root, function (ID) local cash = math.floor(distance / 2) if ( getPlayerMoney ( source ) < cash ) then outputChatBox (" You need ".. cash .."$ to use this service.", source, 255,0,0) else takePlayerMoney (source, cash ) end end) function onMarkerHit(hitPlayer) if ( getElementType ( hitPlayer ) == 'player' and not isPedInVehicle ( hitPlayer ) and not isPedDead ( hitPlayer ) ) then triggerClientEvent(hitPlayer,"showgui",hitPlayer,moneyTable) end end --Please try to help me i really stuck here Edited September 9, 2015 by Guest Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 Why are you getting the distance on resource start? Also, source in onResourceStart is the root element. Link to comment
Hero192 Posted September 9, 2015 Author Share Posted September 9, 2015 (edited) I fixed the code but i get only distance for one marker and not all markers and i want to show the cash based on distances to the gridlist help me please local moneyTable = { {1111}, -- How to remplace the argument [1] in theTable by distance numbers as price {1111}, {1111}, {1111}, } markerpos = {} playerpos = {} addEventHandler("onResourceStart",resourceRoot, function () for index, data in pairs(markers) do local busmarker = createMarker(data.x, data.y, data.z-1, "cylinder", 1.5,247,187, 7, 120) markerpos = { getElementPosition( busmarker ) } addEventHandler("onMarkerHit",busmarker,onMarkerHit) end end) addEvent ("warpplayer",true) addEventHandler ("warpplayer",root, function () local px, py, pz = unpack ( playerpos ) local mx, my, mz = unpack ( markerpos ) playerpos = { getElementPosition( source ) } local distance = getDistanceBetweenPoints2D ( px, py , mx, my ) local cash = math.floor(distance / 2) if ( getPlayerMoney ( source ) < cash ) then outputChatBox (" You need ".. cash .."$ to use this service.", source, 255,0,0) else takePlayerMoney (source, cash ) end end) Edited September 9, 2015 by Guest Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 Because you're always getting the position of the last busmarker created and setting it to the global variable 'markerpos'. The logic is not even close to being correct. You need to find the marker on warpplayer to get its position. Link to comment
Hero192 Posted September 9, 2015 Author Share Posted September 9, 2015 Can you please do it for me i tried alot of time before i post any thing but i fails Link to comment
Hero192 Posted September 9, 2015 Author Share Posted September 9, 2015 anyone can help me? Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 Post the rest of the code. Link to comment
Hero192 Posted September 9, 2015 Author Share Posted September 9, 2015 local markers = { --Markers table [1]={x=2220.43, y=2469.49, z=10.82, bx=2221.24, by=2468.76, blip=8, dim=0, int=0}, [2]={x=1625.00, y=1850.43, z=10.82, bx=1625.00, by=1850.43, blip=8, dim=0, int=0}, [3]={x= 1718.26, y=1484.68, z=10.82, bx=1718.26, by=1484.68, blip=8, dim=0, int=0}, [4]={x=1214.07, y=-1316.54, z=13.56, bx=1214.07, by=-1316.54, blip=8, dim=0, int=0}, } local moneyTable = { [1]={1111}, -- How to remplace the argument [1] in theTable by distance numbers as price [2]={1111}, [3]={1111}, [4]={1111}, } busmarker = {} playerpos = {} addEventHandler("onResourceStart",resourceRoot, function () for index, data in pairs(markers) do local busmarker = createMarker(data.x, data.y, data.z-1, "cylinder", 1.5,247,187, 7, 120) markerpos = { getElementPosition( busmarker ) } addEventHandler("onMarkerHit",busmarker,onMarkerHit) end end) addEvent ("warpplayer",true) addEventHandler ("warpplayer",root, function () local px, py, pz = unpack ( playerpos ) local mx, my, mz = unpack ( markerpos ) playerpos = { getElementPosition( source ) } local distance = getDistanceBetweenPoints2D ( px, py , mx, my ) local cash = math.floor(distance / 2) if ( getPlayerMoney ( source ) < cash ) then outputChatBox (" You need ".. cash .."$ to use this service.", source, 255,0,0) else takePlayerMoney (source, cash ) end end) function onMarkerHit(hitPlayer) if ( getElementType ( hitPlayer ) == 'player' and not isPedInVehicle ( hitPlayer ) and not isPedDead ( hitPlayer ) ) then triggerClientEvent(hitPlayer,"showgui",hitPlayer,moneyTable) end end Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 This is different from your original code. Is 'source' defined in warpplayer? local px, py, pz = getElementPosition(client) Link to comment
Hero192 Posted September 9, 2015 Author Share Posted September 9, 2015 so you mean that? still doing the same and the problem is when i selecte the gridlist to check the prices of markers distance it give me the same price.. you said: You need to find the marker on warpplayer to get its position. how to do that? addEvent ("warpplayer",true) addEventHandler ("warpplayer",root, function () local px, py, pz = getElementPosition(client) local mx, my, mz = unpack ( markerpos ) local distance = getDistanceBetweenPoints2D ( px, py , mx, my ) local cash = math.floor(distance / 2) if ( getPlayerMoney ( source ) < cash ) then outputChatBox (" You need ".. cash .."$ to use this service.", source, 255,0,0) else takePlayerMoney (source, cash ) end end) Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 You're already doing that. Check /debugscript 3 for errors. Post the client side script and make sure that source is defined. I suggest you start learning more. Link to comment
Hero192 Posted September 9, 2015 Author Share Posted September 9, 2015 There's no errors, client side: local root = getRootElement() local client = getLocalPlayer() buswindow = guiCreateWindow(419,244,500,287,"Bus",false) guiSetVisible (buswindow, false) guiWindowSetSizable(buswindow,false) busGrid = guiCreateGridList(9,20,482,224,false,buswindow) costColumn = guiGridListAddColumn(busGrid,"Price:",0.7) spawnBtn = guiCreateButton(17,247,157,31,"Spawn",false,buswindow) rejectBtn = guiCreateButton(329,247,157,31,"Cancel",false,buswindow) addEvent("showgui",true) addEventHandler("showgui",root, function (moneyTable) guiSetVisible(buswindow,true) showCursor(true) guiGridListClear(busGrid) for i,v in ipairs (moneyTable) do local row = guiGridListAddRow (busGrid) guiGridListSetItemText (busGrid, row, 1, v[1], false, false) end end) addEventHandler ("onClientGUIClick", root, function () if (source == rejectBtn) then guiSetVisible(buswindow,false) showCursor(false) elseif (source == spawnBtn) then local row,col = guiGridListGetSelectedItem(busGrid) if row and col and row ~= -1 and col ~= -1 then guiSetVisible(buswindow,false) showCursor(false) triggerServerEvent("warpplayer",client,guiGridListGetSelectedItem(busGrid)+1) end end end) Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 Your code is a total mess. Like I said, you should try to learn more. @line33 client is not defined, and you're sending the selected item but you're doing nothing with it server-side. I can't help you if none of your code make any sense. Link to comment
Hero192 Posted September 9, 2015 Author Share Posted September 9, 2015 If i was good i wasn't going to post this topic, i posted this to find someone who can give me his hand and help me out to correct and learn from my fails , be sure next time i can't do the same fail if you helped me Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 My point is, instead of bumping into errors, warnings and logical faults, learning the basics and looking at examples can make it much easier. Link to comment
Hero192 Posted September 9, 2015 Author Share Posted September 9, 2015 client is defined with localPlayer, look at the top of my code and i know basic lua scripting .. my problem is with mta functions 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