Jump to content

Problems with Values.


WolfPire

Recommended Posts

So... I'm trying to create an hospital, but i can't seem to change the text of the Fee. I get a "nil" value somehow.

Check the code out and help me if you can please.

HospitalSF = createColSphere(-2654, 639, 15, 1) 
HospitalLV = createColSphere(1608, 1817, 11, 1) 
HospitalFC = createColSphere(-320, 1051, 21, 1) 
HospitalM = createColSphere(1243, 329, 20, 1) 
HospitalLS1 = createColSphere(2035, -1404, 18, 1) 
HospitalLS2 = createColSphere(1174, -1323, 16, 1) 
  
function Heal() 
    if Money < fee then 
    outputChatBox("You aint got the greens") 
    else 
    Fee = guiScrollBarGetScrollPosition(Bar) 
    triggerServerEvent("takeMoney",getRootElement(),fee) 
    setElementHealth(localPlayer, getElementHealth(localPlayer) + fee) 
    outputChatBox("Recovered"..fee.."% of HP!") 
    end 
end 
  
function Exit() 
    destroyElement(HospitalW) 
    setTimer(fadeCamera,1000,1,false,1,0,0,0) 
end 
  
addEventHandler("onClientColShapeHit",getRootElement(), 
function() 
    if source == HospitalSF or HospitalLV or HospitalFC or HospitalM or HospitalLS1 or HospitalLS2 then 
        setTimer(fadeCamera,1000,1,true,1) 
        Name = getPlayerName(localPlayer) 
        Money = getPlayerMoney(localPlayer) 
        Skin = getElementModel(localPlayer) 
        HospitalW = guiCreateWindow(291,266,551,269,"Hospital",false) 
        Name = guiCreateLabel(24,28,128,18,"Name: "..Name.."",false,HospitalW) 
        Currency = guiCreateLabel(24,52,121,18,"Currency: "..Money.."",false,HospitalW) 
        Skin = guiCreateLabel(24,75,113,18,"Skin(ID): "..Skin.."",false,HospitalW) 
        Bar = guiCreateScrollBar(74,146,361,22,true,false,HospitalW) 
        HPL = guiCreateLabel(91,123,85,18,"HP: "..fee.."",false,HospitalW) 
        ExitB = guiCreateButton(237,219,81,35,"Exit",false,HospitalW) 
        HealB = guiCreateButton(441,144,101,26,"Heal",false,HospitalW) 
        Img = guiCreateStaticImage(148,33,251,93,"Hospilogo.png",false,HospitalW) 
        addEventHandler("onClientGUIClick",HealB,Heal,false) 
        addEventHandler("onClientGUIClick",ExitB,Exit,false) 
    end 
end 
) 
  
function getBarPos() 
    if Bar then 
    fee = guiScrollBarGetScrollPosition(Bar) 
    guiSetText(HPL,"Fee: "..fee.."") -- This is the problem. 
    end 
end 
  
    addEventHandler("onClientRender",getRootElement(),getBarPos) 

If you guys could help me once again, i would be really grateful for your help =)

- WolfPire

Link to comment
HospitalSF = createColSphere(-2654, 639, 15, 1) 
HospitalLV = createColSphere(1608, 1817, 11, 1) 
HospitalFC = createColSphere(-320, 1051, 21, 1) 
HospitalM = createColSphere(1243, 329, 20, 1) 
HospitalLS1 = createColSphere(2035, -1404, 18, 1) 
HospitalLS2 = createColSphere(1174, -1323, 16, 1) 
  
function Heal() 
    if (Money < fee) then 
        outputChatBox("You aint got the greens") 
    else 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        triggerServerEvent("takeMoney",getRootElement(),fee) 
        setElementHealth(localPlayer, getElementHealth(localPlayer) + fee) 
        outputChatBox("Recovered ".. fee .."% of HP!") 
    end 
end 
  
function Exit() 
    destroyElement(HospitalW) 
    setTimer(fadeCamera,1000,1,false,1,0,0,0) 
end 
  
