Jump to content

Need double help


manve1

Recommended Posts

Posted

I need double help, on same script but for 2 different things.

___________________________________________________________

1. I tried making grid list with player names, but when i try making that it refreshes every 50miliseconds, i fail, so i only see other player names after restart.

    function playerList() 
            local Column = guiGridListAddColumn( Grid, "Player", 0.85 ) 
            if ( Column ) then           
                    for id, player in ipairs(getElementsByType("player")) do 
                        local Row = guiGridListAddRow ( Grid ) 
                                setTimer( function ( ) 
                                    guiGridListSetItemText ( Grid, Row, Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) 
                                end 
                                ,50, 0 ) 
                    end 
            end 
    end 
     
    addEventHandler("onClientResourceStart", root, playerList) 

_______________________________________________________________

2. I'm making on same script label's which tells player name once selected on grid List the name.

player_name = guiCreateLabel( 0.325, 0.1, 0.5, 0.2, "PlayerName: ", true, Wnd ) 
    player_name2 = guiCreateLabel( 0.325, 0.1, 0.5, 0.2, "PlayerName: ".. getPlayerName ( localPlayer ):gsub ( "#%x%x%x%x%x%x", "" ), true, Wnd ) 
      
    function change_name() 
    local row = guiGridListGetSelectedItem ( Grid ) 
    if ( row ~= -1 ) then 
    guiSetText( player_name, guiGetText(player_name2) ) 
    end 
    end 
    addEventHandler ( "onClientGUIClick", Grid, change_name, false ) 

____________________________________________________

Looking for tutorials or information? check out: www.simpleask.co.uk

Posted

Try

function playerList() 
    local Column = guiGridListAddColumn( Grid, "Player", 0.85 ) 
    if ( Column ) then         
        for id, player in ipairs(getElementsByType("player")) do 
            local Row = guiGridListAddRow ( Grid ) 
            guiGridListSetItemText ( Grid, Row, Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) 
        end 
    end 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), playerList) 
addEventHandler ( "onClientPlayerJoin", root, playerList ) 

player_name = guiCreateLabel( 0.325, 0.1, 0.5, 0.2, "PlayerName: ", true, Wnd ) 
player_name2 = guiCreateLabel( 0.325, 0.1, 0.5, 0.2, "PlayerName: ".. getPlayerName ( localPlayer ):gsub ( "#%x%x%x%x%x%x", "" ), true, Wnd ) 
      
function change_name() 
    local row = guiGridListGetSelectedItem ( Grid ) 
    if ( row ~= -1 ) then 
        outputChatBox("* Please select a player!",255,255,255,true) 
        return 
    end 
    guiSetText( player_name, guiGetText(player_name2) ) 
end 
addEventHandler ( "onClientGUIClick", Grid, change_name, false ) 

357ac0078264.jpg

- Working on [php/HTML/Mysql/Lua/Java Scripts/Web Design/3D Modeling]

Posted (edited)

First code:

local pColumn = guiGridListAddColumn(Grid, 'Player', 0.85) 
  
addEventHandler('onClientResourceStart', resourceRoot,  
    function() 
        if (pColumn) then 
            for k,v in next, getElementsByType 'player' do 
                guiGridListSetItemText(Grid, guiGridListAddRow(Grid), pColumn, getPlayerName(v):gsub('#%x%x%x%x%x%x', ''), false, false) 
                pTimer = setTimer(updateList, 2000, 0) 
            end 
        end 
    end 
) 
  
function updateList() 
    for i = 1, #guiGridListGetRowCount(Grid) do 
        guiGridListRemoveRow(Grid, i) 
    end 
    for k,v in next, getElementsByType 'player' do 
        guiGridListSetItemText(Grid, guiGridListAddRow(Grid), pColumn, getPlayerName(v):gsub('#%x%x%x%x%x%x', ''), false, false) 
    end 
end 

Second code:

local pNameLabel = guiCreateLabel(0.325, 0.1, 0.5, 0.2, 'Player Name: ', true, Wnd) 
  
addEventHandler('onClientGUIClick', Grid, 
    function() 
        if (pNameLabel) then 
            local pRow = guiGridListGetSelectedItem(source)  
            if (pRow and pRow ~= -1) then 
                guiSetText(pNameLabel, 'Player Name: ' .. guiGridListGetItemText(source, pRow, 1)) 
            end 
        end 
    end, false 
) 

Edited by Guest

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted
I've got a problem with the grid list.

QCB82.png

it adds the name over and over again.. never stops.

Ops, my bad; I forgot to remove rows before update, copy my code again.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

You shouldn't use timer, if you use timer and clear the grid list and then re add the rows, you will not be able to select anything in the grid list.

You should update the grid list with events onClientPlayerJoin and onClientPlayerQuit and onClientPlayerChangeNick.

CiTLh.png
Posted
You shouldn't use timer, if you use timer and clear the grid list and then re add the rows, you will not be able to select anything in the grid list.

You should update the grid list with events onClientPlayerJoin and onClientPlayerQuit and onClientPlayerChangeNick.

It's updated every 2 seconds, there's nothing stopping from select anything.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted (edited)

I am sorry, but Anderl, the grid list player names isn't being updated

EDIT: everything i tried to change, isn't updating ..

Edited by Guest

Looking for tutorials or information? check out: www.simpleask.co.uk

Posted
You shouldn't use timer, if you use timer and clear the grid list and then re add the rows, you will not be able to select anything in the grid list.

You should update the grid list with events onClientPlayerJoin and onClientPlayerQuit and onClientPlayerChangeNick.

It's updated every 2 seconds, there's nothing stopping from select anything.

Try to select anything and after 2 second, you will lose what you select and the scroll bar will back to top again.

