Jump to content

Wanted


TorNix~|nR

Recommended Posts

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.

Link to comment

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 by Fist
  • Like 1
Link to comment

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);

 

  • Like 1
Link to comment

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  
)

 

Link to comment
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?

Link to comment
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);

 

  • Like 1
Link to comment
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

 

  • Like 1
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...