addEventHandler("onClientColShapeHit",getRootElement(), 
    function() 
        if (source == HospitalSF or HospitalLV or HospitalFC or HospitalM or HospitalLS1 or HospitalLS2) then 
            setTimer(fadeCamera,1000,1,true,1) 
            Name = getPlayerName(localPlayer) 
            Money = getPlayerMoney(localPlayer) 
            Skin = getElementModel(localPlayer) 
            HospitalW = guiCreateWindow(291,266,551,269,"Hospital",false) 
            Name = guiCreateLabel(24,28,128,18,"Name: "..Name.."",false,HospitalW) 
            Currency = guiCreateLabel(24,52,121,18,"Currency: "..Money.."",false,HospitalW) 
            Skin = guiCreateLabel(24,75,113,18,"Skin(ID): "..Skin.."",false,HospitalW) 
            Bar = guiCreateScrollBar(74,146,361,22,true,false,HospitalW) 
            HPL = guiCreateLabel(91,123,85,18,"HP: "..fee.."",false,HospitalW) 
            ExitB = guiCreateButton(237,219,81,35,"Exit",false,HospitalW) 
            HealB = guiCreateButton(441,144,101,26,"Heal",false,HospitalW) 
            Img = guiCreateStaticImage(148,33,251,93,"Hospilogo.png",false,HospitalW) 
            addEventHandler("onClientGUIClick",HealB,Heal,false) 
            addEventHandler("onClientGUIClick",ExitB,Exit,false) 
        end 
    end 
) 
  
function getBarPos() 
    if Bar then 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        guiSetText(HPL,"Fee: ".. tostring(fee)) 
    end 
end 
addEventHandler("onClientRender",getRootElement(),getBarPos) 

Link to comment
HospitalSF = createColSphere(-2654, 639, 15, 1) 
HospitalLV = createColSphere(1608, 1817, 11, 1) 
HospitalFC = createColSphere(-320, 1051, 21, 1) 
HospitalM = createColSphere(1243, 329, 20, 1) 
HospitalLS1 = createColSphere(2035, -1404, 18, 1) 
HospitalLS2 = createColSphere(1174, -1323, 16, 1) 
  
function Heal() 
    if (Money < fee) then 
        outputChatBox("You aint got the greens") 
    else 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        triggerServerEvent("takeMoney",getRootElement(),fee) 
        setElementHealth(localPlayer, getElementHealth(localPlayer) + fee) 
        outputChatBox("Recovered ".. fee .."% of HP!") 
    end 
end 
  
function Exit() 
    destroyElement(HospitalW) 
    setTimer(fadeCamera,1000,1,false,1,0,0,0) 
end 
  
addEventHandler("onClientColShapeHit",getRootElement(), 
    function() 
        if (source == HospitalSF or HospitalLV or HospitalFC or HospitalM or HospitalLS1 or HospitalLS2) then 
            setTimer(fadeCamera,1000,1,true,1) 
            Name = getPlayerName(localPlayer) 
            Money = getPlayerMoney(localPlayer) 
            Skin = getElementModel(localPlayer) 
            HospitalW = guiCreateWindow(291,266,551,269,"Hospital",false) 
            Name = guiCreateLabel(24,28,128,18,"Name: "..Name.."",false,HospitalW) 
            Currency = guiCreateLabel(24,52,121,18,"Currency: "..Money.."",false,HospitalW) 
            Skin = guiCreateLabel(24,75,113,18,"Skin(ID): "..Skin.."",false,HospitalW) 
            Bar = guiCreateScrollBar(74,146,361,22,true,false,HospitalW) 
            HPL = guiCreateLabel(91,123,85,18,"HP: "..fee.."",false,HospitalW) 
            ExitB = guiCreateButton(237,219,81,35,"Exit",false,HospitalW) 
            HealB = guiCreateButton(441,144,101,26,"Heal",false,HospitalW) 
            Img = guiCreateStaticImage(148,33,251,93,"Hospilogo.png",false,HospitalW) 
            addEventHandler("onClientGUIClick",HealB,Heal,false) 
            addEventHandler("onClientGUIClick",ExitB,Exit,false) 
        end 
    end 
) 
  
