Jump to content

[Problem]Progress bar


Recommended Posts

i tried it .

my script is farmer job and the progress bar appear when you get in the tractor so its says the "progress bar not found" all what i want to do is that the progress bar increases when the tractor move . (and im not seeing the progress bar increasing in game)

Link to comment
Try like this ,
progressBar = guiCreateProgressBar( 0.75, 0.3, 1, 1, true, nil ) 
guiProgressBarSetProgress(progressBar,tonumber(guiProgressBarGetProgress(progressBar))+1) 

it worked , but i want to increase the value of progress bar when the car move only

Link to comment

New to scripting.. but try this..

  
function () 
local vehicle = getPedOccupiedVehicle( localPlayer ) 
if vehicle == 531 then 
if vehicle and getVehicleOccupant( vehicle, 0 ) == localPlayer and getVehicleEngineState( vehicle ) == true and getElementSpeed( vehicle ) > 1 then 
guiProgressBarSetProgress(progressBar , +1) 
else  
    outputChatBox ("progressbar not found!") 
        
end     
end 
end 
) 

Link to comment

These are the functions to make your script ,

getVehicleEngineState --- if the vehicle are on 
getPedOccupiedVehicle ----- if ped in the vehicle  
[url=https://wiki.multitheftauto.com/wiki/GetElementSpeed]https://wiki.multitheftauto.com/wiki/GetElementSpeed[/url]---- get the vehicle speed  
guiProgressBarGetProgress ---- get the bar valute form 0  
guiProgressBarSetProgress --- set it for an example 100  

Link to comment
New to scripting.. but try this..
  
function () 
local vehicle = getPedOccupiedVehicle( localPlayer ) 
if vehicle == 531 then 
if vehicle and getVehicleOccupant( vehicle, 0 ) == localPlayer and getVehicleEngineState( vehicle ) == true and getElementSpeed( vehicle ) > 1 then 
guiProgressBarSetProgress(progressBar , +1) 
else  
    outputChatBox ("progressbar not found!") 
        
end     
end 
end 
) 

not working :/

Link to comment
These are the functions to make your script ,
getVehicleEngineState --- if the vehicle are on 
getPedOccupiedVehicle ----- if ped in the vehicle  
[url=https://wiki.multitheftauto.com/wiki/GetElementSpeed]https://wiki.multitheftauto.com/wiki/GetElementSpeed[/url]---- get the vehicle speed  
guiProgressBarGetProgress ---- get the bar valute form 0  
guiProgressBarSetProgress --- set it for an example 100  

This thing is perfect go for it

Link to comment
These are the functions to make your script ,
getVehicleEngineState --- if the vehicle are on 
getPedOccupiedVehicle ----- if ped in the vehicle  
[url=https://wiki.multitheftauto.com/wiki/GetElementSpeed]https://wiki.multitheftauto.com/wiki/GetElementSpeed[/url]---- get the vehicle speed  
guiProgressBarGetProgress ---- get the bar valute form 0  
guiProgressBarSetProgress --- set it for an example 100  

This thing is perfect go for it

i Can't do it :/ (i tried)

Link to comment
You said you tried, show us what you tried.

function move (player, seat, jacked ) 
local vehicle = getPedOccupiedVehicle( localPlayer ) 
if vehicle == 531 then 
if vehicle and getVehicleOccupant( vehicle, 0 ) == localPlayer and getVehicleEngineState( vehicle ) == true and getElementSpeed( vehicle ) > 1 then 
guiProgressBarSetProgress(progressBar , +1)      
end    
end 
end 
) 
addEventHandler( "onClientVehicleEnter", getRootElement(), move ) 
  

this is not working.

Link to comment

There are many problems in that script.

1: 'vehicle' is a element, not a number, you must use getElementModel to get it's model.

2: getElementSpeed is not defined anywhere, since this is not a MTA native function, you must define it.

3: At guiProgressBarSetProgress, you forgot to get the current bar progress, in order to increase it.

Link to comment
There are many problems in that script.

1: 'vehicle' is a element, not a number, you must use getElementModel to get it's model.

2: getElementSpeed is not defined anywhere, since this is not a MTA native function, you must define it.

3: At guiProgressBarSetProgress, you forgot to get the current bar progress, in order to increase it.

i have a question about getElementSpeed it's like removed from mta ?

how to define it as you said ?

Link to comment

whats wrong ?

function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.8 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 

function speed(element, unit, speed)  
    if (unit == nil) then unit = 0 end 
    if (speed == nil) then speed = 0 end 
    speed = tonumber(speed) 
    local acSpeed = getElementSpeed(element, unit) 
    if (acSpeed~=false) then 
        local diff = speed/acSpeed 
        local x,y,z = getElementVelocity(element) 
        setElementVelocity(element,x*diff,y*diff,z*diff) 
                guiProgressBarSetProgress(progressBar,tonumber(guiProgressBarGetProgress(progressBar))+1) 
    outputChatBox ( "Red #FFFFFFWhite", getRootElement(), 255, 0, 0, true ) 
        return true 
    end 
    return false 
end  
addEventHandler( "onClientVehicleEnter", getRootElement(), getElementSpeed ) 
addEventHandler( "onClientVehicleEnter", getRootElement(), speed ) 
setTimer ( speed, 1000, 100) 

help please :)

Link to comment
whats wrong ?

function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.8 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 

function speed(element, unit, speed)  
    if (unit == nil) then unit = 0 end 
    if (speed == nil) then speed = 0 end 
    speed = tonumber(speed) 
    local acSpeed = getElementSpeed(element, unit) 
    if (acSpeed~=false) then 
        local diff = speed/acSpeed 
        local x,y,z = getElementVelocity(element) 
        setElementVelocity(element,x*diff,y*diff,z*diff) 
                guiProgressBarSetProgress(progressBar,tonumber(guiProgressBarGetProgress(progressBar))+1) 
    outputChatBox ( "Red #FFFFFFWhite", getRootElement(), 255, 0, 0, true ) 
        return true 
    end 
    return false 
end  
addEventHandler( "onClientVehicleEnter", getRootElement(), getElementSpeed ) 
addEventHandler( "onClientVehicleEnter", getRootElement(), speed ) 
setTimer ( speed, 1000, 100) 

help please :)

no one ?

Link to comment

firstly this is wrong :

addEventHandler( "onClientVehicleEnter", getRootElement(), getElementSpeed )

you are trying to call the function getElementSpeed with the parameters : player and seat that the event onClientVehicleEnter gives to the function (sorry for my bad english). Therefore, erase this line.

Secondly;

same mistake here too

addEventHandler( "onClientVehicleEnter", getRootElement(), speed )

heres a tip of how you should do it :

function speed(player, seat)

local vspeed = getElementSpeed(source,"mph")

if vspeed then

.... -- now you continue with the function

end

addEventHandler("onClientVehicleEnter",getRootElement(),speed)

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