Jump to content

Gui text issue


Franky

Recommended Posts

local gPlayer = getLocalPlayer ( ) 
local gVehicle = getPlayerOccupiedVehicle ( gPlayer ) 
  
function analyseGui ( ) 
    local engineSize = getElementData ( gVehicle, "engine.size" ) --sets it by car id. it the engine size in liters. example: 2.8 
    window = guiCreateWindow ( 0.25, 0.25, 0.5, 0.5, " Gui ", true ) 
    guiCreateLabel ( 0.05, 0.05, 0.3, 0.5, engineSize.. "liter", true, window )      
    guiWindowSetSizable ( analysegui, false ) 
    guiSetVisible ( analysegui, false ) 
end 
addEventHandler( "onClientResourceStart", getResourceRootElement ( getThisResource ( ) ), analyseGui ) 
  
function analyseCMD ( source, commandName ) 
    if ( gVehicle ) == false then 
        outputChatBox ( "You need to be in the car you want to analyse!", source, 255, 0, 0 ) 
    else 
        guiSetVisible ( analysegui, true ) 
        showCursor ( true ) 
    end 
end 
addCommandHandler ( "analyse", analyseCMD ) 

It gives and error "Bad Argument @ "getElementData" line 5

Can someone help?

Link to comment

Hmmm... I think this sould be in DM Server-Side? ;)

Anyway, I think that gVehicle is the problem. The player needs to be inside a vehicle on resource start. That may give trouble...

Wouldn't it be better that you create the GUI first, and edit it later? Also, do getPlayerOccupiedVehicle in the analyseCMD function. For this reason you might want to remove "local engineSize=.." and place it somewhere else.

Link to comment
Hmmm... I think this sould be in DM Server-Side? ;)

Anyway, I think that gVehicle is the problem. The player needs to be inside a vehicle on resource start. That may give trouble...

Wouldn't it be better that you create the GUI first, and edit it later? Also, do getPlayerOccupiedVehicle in the analyseCMD function. For this reason you might want to remove "local engineSize=.." and place it somewhere else.

It needs to be in client side because all GUI's are client side.. it sets the ElementData at server side script.. i have an idea so ill try it.. thanks..

Link to comment
Hmmm... I think this sould be in DM Server-Side? ;)

Anyway, I think that gVehicle is the problem. The player needs to be inside a vehicle on resource start. That may give trouble...

Wouldn't it be better that you create the GUI first, and edit it later? Also, do getPlayerOccupiedVehicle in the analyseCMD function. For this reason you might want to remove "local engineSize=.." and place it somewhere else.

It needs to be in client side because all GUI's are client side.. it sets the ElementData at server side script.. i have an idea so ill try it.. thanks..

Eh..? No I meant DM Server-side section on the forums! :P

Anyway, as I said: You need to be in a car on resource start. You just need another method... Because switching the car doesn't switch GUI right now... In fact, it's not updated at all... :?

Link to comment

getPlayerOccupiedVehicle will only retrieve the player's occupied vehicle at the instance it is executed. The "g_Vehicle" variable will not update with new vehicles.

In this case it is executed when the script is loaded - the player has no vehicle at this point and this is what you're passing into getElementData - false.

You need to use an event such as onClientVehicleEnter to update the variable.

Also, you'll need to update your GUI every time the vehicle is changed. You'll have to create a dummy GUI upon startup, and use guiSetVisible to hide it. Once you need to show it (i.e. the player entered a vehicle) make it visible again, THEN use getElementData and update the label using guiSetText

Link to comment
  • Recently Browsing   0 members

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