function getBarPos() 
    if Bar then 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        guiSetText(HPL,"Fee: ".. tostring(fee)) 
    end 
end 
addEventHandler("onClientRender",getRootElement(),getBarPos) 

Thanks, once again =)

Edited by Guest
Link to comment

Sorry for not replying, i fell asleep.

Just tested it this morning.

I still got the same error >.<

Edit: The error is:

"WARNING: Hospital/h_c:49: Bad argument @ 'guiSetText' [Expected gui-element at argument 1, got nil]"

also discovered another error...

"ERROR: Hospital/h_c:36: attempt to concatenate global 'fee' (a nil value)"

I have 2 thoughts... Maybe it's the label and if its not... I might be sure it's something with this function.

Link to comment

Client

HospitalSF = createColSphere(-2654, 639, 15, 1) 
HospitalLV = createColSphere(1608, 1817, 11, 1) 
HospitalFC = createColSphere(-320, 1051, 21, 1) 
HospitalM = createColSphere(1243, 329, 20, 1) 
HospitalLS1 = createColSphere(2035, -1404, 18, 1) 
HospitalLS2 = createColSphere(1174, -1323, 16, 1) 
  
function Heal() 
    if (Money < fee) then 
        outputChatBox("You aint got the greens") 
    else 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        triggerServerEvent("takeMoney",getRootElement(),fee) 
        setElementHealth(localPlayer, getElementHealth(localPlayer) + fee) 
        outputChatBox("Recovered ".. fee .."% of HP!") 
    end 
end 
  
function Exit() 
    destroyElement(HospitalW) 
    setTimer(fadeCamera,1000,1,false,1,0,0,0) 
end 
  
addEventHandler("onClientColShapeHit",root, 
    function() 
        if source == HospitalSF or HospitalLV or HospitalFC or HospitalM or HospitalLS1 or HospitalLS2 then 
            if theElement == localPlayer then 
                setTimer(fadeCamera,1000,1,true,1) 
                Name = getPlayerName(localPlayer) 
                Money = getPlayerMoney(localPlayer) 
                Skin = getElementModel(localPlayer) 
                HospitalW = guiCreateWindow(291,266,551,269,"Hospital",false) 
                Name = guiCreateLabel(24,28,128,18,"Name: "..Name.."",false,HospitalW) 
                Currency = guiCreateLabel(24,52,121,18,"Currency: "..Money.."",false,HospitalW) 
                Skin = guiCreateLabel(24,75,113,18,"Skin(ID): "..Skin.."",false,HospitalW) 
                Bar = guiCreateScrollBar(74,146,361,22,true,false,HospitalW) 
                HPL = guiCreateLabel(91,123,85,18,"HP: "..tostring( getElementHealth( localPlayer ) ) .."",false,HospitalW) 
                ExitB = guiCreateButton(237,219,81,35,"Exit",false,HospitalW) 
                HealB = guiCreateButton(441,144,101,26,"Heal",false,HospitalW) 
                Img = guiCreateStaticImage(148,33,251,93,"Hospilogo.png",false,HospitalW) 
                addEventHandler("onClientGUIClick",HealB,Heal,false) 
                addEventHandler("onClientGUIClick",ExitB,Exit,false) 
            end  
        end 
    end 
) 
  
function getBarPos() 
    if Bar and isElement( HPL ) then 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        guiSetText( HPL,"Fee: ".. tostring( fee ) ) 
    end 
end 
addEventHandler( "onClientRender",root,getBarPos ) 

Link to comment
Client
HospitalSF = createColSphere(-2654, 639, 15, 1) 
HospitalLV = createColSphere(1608, 1817, 11, 1) 
HospitalFC = createColSphere(-320, 1051, 21, 1) 
HospitalM = createColSphere(1243, 329, 20, 1) 
HospitalLS1 = createColSphere(2035, -1404, 18, 1) 
HospitalLS2 = createColSphere(1174, -1323, 16, 1) 
  
