NickScripter Posted August 18, 2019 Posted August 18, 2019 (edited) Hello!! I'm having a little trouble showing the names of the near players on the weapon sales list. I am trying to do it this way: function putPlayers() guiGridListClear(players_grid) if (source and isElement(source) and getElementType(source) == "player") and localPlayer ~= source then local sX, sY, sZ = getElementPosition(localPlayer) local rX, rY, rZ = getElementPosition(source) local distance = getDistanceBetweenPoints3D(sX, sY, sZ, rX, rY, rZ) if distance <= range then for _,player in ipairs(getElementsByType("player")) do local row = guiGridListAddRow(players_grid) guiGridListSetItemText(players_grid,row,1,getPlayerName(source),false,false) end else guiGridListClear(players_grid) end end end I have no idea how i can do it XD Edited August 18, 2019 by Nickqq
sacr1ficez Posted August 18, 2019 Posted August 18, 2019 1 hour ago, Nickqq said: Hello!! I'm having a little trouble showing the names of the near players on the weapon sales list. I am trying to do it this way: function putPlayers() guiGridListClear(players_grid) if (source and isElement(source) and getElementType(source) == "player") and localPlayer ~= source then local sX, sY, sZ = getElementPosition(localPlayer) local rX, rY, rZ = getElementPosition(source) local distance = getDistanceBetweenPoints3D(sX, sY, sZ, rX, rY, rZ) if distance <= range then for _,player in ipairs(getElementsByType("player")) do local row = guiGridListAddRow(players_grid) guiGridListSetItemText(players_grid,row,1,getPlayerName(source),false,false) end else guiGridListClear(players_grid) end end end I have no idea how i can do it XD local players = getElementsByType("player") -- get all players for i = 1, #players do -- use int loop, no need for ipairs unless you need sorting, it's better for performance. local player = players[i] -- get player if player then local player_name = getPlayerName(player) local row = guiGridListAddRow(players_grid) guiGridListSetItemText(players_grid, row, 1, player_name, false, false) end end Adjust it to your code, i doubt that you've checked debugscript 3 for errors/warnings.
NickScripter Posted August 18, 2019 Author Posted August 18, 2019 I want to show on the list only the close ranged players, not everyone
sacr1ficez Posted August 18, 2019 Posted August 18, 2019 11 minutes ago, Nickqq said: I want to show on the list only the close ranged players, not everyone That's why i noticed you about that: Adjust it to your code You should do it by yourself, if something will not work let me know.
NickScripter Posted August 18, 2019 Author Posted August 18, 2019 I have no idea how i can do it =/ tryed everything..
sacr1ficez Posted August 18, 2019 Posted August 18, 2019 (edited) 1 hour ago, Nickqq said: I have no idea how i can do it =/ tryed everything.. Okey. I will try to help you a bit with it. First of all, this is function called only on client or it's function from event handler? I'm wondering because you used source. Provide me more information so i could help you. Edited August 18, 2019 by majqq
NickScripter Posted August 18, 2019 Author Posted August 18, 2019 10 minutes ago, majqq said: Okey. I will try to help you a bit with it. First of all, this is function called only on client or it's function from event handler? I'm wondering because you used source. Provide me more information so i could help you. Okay... It is a client only that through this function identifies nearby players and lists them.
sacr1ficez Posted August 18, 2019 Posted August 18, 2019 3 hours ago, Nickqq said: Okay... It is a client only that through this function identifies nearby players and lists them. Should work, untested. function putPlayers() guiGridListClear(players_grid) -- i've deleted conditions which didn't make any sense... local players = getElementsByType("player") -- get all players for i = 1, #players do -- use int loop, no need for ipairs unless you need sorting, it's better for performance. local player = players[i] -- get player if player and player ~= getLocalPlayer() then -- remove player ~= getLocalPlayer() if you want to count yourself local x, y, z = getElementPosition(getLocalPlayer()) -- get position of local player local posX, posY, posZ = getElementPosition(player) -- get position of another player local distance = getDistanceBetweenPoints3D(x, y, z, posX, posY, posZ) if distance <= 30 then -- range local player_name = getPlayerName(player) local row = guiGridListAddRow(players_grid) guiGridListSetItemText(players_grid, row, 1, player_name, false, false) end end end end
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now