TorNix~|nR Posted April 18, 2017 Posted April 18, 2017 hello guys, I want a Wanted command, when says with command /wanted it shows you all list of players with wanted levels for example TorNix~|nR has 3 wanted levels Test has 2 wanted levels Help please ? Sorry for the spam guys, it's the forum bug it says 404 Not Found ngix sorry.
AE. Posted April 18, 2017 Posted April 18, 2017 create a grid list and loop players and check they have a wanted level more than 0 and add them to rows 1
Fist Posted April 19, 2017 Posted April 19, 2017 (edited) will you ever learn how to do something by yourself ? This is dozen topic of you asking simple :~. but anyway this should work, not tested tho. local sW,sH = guiGetScreenSize(); local wantedlist = {window={},grid={}}; local mwW,mwH = 500,500; local wantedlist.window[1] = guiCreateWindow(sW*0.5-mwW/2,sH*0.5-mwH/2,mwW,mwH,"players with wanted stars",false); local wantedlist.grid[1] = guiCreateGridList(0,0,mwW-5,mwH-5,false,wantedlist.window[1]); guiGridListAddColumn(wantedlist.grid[1],"Player",0.5); guiGridListAddColumn(wantedlist.grid[1],"Wanted Level",0.4); function updateWantedList() guiGridListClear(wantedlist.grid[1]); for _,v in pairs(getElementsByType("player")) do local wantedlevel = getPlayerWantedLevel(v); if (wantedlevel > 0) then local row = guiGridListAddRow(wantedlist.grid[1]); guiGridListSetItemText(wantedlist.grid[1],row,1,getPlayerName(v):gsub("#%x%x%x%x%x%x",""),false,false) guiGridListSetItemText(wantedlist.grid[1],row,1,wantedlevel,false,false) end end end addCommandHandler("wantedplayers",function() if guiGetVisible(wantedlist.window[1]) then guiSetVisible(wantedlist.window[1],false); else guiSetVisible(wantedlist.window[1],true); updateWantedList(); end end); Edited April 19, 2017 by Fist 1
Fist Posted April 19, 2017 Posted April 19, 2017 lol accidently put 2 variables as local even tho they souldn't been local here is fixed code + added one more thing local sW,sH = guiGetScreenSize(); local wantedlistgui = {window={},grid={}} local mwW,mwH = 500,500; wantedlistgui.window[1] = guiCreateWindow(sW*0.5-mwW/2,sH*0.5-mwH/2,mwW,mwH,"players with wanted stars",false); wantedlistgui.grid[1] = guiCreateGridList(0,25,mwW-5,mwH-30,false,wantedlistgui.window[1]); guiSetVisible(wantedlistgui.window[1],false) guiGridListAddColumn(wantedlistgui.grid[1],"Player",0.5); guiGridListAddColumn(wantedlistgui.grid[1],"Wanted Level",0.4); function updateWantedList() guiGridListClear(wantedlistgui.grid[1]); for _,v in pairs(getElementsByType("player")) do local wantedlevel = getPlayerWantedLevel(v); if (wantedlevel > 0) then local row = guiGridListAddRow(wantedlistgui.grid[1]); guiGridListSetItemText(wantedlistgui.grid[1],row,1,getPlayerName(v):gsub("#%x%x%x%x%x%x",""),false,false) guiGridListSetItemText(wantedlistgui.grid[1],row,2,wantedlevel,false,false) end end if (guiGridListGetRowCount(wantedlistgui.grid[1]) == 0) then local row = guiGridListAddRow(wantedlistgui.grid[1]); guiGridListSetItemText(wantedlistgui.grid[1],row,1,"no players found with wanted levels",false,false) guiGridListSetItemText(wantedlistgui.grid[1],row,2,"",false,false) end end addCommandHandler("wantedplayers",function() if guiGetVisible(wantedlistgui.window[1]) then guiSetVisible(wantedlistgui.window[1],false); else guiSetVisible(wantedlistgui.window[1],true); updateWantedList(); end end); 1
TorNix~|nR Posted April 19, 2017 Author Posted April 19, 2017 Thank you guys @Fist, 2 bugs found, when open it, it shows no players found with wanted levels, and you can move the mouse on it also I made a script server-side it works fine, but I want only showing the wanted players, it shows everyone, even with 0 wanted level, help please? Code: addCommandHandler("wantedlevels", function(playerSource) for _, thePlayer in ipairs(getElementsByType("player")) do local level = getPlayerWantedLevel ( thePlayer ) outputChatBox("* "..getPlayerName(thePlayer).."has "..level.." wanted levels", playerSource) end end )
TorNix~|nR Posted April 19, 2017 Author Posted April 19, 2017 (edited) @Fist thanks for the panel, can you only help me on my code please :)? Edited April 19, 2017 by TorNix~|nR
Fist Posted April 19, 2017 Posted April 19, 2017 Just now, TorNix~|nR said: @Fist thanks for the panel, can you only help me on my code please :)? omg, just add check variable if wanted level is more than 0.
TorNix~|nR Posted April 19, 2017 Author Posted April 19, 2017 addCommandHandler("wantedplayers", function(playerSource) for _, thePlayer in ipairs(getElementsByType("player")) do local level = getPlayerWantedLevel ( thePlayer ) if not ( level > 0 ) then outputChatBox("* "..getPlayerName(thePlayer).."has "..level.." wanted levels", playerSource) end end end ) I tried this, isn't worked, help please?
Fist Posted April 19, 2017 Posted April 19, 2017 1 minute ago, TorNix~|nR said: works, thanks @Fist btw i added buttons to the panel, i think you'd have easier use with this one. local sW,sH = guiGetScreenSize(); local wantedlistgui = {window={},grid={},button={}} local mwW,mwH = 500,500; wantedlistgui.window[1] = guiCreateWindow(sW*0.5-mwW/2,sH*0.5-mwH/2,mwW,mwH,"players with wanted stars",false); wantedlistgui.grid[1] = guiCreateGridList(0,25,mwW-5,mwH-65,false,wantedlistgui.window[1]); wantedlistgui.button[1] = guiCreateButton(0,mwH-40,mwW/2-17,30,"update gridlist",false,wantedlistgui.window[1]); wantedlistgui.button[2] = guiCreateButton(mwW/2-5,mwH-40,mwW/2+17,30,"close gui",false,wantedlistgui.window[1]); guiSetVisible(wantedlistgui.window[1],false) guiGridListAddColumn(wantedlistgui.grid[1],"Player",0.5); guiGridListAddColumn(wantedlistgui.grid[1],"Wanted Level",0.4); function updateWantedList() guiGridListClear(wantedlistgui.grid[1]); for _,v in pairs(getElementsByType("player")) do local wantedlevel = getPlayerWantedLevel(v); if (wantedlevel > 0) then local row = guiGridListAddRow(wantedlistgui.grid[1]); guiGridListSetItemText(wantedlistgui.grid[1],row,1,getPlayerName(v):gsub("#%x%x%x%x%x%x",""),false,false) guiGridListSetItemText(wantedlistgui.grid[1],row,2,wantedlevel,false,false) end end if (guiGridListGetRowCount(wantedlistgui.grid[1]) == 0) then local row = guiGridListAddRow(wantedlistgui.grid[1]); guiGridListSetItemText(wantedlistgui.grid[1],row,1,"no players found with wanted levels",false,false) guiGridListSetItemText(wantedlistgui.grid[1],row,2,"",false,false) end end addEventHandler("onClientGUIClick",root,function() if (source == wantedlistgui.button[1]) then updateWantedList(); elseif (source == wantedlistgui.button[2]) then guiSetVisible(wantedlistgui.window[1],false); showCursor(false); end end); addCommandHandler("wantedplayers",function() if not guiGetVisible(wantedlistgui.window[1]) then guiSetVisible(wantedlistgui.window[1],true); showCursor(true); updateWantedList(); end end); 1
TorNix~|nR Posted April 19, 2017 Author Posted April 19, 2017 Yeah worked, but there is a little bug I have 1 wanted level, all players showed with 1 wanted level like me.
NeXuS™ Posted April 19, 2017 Posted April 19, 2017 These are the basics mate. You should read the LUA 5.3 Reference Manual if you can understand english well. If you cannot, you should just start scripting, and check if you have any information about "Scripting in MTA" in your language. (MTA:SA wiki page)
Fist Posted April 19, 2017 Posted April 19, 2017 1 minute ago, TorNix~|nR said: Yeah worked, but there is a little bug I have 1 wanted level, all players showed with 1 wanted level like me. what? makes no sense. Try replacing updateWantedList with this one function updateWantedList() guiGridListClear(wantedlistgui.grid[1]); for _,v in pairs(getElementsByType("player")) do if (getPlayerWantedLevel(v) > 0) then local row = guiGridListAddRow(wantedlistgui.grid[1]); guiGridListSetItemText(wantedlistgui.grid[1],row,1,getPlayerName(v):gsub("#%x%x%x%x%x%x",""),false,false) guiGridListSetItemText(wantedlistgui.grid[1],row,2,getPlayerWantedLevel(v),false,false) end end if (guiGridListGetRowCount(wantedlistgui.grid[1]) == 0) then local row = guiGridListAddRow(wantedlistgui.grid[1]); guiGridListSetItemText(wantedlistgui.grid[1],row,1,"no players found with wanted levels",false,false) guiGridListSetItemText(wantedlistgui.grid[1],row,2,"",false,false) end end 1
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