Jump to content

question with function


Kenix

Recommended Posts

With:
function getSkillFunc(player,Levelids) 
    if ( Levelids ) then 
        local skillsID = tonumber( Levelids ) 
        triggerClientEvent(player, "selectSkill", getRootElement() ,skillsID) 
        return true 
    else 
        return false 
    end 
end 

And this:

addEvent("selectSkill",true) 
addEventHandler( "selectSkill", getRootElement(), 
    function(skillsID) 
    if (tonumber(skillsID)) then 
    guiGridListSetItemText(GUIEditor_Grid[211],tonumber(skillsID),5,"purchased",false,false) 
    guiGridListSetItemColor (GUIEditor_Grid[211],tonumber(skillsID),5,0,255,0) 
    outputChatBox("text change "..tonumber(skillsID)) 
    end 
    end 
) 

it works perfectly, take a look at this screenshot.

http://img855.imageshack.us/i/mtascreen ... 82115.png/

THX MAN !!!! :D

Link to comment
  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

I have a new question:)

Added:

Damn I have not done something when you buy the window closes because it is not clear whether or not I bought a GUI and I have not seen appearing a text in gridList

:D

sorry guys, I sometimes stupid ... :(

days were difficult

after closing it all disappears(something that was added to the text), I made a script:

  
addEvent("selectSkill",true) 
addEventHandler( "selectSkill", getRootElement(), 
    function(skillsID) 
    if (tonumber(skillsID)) then 
    guiGridListSetItemText(MainGrid,tonumber(skillsID),5,"purchased",false,false) 
    guiGridListSetItemColor (MainGrid,tonumber(skillsID),5,0,255,0) 
    local datasSk = setElementData(getLocalPlayer(),"SkillBuy",skillsID) 
    outputChatBox("set data skill "..tostring(skillsID).." , "..tostring(datasSk)) 
    outputChatBox("text change "..tonumber(skillsID)) 
    end 
    end 
) 
  

he says set data skill 0 , false

  
function startShowingShopLevelMenu()  
showCursor(true) 
GUIEditor_Window = {} 
GUIEditor_Grid = {} 
  
MainWindowLevel = guiCreateWindow(0.2234,0.0586,0.5969,0.9102,"New Skills Shop",true) 
MainButton = guiCreateButton(0.1289,0.9418,0.6974,0.0370,"Buy Skill",true,MainWindowLevel) 
MainGrid = guiCreateGridList(0.0419,0.0354,0.9058,0.8970,true,MainWindowLevel) 
guiGridListSetSelectionMode(MainGrid,1) 
guiGridListAddColumn(MainGrid,"ID",0.2) 
guiGridListAddColumn(MainGrid,"Name",0.2) 
guiGridListAddColumn(MainGrid,"$",0.2) 
guiGridListAddColumn(MainGrid,"Level",0.2) 
guiGridListAddColumn(MainGrid,"Status",0.2) 
if ( skillsID ) then 
if getElementData(getLocalPlayer(),"SkillBuy") == tonumber(skillsID) then outputChatBox("get element data") 
local textAddSkill = guiGridListSetItemText(MainGrid,tonumber(skillsID),5,"purchased",false,false) 
local textAddSkill2 = guiGridListSetItemColor (MainGrid,tonumber(skillsID),5,0,255,0) 
outputChatBox("text add "..tostring(textAddSkill).." , "..tostring(textAddSkill2)) 
end 
end 
  addEventHandler ("onClientGUIClick", MainButton, onClientPlayerSkillBuy) 
for i,v in ipairs (skillsLevelsTable) do 
  local row21 = guiGridListAddRow (MainGrid) 
  guiGridListSetItemText (MainGrid, row21, 1, v[1], false, true) 
  guiGridListSetItemText (MainGrid, row21, 2, v[2], false, true) 
  guiGridListSetItemText (MainGrid, row21, 3, v[3], false, true) 
  guiGridListSetItemText (MainGrid, row21, 4, v[4], false, true) 
  guiGridListSetItemText (MainGrid, row21, 5, v[5], false, true) 
  guiGridListSetItemText (MainGrid, row21, 6, v[6], false, true) 
  end 
end 
  

Link to comment
  • Moderators

I really don't know but maybe try this:

addEvent("selectSkill",true) 
addEventHandler( "selectSkill", getLocalPlayer(), 
    function(skillsID) 
    if (tonumber(skillsID)) then 
    guiGridListSetItemText(MainGrid,tonumber(skillsID),5,"purchased",false,false) 
    guiGridListSetItemColor (MainGrid,tonumber(skillsID),5,0,255,0) 
    local datasSk = setElementData(getLocalPlayer(),"SkillBuy",skillsID) 
    outputChatBox("set data skill "..tostring(skillsID).." , "..tostring(datasSk)) 
    outputChatBox("text change "..tonumber(skillsID)) 
    end 
    end 
) 

Link to comment
Hi volk, could you please explain what do you want to do?

Hi man :)

