ViPeR124 Posted January 21, 2014 Share Posted January 21, 2014 Hey guys, I'm new in scripting for mta but i have some know how in LUA. Only one little function in my script is not working well. I created a gui with a ComboBox and a Button. In the ComboBox i added the item 'Admiral'. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () wdwVeh = guiCreateWindow(32, 245, 264, 495, "Auto aus wählen:", false) cbmVeh = guiCreateComboBox(427, 80, 0, 15, "", false, wdwVeh) cbmVeh2 = guiCreateComboBox(10, 24, 244, 423, "", false, wdwVeh) guiComboBoxAddItem(cbmVeh2, "Admiral") btnVeh = guiCreateButton(172, 457, 82, 28, "Wählen", false, wdwVeh) guiSetVisible(wdwVeh, false) addEventHandler("onClientGUIClick", btnVeh, chooseVehicle, button ) end ) The gui is working. Everything shows up when i press 'x' (bindkey). But i have added a function to the ButtonClick event which is called "chooseVehicle" function chooseVehicle( button ) local text = guiComboBoxGetSelected(cbmVeh2) if text == "Admiral" then triggerServerEvent ( "cbmVeh", localPlayer) else outputChatBox("It's not working :C") end showCursor(false) guiSetVisible(wdwVeh, false) end so and in this part of my code i have a problem. if the selected item is "admiral" then I want to spawn an Admiral but it ever shows the 'It's not working :C' but i don't know why. If I try this: outputChatBox(''..text..'') it shows the Admiral in the chat. So is someone there who knows where the problem is? And sorry for my bad english i'm German Greets Link to comment
Dealman Posted January 21, 2014 Share Posted January 21, 2014 That only returns the selected index of the ComboBox. guiComboBoxGetItemText gets the text of an item. Make it; local theItem = guiComboBoxGetSelected(cbmVeh2) local theText = guiComboBoxGetItemText(cbmVeh2, theItem) Link to comment
MTA Team 0xCiBeR Posted January 21, 2014 MTA Team Share Posted January 21, 2014 (edited) @Dealman if it is returning the correct string, there is also a problem somewhere else, and the variable is actually returning the correct string asi seen in: If I try this: outputChatBox(''..text..'') it shows the Admiral in the chat. Post us the server-side Script. Edit: Seems as it fixed it, my bad. Edited January 21, 2014 by Guest Link to comment
ViPeR124 Posted January 21, 2014 Author Share Posted January 21, 2014 thank you Dealman for the quick reply! It's working now. Thank you very much! Link to comment
Dealman Posted January 21, 2014 Share Posted January 21, 2014 @Dealman if it is returning the correct string, there is also a problem somewhere else, and the variable is actually returning the correct string asi seen in: If I try this: outputChatBox(''..text..'') it shows the Admiral in the chat. Post us the server-side Script. Fair enough, missed that part. But I still fail to see why server-side code matters? It never succeeds to trigger the event, the if statement fails - thus it always outputs the message. Server-side code should not matter. Link to comment
MTA Team 0xCiBeR Posted January 21, 2014 MTA Team Share Posted January 21, 2014 Actually it is passing the IF statement, beacuse if it wasn't, it wouldn't output "Admiral" Anyway, it's fixed Link to comment
Dealman Posted January 21, 2014 Share Posted January 21, 2014 If it passed the if statement, it wouldn't trigger whatever code is after else... Maybe outputChatBox retrieves the text of the item automatically...? Link to comment
ViPeR124 Posted January 21, 2014 Author Share Posted January 21, 2014 ok my mistake it is not working ._. I copied the triggerServerEvent under the else... function chooseVehicle( button ) local theItem = guiComboBoxGetSelected(cbmVeh2) local theText = guiComboBoxGetItemText(cbmVeh2, theITem) if theText == 'Admiral' then triggerServerEvent ( "admiral", localPlayer) else outputChatBox('It is not working!') end showCursor(false) guiSetVisible(wdwVeh, false) end Thats the new code and it is not working at all. I don't know what to do ... Link to comment
MTA Team 0xCiBeR Posted January 21, 2014 MTA Team Share Posted January 21, 2014 Post the server-side script.(where the "admiral" event is added) Link to comment
ViPeR124 Posted January 21, 2014 Author Share Posted January 21, 2014 function admiral() local sx, sy ,sz = getElementPosition(PlayerSource) local name = getPlayerName(source) local veh = createVehicle(445, sx, sy, sz, 0, 0 ,90, name) warpPedIntoVehicle(source, veh) end Thats the admiral event Link to comment
MTA Team 0xCiBeR Posted January 21, 2014 MTA Team Share Posted January 21, 2014 function admiral() local sx, sy ,sz = getElementPosition(source) local name = getPlayerName(source) local veh = createVehicle(445, sx, sy, sz, 0, 0 ,90, name) warpPedIntoVehicle(source, veh) end PD: If it's posible please use LUA tags..It's easier to read. Thanks! Link to comment
ViPeR124 Posted January 21, 2014 Author Share Posted January 21, 2014 (edited) This is not working at all. I think the problem is in this code: function chooseVehicle( button ) local theItem = guiComboBoxGetSelected(cbmVeh2) local theText = guiComboBoxGetItemText(cbmVeh2, theITem) if theText == 'Admiral' then triggerServerEvent ( "admiral", localPlayer) else outputChatBox('It is not working!') end showCursor(false) guiSetVisible(wdwVeh, false) end Because it seems that the result of if theText == 'Admiral' then returns a false. But i don't know why Edited January 21, 2014 by Guest Link to comment
MTA Team 0xCiBeR Posted January 21, 2014 MTA Team Share Posted January 21, 2014 Oh now that's a problem. Then probably you have a problem with the GUI, or the variables you put in the functions. Link to comment
ViPeR124 Posted January 21, 2014 Author Share Posted January 21, 2014 hmm ok i will try to create a gui with the guieditor. Maybe it will fix my problem Link to comment
ViPeR124 Posted January 21, 2014 Author Share Posted January 21, 2014 Okay I solved the Problem. I used the Item ID and it is working Perfectly. function chooseVehicle( button ) local theItemID = guiComboBoxGetSelected(GUIEditor.combobox[2]) if theItemID == 0 then triggerServerEvent ( "admiral", localPlayer) else outputChatBox('Something went wrong!') end showCursor(false) guiSetVisible(GUIEditor.window[1], false) end Link to comment
ViRuZGamiing Posted January 21, 2014 Share Posted January 21, 2014 Maybe it was because of the IT that needed to be It, local theText = guiComboBoxGetItemText(cbmVeh2,theITem-- theItem Link to comment
ViPeR124 Posted January 22, 2014 Author Share Posted January 22, 2014 Maybe it was because of the IT that needed to be It, local theText = guiComboBoxGetItemText(cbmVeh2,theITem-- theItem no it's not because of the IT only the I is written in a capital letter not the t... 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