function Heal() 
    if (Money < fee) then 
        outputChatBox("You aint got the greens") 
    else 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        triggerServerEvent("takeMoney",getRootElement(),fee) 
        setElementHealth(localPlayer, getElementHealth(localPlayer) + fee) 
        outputChatBox("Recovered ".. fee .."% of HP!") 
    end 
end 
  
function Exit() 
    destroyElement(HospitalW) 
    setTimer(fadeCamera,1000,1,false,1,0,0,0) 
end 
  
addEventHandler("onClientColShapeHit",root, 
    function() 
        if source == HospitalSF or HospitalLV or HospitalFC or HospitalM or HospitalLS1 or HospitalLS2 then 
            if theElement == localPlayer then 
                setTimer(fadeCamera,1000,1,true,1) 
                Name = getPlayerName(localPlayer) 
                Money = getPlayerMoney(localPlayer) 
                Skin = getElementModel(localPlayer) 
                HospitalW = guiCreateWindow(291,266,551,269,"Hospital",false) 
                Name = guiCreateLabel(24,28,128,18,"Name: "..Name.."",false,HospitalW) 
                Currency = guiCreateLabel(24,52,121,18,"Currency: "..Money.."",false,HospitalW) 
                Skin = guiCreateLabel(24,75,113,18,"Skin(ID): "..Skin.."",false,HospitalW) 
                Bar = guiCreateScrollBar(74,146,361,22,true,false,HospitalW) 
                HPL = guiCreateLabel(91,123,85,18,"HP: "..tostring( getElementHealth( localPlayer ) ) .."",false,HospitalW) 
                ExitB = guiCreateButton(237,219,81,35,"Exit",false,HospitalW) 
                HealB = guiCreateButton(441,144,101,26,"Heal",false,HospitalW) 
                Img = guiCreateStaticImage(148,33,251,93,"Hospilogo.png",false,HospitalW) 
                addEventHandler("onClientGUIClick",HealB,Heal,false) 
                addEventHandler("onClientGUIClick",ExitB,Exit,false) 
            end  
        end 
    end 
) 
  
function getBarPos() 
    if Bar and isElement( HPL ) then 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        guiSetText( HPL,"Fee: ".. tostring( fee ) ) 
    end 
end 
addEventHandler( "onClientRender",root,getBarPos ) 

Works like charm =)

But you forgot to add "theElement" @ the function.

But thanks guys. If i have any other issue. I'll let you know! =)

Edit:

Now whenever i press "Heal". The sscript sends me an error "attempt to compare number with nil"

Here's the code:

HospitalSF = createColSphere(-2654, 639, 15, 1) 
HospitalLV = createColSphere(1608, 1817, 11, 1) 
HospitalFC = createColSphere(-320, 1051, 21, 1) 
HospitalM = createColSphere(1243, 329, 20, 1) 
HospitalLS1 = createColSphere(2035, -1404, 18, 1) 
HospitalLS2 = createColSphere(1174, -1323, 16, 1) 
  
function Exit() 
    destroyElement(HospitalW) 
    setTimer(fadeCamera,1000,1,true,1) 
    showCursor(false) 
end 
  