see when you close it then it disappears from gridList

and I want to do after buying it persisted gridList (get/set ElementData)

Edit:

before (open and buy)

a415e1ebd9af.jpg

after(close and open)

511de2106f62.jpg

Edited by Guest
Link to comment
make a table and then load from it?

btw, why do you clean the grid list every time?

I have no line in the script to clean it

at the expense of the tables I do not know, I just want to do what you are buying the ability and it is stored in gridList.

maybe something I can not do. :?

Link to comment
  • Moderators

Solidsnake ( and me ) think that you create the gui every times ( when you want to show it )

So just use this function 1 time ( startShowingShopLevelMenu )

Then use guiSetVisible( MainWindowLevel , true ) to show it again.

Link to comment
Solidsnake ( and me ) think that you create the gui every times ( when you want to show it )

So just use this function 1 time ( startShowingShopLevelMenu )

Then use guiSetVisible( MainWindowLevel , true ) to show it again.

try this?

  
addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), 
function() 
  bindKey ( "F2", "down",  
     function(   ) 
if (guiGetVisible(MainWindowLevel) == false) then 
     guiSetVisible(MainWindowLevel,true) 
     startShowingShopLevelMenu() 
     elseif (guiGetVisible(MainWindowLevel) == true) then 
     guiSetVisible(MainWindowLevel,false) 
     showCursor(false) 
     end 
   end) 
end) 
  

Link to comment
You can use setAccountData and setElementData to save it and then when he joins again use getAccountData with setElementData.

I know it

but because the text still does not appear even if I use set/get elementdata and on set/getAcountData it will be realized when it is completed

and I am 100% sure that the text does not appear because it is not right

  
if ( skillsID ) then 
if getElementData(getLocalPlayer(),"SkillBuy") == tonumber(skillsID) then outputChatBox("get element data") 
local textAddSkill = guiGridListSetItemText(MainGrid,tonumber(skillsID),5,"purchased",false,false) 
local textAddSkill2 = guiGridListSetItemColor (MainGrid,tonumber(skillsID),5,0,255,0) 
outputChatBox("text add "..tostring(textAddSkill).." , "..tostring(textAddSkill2)) 
end 
end 
  

Link to comment
  • Moderators
Solidsnake ( and me ) think that you create the gui every times ( when you want to show it )

So just use this function 1 time ( startShowingShopLevelMenu )

Then use guiSetVisible( MainWindowLevel , true ) to show it again.

try this?

  
addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), 
function() 
  bindKey ( "F2", "down",  
     function(   ) 
if (guiGetVisible(MainWindowLevel) == false) then 
     guiSetVisible(MainWindowLevel,true) 
     startShowingShopLevelMenu() 
     elseif (guiGetVisible(MainWindowLevel) == true) then 
     guiSetVisible(MainWindowLevel,false) 
     showCursor(false) 
     end 
   end) 
