Jump to content

Help?


Recommended Posts

Hello there,

I'm a beginner in LUA, so I'm trying to learn as much as I can. I'm struggling now with something:

I created a gridlist with 3 columns. I want to retrieve all the weapons that the client has, listing their names, IDs, and total ammo into the gridlist created previously.

It is necessary for tables and loops to be set, as I stated I'm beginner so I'm trying to learn these stuff.

To start with:

wepGridlist = guiCreateGridList(20, 27, 335, 177, false, window)        guiGridListAddColumn(wepGridlist, "ID", 0.2)        guiGridListAddColumn(wepGridlist, "Name", 0.4)        guiGridListAddColumn(wepGridlist, "Ammo", 0.3)

If you can, please explain the code you're going to post, step by step.

Link to comment

Hello there,

I'm a beginner in LUA, so I'm trying to learn as much as I can. I'm struggling now with something:

I created a gridlist with 3 columns. I want to retrieve all the weapons that the client has, listing their names, IDs, and total ammo into the gridlist created previously.

It is necessary for tables and loops to be set, as I stated I'm beginner so I'm trying to learn these stuff.

To start with:

wepGridlist = guiCreateGridList(20, 27, 335, 177, false, window) 
        guiGridListAddColumn(wepGridlist, "ID", 0.2) 
        guiGridListAddColumn(wepGridlist, "Name", 0.4) 
        guiGridListAddColumn(wepGridlist, "Ammo", 0.3) 

If you can, please explain the code you're going to post, step by step.

Link to comment

First of all, I'm not sure if it works.

It goes like this.

  
for i=1, guiGridListGetRowCount(wepGridlist) do 
  
end 
[lua] 
This creates a loop till the row count of your gridlist 
For example, if it is 5, it will loop 5 times. 
  
[lua] 
for i=1, guiGridListGetRowCount(wepGridlist) do 
    local ID = guiGridListGetItemText( wepGridlist, i, 1 ) 
    local Name = guiGridListGetItemText( wepGridlist, i, 2 ) 
    local Ammo = guiGridListGetItemText( wepGridlist, i, 3 ) 
end 
  

Now here, you used guiGridListGetItemText, with your gridlist name and where is the loop as i will change everytime it loops till your row count.

You get your results!

GL to scripting

Link to comment

First of all, I'm not sure if it works.

It goes like this.

  
for i=1, guiGridListGetRowCount(wepGridlist) do 
  
end 
[lua] 
This creates a loop till the row count of your gridlist 
For example, if it is 5, it will loop 5 times. 
  
[lua] 
for i=1, guiGridListGetRowCount(wepGridlist) do 
    local ID = guiGridListGetItemText( wepGridlist, i, 1 ) 
    local Name = guiGridListGetItemText( wepGridlist, i, 2 ) 
    local Ammo = guiGridListGetItemText( wepGridlist, i, 3 ) 
end 
  

Now here, you used guiGridListGetItemText, with your gridlist name and where is the loop as i will change everytime it loops till your row count.

You get your results!

GL to scripting

Link to comment

Thanks for the effort, but this is not the help I'm looking for.

I need a function that retrieves the localPlayer's weapons names, IDs, and ammo. After retrieving these, it then adds the info we retrieved into multiple rows respectively.

For example I got 2 weapons, Deagle and AK-47, it should be as follows:

ID Name Ammo

24 Deagle 123/7

30 AK-47 70/30

Link to comment

Thanks for the effort, but this is not the help I'm looking for.

I need a function that retrieves the localPlayer's weapons names, IDs, and ammo. After retrieving these, it then adds the info we retrieved into multiple rows respectively.

For example I got 2 weapons, Deagle and AK-47, it should be as follows:

ID Name Ammo

24 Deagle 123/7

30 AK-47 70/30

Link to comment
  
wepGridlist = guiCreateGridList(20, 27, 335, 177, false, window) 
    local idCol = guiGridListAddColumn(wepGridlist, "ID", 0.2) 
    local nameCol = guiGridListAddColumn(wepGridlist, "Name", 0.4) 
    local ammoCol = guiGridListAddColumn(wepGridlist, "Ammo", 0.3) 
  