addEventHandler("onClientColShapeHit",root, 
    function(theElement) 
        if source == HospitalSF or HospitalLV or HospitalFC or HospitalM or HospitalLS1 or HospitalLS2 then 
            if theElement == localPlayer then 
                setTimer(fadeCamera,50,1,false,1,0,0,0) 
                showCursor(true) 
                Name = getPlayerName(localPlayer) 
                Money = getPlayerMoney(localPlayer) 
                Skin = getElementModel(localPlayer) 
                HospitalW = guiCreateWindow(291,266,551,269,"Hospital",false) 
                Name = guiCreateLabel(24,28,128,18,"Name: "..Name.."",false,HospitalW) 
                Currency = guiCreateLabel(24,52,121,18,"Currency: "..Money.."",false,HospitalW) 
                Skin = guiCreateLabel(24,75,113,18,"Skin(ID): "..Skin.."",false,HospitalW) 
                Bar = guiCreateScrollBar(74,146,361,22,true,false,HospitalW) 
                FeeL = guiCreateLabel(91,123,85,18,"Fee: "..tostring( fee ) .."",false,HospitalW) 
                HPL = guiCreateLabel(371,123,85,18,"HP: "..tostring( getElementHealth( localPlayer ) ) .."",false,HospitalW) 
                ExitB = guiCreateButton(237,219,81,35,"Exit",false,HospitalW) 
                HealB = guiCreateButton(441,144,101,26,"Heal",false,HospitalW) 
                Img = guiCreateStaticImage(148,33,251,93,"Hospilogo.png",false,HospitalW) 
                addEventHandler("onClientGUIClick",HealB,Heal,false) 
                addEventHandler("onClientGUIClick",ExitB,Exit,false) 
            end  
        end 
    end 
) 
  
function getBarPos() 
    if Bar and isElement( FeeL ) then 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        guiSetText( FeeL,"Fee: ".. tostring( fee ) ) 
    end 
end 
addEventHandler( "onClientRender",root,getBarPos ) 
  
function Heal() 
    if (Money < fee) then 
        outputChatBox("You aint got the greens") 
    else 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        triggerServerEvent("takeMoney",getRootElement(),fee) 
        setElementHealth(localPlayer, getElementHealth(localPlayer) + fee) 
        outputChatBox("Recovered ".. fee .."% of HP!") 
    end 
end 

Edit 2: Also, the hospital script merged with all the scripts!

Whenever i step on any colshape, the GUI pops up, may i get some help on this please?

Link to comment
HospitalSF = createColSphere(-2654, 639, 15, 1) 
HospitalLV = createColSphere(1608, 1817, 11, 1) 
HospitalFC = createColSphere(-320, 1051, 21, 1) 
HospitalM = createColSphere(1243, 329, 20, 1) 
HospitalLS1 = createColSphere(2035, -1404, 18, 1) 
HospitalLS2 = createColSphere(1174, -1323, 16, 1) 
  
function Exit() 
    destroyElement(HospitalW) 
    setTimer(fadeCamera,1000,1,true,1) 
    showCursor(false) 
end 
  
addEventHandler("onClientColShapeHit",root, 
    function(theElement) 
        if (source == HospitalSF or source == HospitalLV or source == HospitalFC or source == HospitalM or source == HospitalLS1 or source == HospitalLS2) then 
            if theElement == localPlayer then 
                setTimer(fadeCamera,50,1,false,1,0,0,0) 
                showCursor(true) 
                Name = getPlayerName(localPlayer) 
                Money = getPlayerMoney(localPlayer) 
                Skin = getElementModel(localPlayer) 
                HospitalW = guiCreateWindow(291,266,551,269,"Hospital",false) 
                Name = guiCreateLabel(24,28,128,18,"Name: "..Name.."",false,HospitalW) 
                Currency = guiCreateLabel(24,52,121,18,"Currency: "..Money.."",false,HospitalW) 
                Skin = guiCreateLabel(24,75,113,18,"Skin(ID): "..Skin.."",false,HospitalW) 
                Bar = guiCreateScrollBar(74,146,361,22,true,false,HospitalW) 
                FeeL = guiCreateLabel(91,123,85,18,"Fee: "..tostring( fee ) .."",false,HospitalW) 
                HPL = guiCreateLabel(371,123,85,18,"HP: "..tostring( getElementHealth( localPlayer ) ) .."",false,HospitalW) 
                ExitB = guiCreateButton(237,219,81,35,"Exit",false,HospitalW) 
                HealB = guiCreateButton(441,144,101,26,"Heal",false,HospitalW) 
                Img = guiCreateStaticImage(148,33,251,93,"Hospilogo.png",false,HospitalW) 
                addEventHandler("onClientGUIClick",HealB,Heal,false) 
                addEventHandler("onClientGUIClick",ExitB,Exit,false) 
            end 
        end 
    end 
) 
  