end) 
  

No because you create again the gui when you want to show it. Create this gui when the player join, then you will only use guiSetVisible:

addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), 
function() 
    startShowingShopLevelMenu() 
    bindKey ( "F2", "down",  
        function(   ) 
            if (guiGetVisible(MainWindowLevel) == false) then 
                guiSetVisible(MainWindowLevel,true) 
            elseif (guiGetVisible(MainWindowLevel) == true) then 
                guiSetVisible(MainWindowLevel,false) 
                showCursor(false) 
            end 
        end 
    ) 
end) 

Ok ?

Link to comment
Solidsnake ( and me ) think that you create the gui every times ( when you want to show it )

So just use this function 1 time ( startShowingShopLevelMenu )

Then use guiSetVisible( MainWindowLevel , true ) to show it again.

try this?

  
addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), 
function() 
  bindKey ( "F2", "down",  
     function(   ) 
if (guiGetVisible(MainWindowLevel) == false) then 
     guiSetVisible(MainWindowLevel,true) 
     startShowingShopLevelMenu() 
     elseif (guiGetVisible(MainWindowLevel) == true) then 
     guiSetVisible(MainWindowLevel,false) 
     showCursor(false) 
     end 
   end) 
end) 
  

No because you create again the gui when you want to show it. Create this gui when the player join, then you will only use guiSetVisible:

addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), 
function() 
    startShowingShopLevelMenu() 
    bindKey ( "F2", "down",  
        function(   ) 
            if (guiGetVisible(MainWindowLevel) == false) then 
                guiSetVisible(MainWindowLevel,true) 
            elseif (guiGetVisible(MainWindowLevel) == true) then 
                guiSetVisible(MainWindowLevel,false) 
                showCursor(false) 
            end 
        end 
    ) 
end) 

Ok ?

so now the text is saved but I would like to see the text appearing on the button and not when join to the server.

Link to comment
  
function startShowingShopLevelMenu()  
showCursor(true) 
  
MainWindowLevel = guiCreateWindow(0.2234,0.0586,0.5969,0.9102,"New Skills Shop",true) 
MainButton = guiCreateButton(0.1289,0.9418,0.6974,0.0370,"Buy Skill",true,MainWindowLevel) 
MainGrid = guiCreateGridList(0.0419,0.0354,0.9058,0.8970,true,MainWindowLevel) 
guiGridListSetSelectionMode(MainGrid,1) 
guiGridListAddColumn(MainGrid,"ID",0.2) 
guiGridListAddColumn(MainGrid,"Name",0.2) 
guiGridListAddColumn(MainGrid,"$",0.2) 
guiGridListAddColumn(MainGrid,"Level",0.2) 
guiGridListAddColumn(MainGrid,"Status",0.2) 
if ( skillsID ) then 
if getElementData(getLocalPlayer(),"SkillBuy") == tonumber(skillsID) then outputChatBox("get element data") 
local textAddSkill = guiGridListSetItemText(MainGrid,tonumber(skillsID),5,"purchased",false,false) 
local textAddSkill2 = guiGridListSetItemColor (MainGrid,tonumber(skillsID),5,0,255,0) 
outputChatBox("text add "..tostring(textAddSkill).." , "..tostring(textAddSkill2)) 
end 
end 
guiSetVisible(MainWindowLevel, false ) 
addEventHandler ("onClientGUIClick", MainButton, onClientPlayerSkillBuy) 
for i,v in ipairs (skillsLevelsTable) do 
  local row21 = guiGridListAddRow (MainGrid) 
  guiGridListSetItemText (MainGrid, row21, 1, v[1], false, true) 
  guiGridListSetItemText (MainGrid, row21, 2, v[2], false, true) 
  guiGridListSetItemText (MainGrid, row21, 3, v[3], false, true) 
  guiGridListSetItemText (MainGrid, row21, 4, v[4], false, true) 
  guiGridListSetItemText (MainGrid, row21, 5, v[5], false, true) 
  guiGridListSetItemText (MainGrid, row21, 6, v[6], false, true) 
  end 