for i=0, 12 do 
    local playerWeapon = getPedWeapon(getLocalPlayer(), i) 
    if (playerWeapon) and ((playerWeapon-i) >= 0) then 
        local id, name, ammo = playerWeapon, getWeaponNameFromID(playerWeapon), getPedTotalAmmo(getLocalPlayer(), i) 
        local row = guiGridListAddRow(wepGridlist) 
        guiGridListSetItemText(wepGridlist, row, idCol, id, false, false) 
        guiGridListSetItemText(wepGridlist, row, nameCol, name, false, false) 
        guiGridListSetItemText(wepGridlist, row, ammoCol, ammo, false, false) 
    end 
end 
  

Link to comment
  
wepGridlist = guiCreateGridList(20, 27, 335, 177, false, window) 
    local idCol = guiGridListAddColumn(wepGridlist, "ID", 0.2) 
    local nameCol = guiGridListAddColumn(wepGridlist, "Name", 0.4) 
    local ammoCol = guiGridListAddColumn(wepGridlist, "Ammo", 0.3) 
  
for i=0, 12 do 
    local playerWeapon = getPedWeapon(getLocalPlayer(), i) 
    if (playerWeapon) and ((playerWeapon-i) >= 0) then 
        local id, name, ammo = playerWeapon, getWeaponNameFromID(playerWeapon), getPedTotalAmmo(getLocalPlayer(), i) 
        local row = guiGridListAddRow(wepGridlist) 
        guiGridListSetItemText(wepGridlist, row, idCol, id, false, false) 
        guiGridListSetItemText(wepGridlist, row, nameCol, name, false, false) 
        guiGridListSetItemText(wepGridlist, row, ammoCol, ammo, false, false) 
    end 
end 
  

Link to comment
  
wepGridlist = guiCreateGridList(20, 27, 335, 177, false, window) 
    local idCol = guiGridListAddColumn(wepGridlist, "ID", 0.2) 
    local nameCol = guiGridListAddColumn(wepGridlist, "Name", 0.4) 
    local ammoCol = guiGridListAddColumn(wepGridlist, "Ammo", 0.3) 
  
for i=0, 12 do 
    local playerWeapon = getPedWeapon(getLocalPlayer(), i) 
    if (playerWeapon) and ((playerWeapon-i) >= 0) then 
        local id, name, ammo = playerWeapon, getWeaponNameFromID(playerWeapon), getPedTotalAmmo(getLocalPlayer(), i) 
        local row = guiGridListAddRow(wepGridlist) 
        guiGridListSetItemText(wepGridlist, row, idCol, id, false, false) 
        guiGridListSetItemText(wepGridlist, row, nameCol, name, false, false) 
        guiGridListSetItemText(wepGridlist, row, ammoCol, ammo, false, false) 
    end 
end 
  

Great, it works perfectly. Thank you!

Link to comment
  
wepGridlist = guiCreateGridList(20, 27, 335, 177, false, window) 
    local idCol = guiGridListAddColumn(wepGridlist, "ID", 0.2) 
    local nameCol = guiGridListAddColumn(wepGridlist, "Name", 0.4) 
    local ammoCol = guiGridListAddColumn(wepGridlist, "Ammo", 0.3) 
  
for i=0, 12 do 
    local playerWeapon = getPedWeapon(getLocalPlayer(), i) 
    if (playerWeapon) and ((playerWeapon-i) >= 0) then 
        local id, name, ammo = playerWeapon, getWeaponNameFromID(playerWeapon), getPedTotalAmmo(getLocalPlayer(), i) 
        local row = guiGridListAddRow(wepGridlist) 
        guiGridListSetItemText(wepGridlist, row, idCol, id, false, false) 
        guiGridListSetItemText(wepGridlist, row, nameCol, name, false, false) 
        guiGridListSetItemText(wepGridlist, row, ammoCol, ammo, false, false) 
    end 
end 
  

Great, it works perfectly. Thank you!

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