function getBarPos() 
    if Bar and isElement( FeeL ) then 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        guiSetText( FeeL,"Fee: ".. tostring( fee ) ) 
    end 
end 
addEventHandler( "onClientRender",root,getBarPos ) 
  
function Heal() 
    local fee = guiScrollBarGetScrollPosition(Bar) 
    local money = getPlayerMoney(localPlayer) 
    if (money < fee) then 
        outputChatBox("You aint got the greens") 
    else 
        triggerServerEvent("takeMoney",getRootElement(),fee) 
        setElementHealth(localPlayer, getElementHealth(localPlayer) + fee) 
        outputChatBox("Recovered ".. fee .."% of HP!") 
    end 
end 

Link to comment
HospitalSF = createColSphere(-2654, 639, 15, 1) 
HospitalLV = createColSphere(1608, 1817, 11, 1) 
HospitalFC = createColSphere(-320, 1051, 21, 1) 
HospitalM = createColSphere(1243, 329, 20, 1) 
HospitalLS1 = createColSphere(2035, -1404, 18, 1) 
HospitalLS2 = createColSphere(1174, -1323, 16, 1) 
  
function Exit() 
    destroyElement(HospitalW) 
    setTimer(fadeCamera,1000,1,true,1) 
    showCursor(false) 
end 
  
addEventHandler("onClientColShapeHit",root, 
    function(theElement) 
        if (source == HospitalSF or source == HospitalLV or source == HospitalFC or source == HospitalM or source == HospitalLS1 or source == HospitalLS2) then 
            if theElement == localPlayer then 
                setTimer(fadeCamera,50,1,false,1,0,0,0) 
                showCursor(true) 
                Name = getPlayerName(localPlayer) 
                Money = getPlayerMoney(localPlayer) 
                Skin = getElementModel(localPlayer) 
                HospitalW = guiCreateWindow(291,266,551,269,"Hospital",false) 
                Name = guiCreateLabel(24,28,128,18,"Name: "..Name.."",false,HospitalW) 
                Currency = guiCreateLabel(24,52,121,18,"Currency: "..Money.."",false,HospitalW) 
                Skin = guiCreateLabel(24,75,113,18,"Skin(ID): "..Skin.."",false,HospitalW) 
                Bar = guiCreateScrollBar(74,146,361,22,true,false,HospitalW) 
                FeeL = guiCreateLabel(91,123,85,18,"Fee: "..tostring( fee ) .."",false,HospitalW) 
                HPL = guiCreateLabel(371,123,85,18,"HP: "..tostring( getElementHealth( localPlayer ) ) .."",false,HospitalW) 
                ExitB = guiCreateButton(237,219,81,35,"Exit",false,HospitalW) 
                HealB = guiCreateButton(441,144,101,26,"Heal",false,HospitalW) 
                Img = guiCreateStaticImage(148,33,251,93,"Hospilogo.png",false,HospitalW) 
                addEventHandler("onClientGUIClick",HealB,Heal,false) 
                addEventHandler("onClientGUIClick",ExitB,Exit,false) 
            end 
        end 
    end 
) 
  
function getBarPos() 
    if Bar and isElement( FeeL ) then 
        local fee = guiScrollBarGetScrollPosition(Bar) 
        guiSetText( FeeL,"Fee: ".. tostring( fee ) ) 
    end 
end 
addEventHandler( "onClientRender",root,getBarPos ) 
  
function Heal() 
    local fee = guiScrollBarGetScrollPosition(Bar) 
    local money = getPlayerMoney(localPlayer) 
    if (money < fee) then 
        outputChatBox("You aint got the greens") 
    else 
        triggerServerEvent("takeMoney",getRootElement(),fee) 
        setElementHealth(localPlayer, getElementHealth(localPlayer) + fee) 
        outputChatBox("Recovered ".. fee .."% of HP!") 
    end 
end 

Thank you very much, this worked!

Thanks everyone for your help! =)

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