end 
  

Edited by Guest
Link to comment
  • Moderators

I was sure of it ! You didn't make this:

    function startShowingShopLevelMenu() 
          -- blablabla 
          guiSetVisible(MainWindowLevel, false ) 
    end  

So this is the code with the setElementVisible at the end like I said

      
    function startShowingShopLevelMenu() 
    showCursor(true) 
    GUIEditor_Window = {} 
    GUIEditor_Grid = {} 
      
    MainWindowLevel = guiCreateWindow(0.2234,0.0586,0.5969,0.9102,"New Skills Shop",true) 
    MainButton = guiCreateButton(0.1289,0.9418,0.6974,0.0370,"Buy Skill",true,MainWindowLevel) 
    MainGrid = guiCreateGridList(0.0419,0.0354,0.9058,0.8970,true,MainWindowLevel) 
    guiGridListSetSelectionMode(MainGrid,1) 
    guiGridListAddColumn(MainGrid,"ID",0.2) 
    guiGridListAddColumn(MainGrid,"Name",0.2) 
    guiGridListAddColumn(MainGrid,"$",0.2) 
    guiGridListAddColumn(MainGrid,"Level",0.2) 
    guiGridListAddColumn(MainGrid,"Status",0.2) 
    if ( skillsID ) then 
    if getElementData(getLocalPlayer(),"SkillBuy") == tonumber(skillsID) then outputChatBox("get element data") 
    local textAddSkill = guiGridListSetItemText(MainGrid,tonumber(skillsID),5,"purchased",false,false) 
    local textAddSkill2 = guiGridListSetItemColor (MainGrid,tonumber(skillsID),5,0,255,0) 
    outputChatBox("text add "..tostring(textAddSkill).." , "..tostring(textAddSkill2)) 
    end 
    end 
    guiSetVisible(MainWindowLevel, false ) 
    addEventHandler ("onClientGUIClick", MainButton, onClientPlayerSkillBuy) 
    for i,v in ipairs (skillsLevelsTable) do 
      local row21 = guiGridListAddRow (MainGrid) 
      guiGridListSetItemText (MainGrid, row21, 1, v[1], false, true) 
      guiGridListSetItemText (MainGrid, row21, 2, v[2], false, true) 
      guiGridListSetItemText (MainGrid, row21, 3, v[3], false, true) 
      guiGridListSetItemText (MainGrid, row21, 4, v[4], false, true) 
      guiGridListSetItemText (MainGrid, row21, 5, v[5], false, true) 
      guiGridListSetItemText (MainGrid, row21, 6, v[6], false, true) 
      end 
      guiSetVisible( MainWindowLevel , false ) 
    end 

Link to comment

not open

He could not open if guiSetVisible (MainWindowLevel, true) instead of the function()

I do not know what to do help :?

  
local getVS = guiGetVisible(MainWindowLevel) 
  
addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), 
function() 
    bindKey ( "F2", "down",  
        function(   ) 
            if (guiGetVisible(MainWindowLevel) == false) then 
                guiSetVisible(MainWindowLevel,true) 
                showCursor(true) 
               outputChatBox("open "..tostring(getVS))    -- Write open false Wtf 
            elseif (guiGetVisible(MainWindowLevel) == true) then 
                guiSetVisible(MainWindowLevel,false) 
                showCursor(false) 
                outputChatBox("close") 
            end 
        end) 
end) 
  

Link to comment
  • Moderators

You doesn't help me because when I give you a code, you don't keep it :|

    addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        startShowingShopLevelMenu() 
        bindKey ( "F2", "down", 
            function(   ) 
                if (guiGetVisible(MainWindowLevel) == false) then 
                    guiSetVisible(MainWindowLevel,true) 
                elseif (guiGetVisible(MainWindowLevel) == true) then 
                    guiSetVisible(MainWindowLevel,false) 
                    showCursor(false) 
                end 
            end 
        ) 
    end) 

