xUltimate Posted January 15, 2011 Share Posted January 15, 2011 carshop = createMarker(1751.32, -2055.36, 12.71, "cylinder", 1, 0, 255, 0, 180) carshopcol = createColSphere ( 1751.32, -2055.36, 13.71, 1 ) function showGUI() GUIEditor_Window = {} GUIEditor_Button = {} GUIEditor_Grid = {} GUIEditor_Window[1] = guiCreateWindow(558,219,302,324,"Los Santos Car Shop",false) GUIEditor_Grid[1] = guiCreateGridList(10,26,283,244,false,GUIEditor_Window[1]) guiGridListSetSelectionMode(GUIEditor_Grid[1],2) guiGridListAddRow(GUIEditor_Grid[1]) guiGridListAddColumn(GUIEditor_Grid[1],"Vehicle",0.2) guiGridListAddColumn(GUIEditor_Grid[1],"Price",0.2) GUIEditor_Button[1] = guiCreateButton(17,295,73,20,"Purchase",false,GUIEditor_Window[1]) GUIEditor_Button[2] = guiCreateButton(219,294,73,20,"Cancel",false,GUIEditor_Window[1]) end addEventHandler("onColShapeHit", carshopcol, showGUI) Its supposed to show the GUI window when someone enters the colsphere but it doesnt. Link to comment
Scooby Posted January 15, 2011 Share Posted January 15, 2011 looks like you have a lot more work to do here but i guess untill u can see the gui, thats gonna be hard. you should try to find how far your script is getting by using outputDebugString("moo") in certain places of ur script. does the showGUI function get triggered as u hit the colshape? does the gui get created and u just cant see it? i dont know if its the right way, but what i do is create the GUI on client start, then use guiSetVisible(myGUI,true) when i need it to be seen. u look like uve made a good start so i wont post a fix for this just yet, have a try adding some debug lines to see if u can find where its going wrong. the marker or colshape will both work. (i use a marker in my server) Link to comment
SDK Posted January 15, 2011 Share Posted January 15, 2011 onColShapeHit doesn't exist clientside, it's onClientColShapeHit. But as Scooby suggests, use onClientResourceStart to create the window and setElementVisible when entering the colshape. Link to comment
xUltimate Posted January 16, 2011 Author Share Posted January 16, 2011 Ok, haha i'll try that sorry if anything i ask is newby, im really new to working with GUI. EDIT: Great it works when someone walks in the marker, but how would I go about loading a xml or a file that has a list like "Sultan", "95000"; "Rancher", "50000"; and it loads the data into the grid and displays it? Link to comment
Scooby Posted January 17, 2011 Share Posted January 17, 2011 maybe it'll be easier for you to work with the car details stored to your script for now, at least until you have the gui grid loading them all ok. you could do something like this, then after you can work on loading it from xml if u want. I load them this way in my script, new saw the need to load them from xml. you can easily get all the vehicle ID's off the wiki and add ur own prices to them to suit ur needs. Im not sure how ur current script is, so just call this function to load the cars into the gridlist. (you may need to alter the column widths) local cars = { 400, 401, 402, 404, 405, 409, 410, 411 } local prices = { 5995, 4995, 6995, 3495, 7999, 34995, 7995, 125000 } function createCarList() local column1 = guiGridListAddColumn(GUIEditor_Grid[1], "Vehicle", 0.50) local column2 = guiGridListAddColumn(GUIEditor_Grid[1], "price", 0.40) if (column1 and column2) then for a = 1,#cars do local name = getVehicleNameFromModel(cars[a]) local prices = tostring(price[a]) local row = guiGridListAddRow (GUIEditor_Grid[1]) if name ~= "" then guiGridListSetItemText (GUIEditor_Grid[1], row, column1, name, false, false) guiGridListSetItemText (GUIEditor_Grid[1], row, column2, prices, false, false) end end end end Link to comment
xUltimate Posted January 17, 2011 Author Share Posted January 17, 2011 Using carshop = createMarker(1751.32, -2055.36, 12.71, "cylinder", 1, 0, 255, 0, 180) carshopcol = createColSphere ( 1751.32, -2055.36, 13.71, 1 ) local cars = { 400, 401, 402, 404, 405, 409, 410, 411 } local prices = { 5995, 4995, 6995, 3495, 7999, 34995, 7995, 125000 } addEventHandler("onClientResourceStart", resourceRoot, function() Window = {} Button = {} Grid = {} Window[1] = guiCreateWindow(558, 219, 302, 324, "Los Santos Car Shop", false) Grid[1] = guiCreateGridList(10, 26, 283, 244, false, Window[1]) guiGridListSetSelectionMode(Grid[1], 2) local column1 = guiGridListAddColumn(Grid[1], "Vehicle", 0.50) local column2 = guiGridListAddColumn(Grid[1], "Price", 0.40) if (column1 and column2) then for a = 1,#cars do local name = getVehicleNameFromModel(cars[a]) local prices = tostring(prices[a]) local row = guiGridListAddRow(Grid[1]) if name ~= "" then guiGridListSetItemText(Grid[1], row, column1, name, false, false) guiGridListSetItemText(Grid[1], row, column2, prices, false, false) end end end Button[1] = guiCreateButton(17, 295, 73, 20, "Purchase", false, Window[1]) Button[2] = guiCreateButton(219, 294, 73, 20, "Cancel", false, Window[1]) guiSetVisible( Window[1], false ) addEventHandler("onClientGUIClick", Button[1], purchaseCar, false ) addEventHandler("onClientGUIClick", Button[2], hideGUI, false ) ------------------------------------------------------------------------------------ end ) function showGUI() guiSetVisible( Window[1], true ) end addEventHandler("onClientColShapeHit",getRootElement(),showGUI) function hideGUI() guiSetVisible( Window[1], false ) end function purchaseCar() guiSetVisible( Window[1], false ) local sig = guiGridListGetSelectedItem(Grid[1]) local price = guiGridListGetItemText(Grid[1], sig, column2) if exports.players:takeMoney(client, price) then -- try to create a permanent one local car = guiGridListGetItemText(Grid[1], sig1, column1) local vehicle, vehicleID = exports.vehicles:create(client, car) if vehicle then local vehname = getVehicleName(vehicle) outputChatBox( "Congratulations! You've bought a " .. vehname .. "!", client, 255, 127, 0 ) outputChatBox( "Remember to use /park to set a permanent spawn position for this vehicle.", client, 255, 255, 0 ) spawnVehicle(vehicle, 1758.65, -2056.82, 13.58, 0, 0, 0) -- give him the keys exports.items:give( client, 1, vehicleID, vehname ) else -- failed somewhere exports.players:giveMoney( client, price ) end else outputChatBox( "A error occured, this was expected.", source, 255, 0, 0 ) end end It is unable to get the price from the text and prints out in the debug "ERROR: call: failed to call 'players:takeMoney' [string "?"]" Link to comment
Scooby Posted January 17, 2011 Share Posted January 17, 2011 local price = guiGridListGetItemText(Grid[1], sig, column2) this will return a string, try using local price = tonumber(guiGridListGetItemText(Grid[1], sig, column2)) Link to comment
xUltimate Posted January 17, 2011 Author Share Posted January 17, 2011 Still the same problem Link to comment
SDK Posted January 17, 2011 Share Posted January 17, 2011 It seems like you're mixing up serverside and clientside scripts. These exported functions from 'players', 'items' and 'vehicles', are you sure they're clientside? Maybe you should be reminded that only the GUI scripts should run clientside, all other scripts like buying and spawning are supposed to be triggered serverside (in an other script file) using events. Link to comment
xUltimate Posted January 18, 2011 Author Share Posted January 18, 2011 Oh sh*t, I forgot about that haha. Going to change it to trigger serverside. EDIT: Ok did that but now it just does nothing. Client: carshop = createMarker(1751.32, -2055.36, 12.71, "cylinder", 1, 0, 255, 0, 180) carshopcol = createColSphere ( 1751.32, -2055.36, 13.71, 1 ) local cars = { 400, 401, 402, 404, 405, 409, 410, 411 } local prices = { 5995, 4995, 6995, 3495, 7999, 34995, 7995, 125000 } addEventHandler("onClientResourceStart", resourceRoot, function() Window = {} Button = {} Grid = {} Window[1] = guiCreateWindow(558, 219, 302, 324, "Los Santos Car Shop", false) Grid[1] = guiCreateGridList(10, 26, 283, 244, false, Window[1]) guiGridListSetSelectionMode(Grid[1], 2) local column1 = guiGridListAddColumn(Grid[1], "Vehicle", 0.50) local column2 = guiGridListAddColumn(Grid[1], "Price", 0.40) if (column1 and column2) then for a = 1,#cars do local name = getVehicleNameFromModel(cars[a]) local prices = tostring(prices[a]) local row = guiGridListAddRow(Grid[1]) if name ~= "" then guiGridListSetItemText(Grid[1], row, column1, name, false, false) guiGridListSetItemText(Grid[1], row, column2, prices, false, false) end end end Button[1] = guiCreateButton(17, 295, 73, 20, "Purchase", false, Window[1]) Button[2] = guiCreateButton(219, 294, 73, 20, "Cancel", false, Window[1]) guiSetVisible( Window[1], false ) addEventHandler("onClientGUIClick", Button[1], callServerPurchase, false ) addEventHandler("onClientGUIClick", Button[2], hideGUI, false ) end ) function showGUI() guiSetVisible( Window[1], true ) end addEventHandler("onClientColShapeHit",getRootElement(),showGUI) function hideGUI() guiSetVisible( Window[1], false ) end function callServerPurchase() local sig = guiGridListGetSelectedItem(Grid[1]) local price = tonumber(guiGridListGetItemText(Grid[1], sig, column2)) local car = guiGridListGetItemText(Grid[1], sig1, column1) setElementData(source, "price", price) setElementData(source, "thecar", car) triggerServerEvent( "purchaseCar", source ) guiSetVisible( Window[1], false ) end Server: addEvent( "purchaseCar", true ) addEventHandler( "purchaseCar", root, function (source) local price = getElementData(source, "price") local car = getElementData(source, "thecar") if exports.players:takeMoney(source, price) then -- try to create a permanent one local vehicle, vehicleID = exports.vehicles:create(source, car) if vehicle then local vehname = getVehicleName(vehicle) outputChatBox( "Congratulations! You've bought a " .. vehname .. "!", source, 255, 127, 0 ) outputChatBox( "Remember to use /park to set a permanent spawn position for this vehicle.", source, 255, 255, 0 ) spawnVehicle(vehicle, 1758.65, -2056.82, 13.58, 0, 0, 0) -- give him the keys exports.items:give( source, 1, vehicleID, vehname ) else -- failed somewhere exports.players:giveMoney( source, price ) end else outputChatBox( "A error occured, this was expected.", source, 255, 0, 0 ) end end ) Link to comment
Aibo Posted January 18, 2011 Share Posted January 18, 2011 «source» of GUI events are GUI elements, not the players, since those events are clientside and only one player (local player) can actually «create» them. right now you're setting element data of a GUI element and trying to get this data from this GUI element on the server side (?). also «source» is a hidden variable passed to event handler functions, you dont need «function(source)» — this will overwrite it with nil, because your event has no arguments. PS: why dont you use event arguments instead of element data anyway? Link to comment
xUltimate Posted January 19, 2011 Author Share Posted January 19, 2011 Funny, I don't even remember adding the (source) part lol. 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