Jump to content

[HELP] Need help with if text == "Admiral" then


ViPeR124

Recommended Posts

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 :x

Greets

Link to comment
  • MTA Team

@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 by Guest
Link to comment
@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

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
  
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

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 by Guest
Link to comment

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...