And this time keep all codes if you are another problem

Link to comment
You doesn't help me because when I give you a code, you don't keep it :|
    addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        startShowingShopLevelMenu() 
        bindKey ( "F2", "down", 
            function(   ) 
                if (guiGetVisible(MainWindowLevel) == false) then 
                    guiSetVisible(MainWindowLevel,true) 
                elseif (guiGetVisible(MainWindowLevel) == true) then 
                    guiSetVisible(MainWindowLevel,false) 
                    showCursor(false) 
                end 
            end 
        ) 
    end) 

And this time keep all codes if you are another problem

this code works I wrote to you earlier but I want to do that at the start of the resource does not display but only after bind F2

Link to comment
  • Moderators

I KNOW !!! :evil:

This !!!

addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        startShowingShopLevelMenu() 
        bindKey ( "F2", "down", 
            function(   ) 
                if (guiGetVisible(MainWindowLevel) == false) then 
                    guiSetVisible(MainWindowLevel,true) 
                elseif (guiGetVisible(MainWindowLevel) == true) then 
                    guiSetVisible(MainWindowLevel,false) 
                    showCursor(false) 
                end 
            end 
        ) 
    end) 

AND THIS !

        
        function startShowingShopLevelMenu() 
        showCursor(true) 
        GUIEditor_Window = {} 
        GUIEditor_Grid = {} 
          
        MainWindowLevel = guiCreateWindow(0.2234,0.0586,0.5969,0.9102,"New Skills Shop",true) 
        MainButton = guiCreateButton(0.1289,0.9418,0.6974,0.0370,"Buy Skill",true,MainWindowLevel) 
        MainGrid = guiCreateGridList(0.0419,0.0354,0.9058,0.8970,true,MainWindowLevel) 
        guiGridListSetSelectionMode(MainGrid,1) 
        guiGridListAddColumn(MainGrid,"ID",0.2) 
        guiGridListAddColumn(MainGrid,"Name",0.2) 
        guiGridListAddColumn(MainGrid,"$",0.2) 
        guiGridListAddColumn(MainGrid,"Level",0.2) 
        guiGridListAddColumn(MainGrid,"Status",0.2) 
        if ( skillsID ) then 
        if getElementData(getLocalPlayer(),"SkillBuy") == tonumber(skillsID) then outputChatBox("get element data") 
        local textAddSkill = guiGridListSetItemText(MainGrid,tonumber(skillsID),5,"purchased",false,false) 
        local textAddSkill2 = guiGridListSetItemColor (MainGrid,tonumber(skillsID),5,0,255,0) 
        outputChatBox("text add "..tostring(textAddSkill).." , "..tostring(textAddSkill2)) 
        end 
        end 
        guiSetVisible(MainWindowLevel, false ) 
        addEventHandler ("onClientGUIClick", MainButton, onClientPlayerSkillBuy) 
        for i,v in ipairs (skillsLevelsTable) do 
          local row21 = guiGridListAddRow (MainGrid) 
          guiGridListSetItemText (MainGrid, row21, 1, v[1], false, true) 
          guiGridListSetItemText (MainGrid, row21, 2, v[2], false, true) 
          guiGridListSetItemText (MainGrid, row21, 3, v[3], false, true) 
          guiGridListSetItemText (MainGrid, row21, 4, v[4], false, true) 
          guiGridListSetItemText (MainGrid, row21, 5, v[5], false, true) 
          guiGridListSetItemText (MainGrid, row21, 6, v[6], false, true) 
          end 
          guiSetVisible( MainWindowLevel , false ) 
        end 

Sorry for SHIFT but I already answered to your question 2 times.

This code create the gui and hide it at the start and then just use F2

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