Jump to content

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


ViPeR124

Recommended Posts

Posted

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

Posted

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) 

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

  • MTA Team
Posted (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 by Guest

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 
Posted
@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.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

  • MTA Team
Posted

Actually it is passing the IF statement, beacuse if it wasn't, it wouldn't output "Admiral"

Anyway, it's fixed :)

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 
Posted

If it passed the if statement, it wouldn't trigger whatever code is after else... Maybe outputChatBox retrieves the text of the item automatically...? :roll:

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

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

  • MTA Team
Posted

Post the server-side script.(where the "admiral" event is added)

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 
Posted

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

  • MTA Team
Posted
  
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!

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 
Posted (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 by Guest
  • MTA Team
Posted

Oh now that's a problem. Then probably you have a problem with the GUI, or the variables you put in the functions.

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 
Posted

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 

Posted

Maybe it was because of the IT that needed to be It,

local theText = guiComboBoxGetItemText(cbmVeh2,theITem-- theItem 

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

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

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