CiTLh.png
Posted
local Column = guiGridListAddColumn ( Grid, "Player", 0.85 ) 
  
function playerList ( ) 
    guiGridListClear ( Grid ) 
    if ( Column ) then 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            local Row = guiGridListAddRow ( Grid ) 
            guiGridListSetItemText ( Grid, Row, Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) 
        end 
    end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, playerList ) 
addEventHandler ( "onClientPlayerJoin", root, playerList ) 
addEventHandler ( "onClientPlayerQuit", root, playerList ) 
addEventHandler ( "onClientPlayerChangeNick", root, playerList ) 

@Anderl:

You could have used: guiGridListClear instead of:

for i = 1, #guiGridListGetRowCount(Grid) do 
        guiGridListRemoveRow(Grid, i) 
end 

Also, you placed the timer inside the for-loop.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
function playerList ( ) 
    local Column = guiGridListAddColumn ( Grid, "Player", 0.85 ) 
    if ( Column ) then 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            local Row = guiGridListAddRow ( Grid ) 
            guiGridListSetItemText ( Grid, Row, Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) 
        end 
    end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, playerList ) 
addEventHandler ( "onClientPlayerJoin", root, playerList ) 
addEventHandler ( "onClientPlayerQuit", root, playerList ) 
addEventHandler ( "onClientPlayerChangeNick", root, playerList ) 

@Anderl:

You could have used: guiGridListClear instead of:

for i = 1, #guiGridListGetRowCount(Grid) do 
        guiGridListRemoveRow(Grid, i) 
end 

Also, you placed the timer inside the for-loop.

Heh, my bad, didn't even see ._.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

Yeah, I forgot to clear it first, copy my code again.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Must be because it was creating column every time, I moved it outside the update function, copy it again.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)

Try

function playerList() 
     Column = guiGridListAddColumn(Grid, "Player", 0.85) 
     if (Column) then 
          for _, player in ipairs (getElementsByType("player")) do 
               local Row = guiGridListAddRow(Grid) 
               guiGridListSetItemText (Grid, Row, Column, getPlayerName(player):gsub("#%x%x%x%x%x%x", ""), false, false) 
          end 
     end 
end 
addEventHandler("onClientResourceStart", resourceRoot, playerList) 
  
function updateList(old, new) 
     if eventName == "onClientPlayerJoin"  then 
          local i = guiGridListAddRow(Grid) 
          guiGridListSetItemText(Grid, i, Column, getPlayerName(source):gsub("#%x%x%x%x%x%x", ""), false, false) 
     elseif eventName == "onClientPlayerQuit"  then 
          for i=0, guiGridListGetRowCount(Grid) do 
               if guiGridListGetItemText(Grid, i, Column) == getPlayerName(source):gsub("#%x%x%x%x%x%x", "") then 
                    guiGridListRemoveRow(Grid, i) 
               end 
          end 
     elseif eventName == "onClientPlayerChangeNick"  then 
          for i=0, guiGridListGetRowCount(Grid) do 
               if guiGridListGetItemText(Grid, i, Column) == old then 
                    guiGridListSetItemText(Grid, i, Column, new, false, false) 
               end 
          end 
     end 
end 
addEventHandler("onClientPlayerJoin", root, updateList) 
addEventHandler("onClientPlayerQuit", root, updateList) 
addEventHandler("onClientPlayerChangeNick", root, updateList) 

Edited by Guest
CiTLh.png
Posted

@TAPL:

if eventName == "onClientPlayerJoin"  then 
          guiGridListSetItemText(Grid, i, Column, getPlayerName(source):gsub("#%x%x%x%x%x%x", ""), false, false) 

"i" is not defined anywhere.

@manve1: My script should work just fine.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)

Try this:

local Column = guiGridListAddColumn( Grid, "Player", 0.85 ) 
function playerList() 
    if not isElement(Grid) then outputDebugString("Column/Grid not created!") return end 
    for _, player in ipairs(getElementsByType("player")) do 
        guiGridListSetItemText ( Grid, guiGridListAddRow ( Grid ), Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) 
    end 
end 
addEventHandler("onClientResourceStart",resourceRoot, playerList) 
addEventHandler("onClientPlayerJoin", root, playerList) 
addEventHandler("onClientPlayerQuit", root, playerList) 
addEventHandler("onClientPlayerChangeNick", root, playerList) 
  
player_name = guiCreateLabel( 0.325, 0.1, 0.5, 0.2, "PlayerName: ", true, Wnd ) --label is created first 
player_name2 = "PlayerName: "..getPlayerName ( localPlayer ):gsub ( "#%x%x%x%x%x%x", "" ) 
function change_name() 
    local row = guiGridListGetSelectedItem ( Grid ) 
    if row == -1 then 
        guiSetText(player_name,player_name2) 
    else 
        guiSetText( player_name,guiGridListGetItemText(Grid,row,1)) 
    end 
end 
addEventHandler ( "onClientGUIClick", Grid, change_name, false ) 

Edited by Guest

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted
Try this:
function playerList() 
    if not isElement(Column) then 
        local Column = guiGridListAddColumn( Grid, "Player", 0.85 ) 
    end 
    if not(isElement(Column) or isElement(Grid)) then outputDebugString("Column/Grid not created!") return end 
    for _, player in ipairs(getElementsByType("player")) do 
        guiGridListSetItemText ( Grid, guiGridListAddRow ( Grid ), Column, getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ), false, false ) 
    end 
end 
addEventHandler("onClientResourceStart",resourceRoot, playerList) 
addEventHandler("onClientPlayerJoin", root, playerList) 
addEventHandler("onClientPlayerQuit", root, playerList) 
addEventHandler("onClientPlayerChangeNick", root, playerList) 

Columns aren't elements.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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