Raised This Month: $51 Target: $400
 12% 

Looping through players help needed


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lolkoun
Junior Member
Join Date: Dec 2017
Old 04-05-2020 , 08:20   Looping through players help needed
Reply With Quote #1

Hello, I am trying to create a menu where I loop through clients and then set render color to the selected one.
I am not so experienced in C++/pawn so I appreciate any help.
I am getting errors:
Code:
// menu_callbacks.sp(181) : warning 213: tag mismatch
// menu_callbacks.sp(181) : error 035: argument type mismatch (argument 2)
// menu_callbacks.sp(181) : error 035: argument type mismatch (argument 3)
// menu_callbacks.sp(182) : warning 213: tag mismatch
// menu_callbacks.sp(182) : error 178: cannot coerce int[] to char[]; storage classes differ
I guess my error is in parsing the data and its data types?
My menu:
Code:
public void CreateColorMenu(int client)
{
  Menu menu = CreateMenu(h_colormenu);
  menu.SetTitle("Color player:");
  
  for (int i = 1; i <= MaxClients; i++) {
    if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == 1) {
        char userid[32];
        char username[128];
        GetClientName(i, username, sizeof(username));
        IntToString(i, userid, sizeof(userid));
        Format(username, sizeof(username), "%N", i);
        menu.AddItem(userid,username);
    }
  } 
  menu.ExitBackButton = true;
  menu.Display(client,MENU_TIME_FOREVER);
}
My menuh
Code:
public int h_colormenu(Menu menu, MenuAction action, int param1, int param2)
{
  if(action == MenuAction_Select)
  {
  		        int info[32];
line 181		GetMenuItem(param2, info, sizeof(info));
line 182		int userid = StringToInt(info);
		        int target = GetClientOfUserId(userid);

		if ((target) == 0)
		{
			PrintToChat(param1, "[SM] %t", "Cant color");
		}
		else if (!CanUserTarget(param1, target))
		{
			PrintToChat(param1, "[SM] %t", "Cant target");
		}
		else
		{
			char name[MAX_NAME_LENGTH];
			GetClientName(target, name, sizeof(name));
			ShowActivity2(param1, "[SM] ", "%t", "Player colored:", "_s", name);
			SetEntityRenderColor(target, 204,0,204,255);
		}
  }
  else if(action == MenuAction_Cancel)
  {
    if(param2 == MenuCancel_ExitBack)
    {
      CreateMainMenu(param2);
    }
  }
}

Last edited by Lolkoun; 04-05-2020 at 08:33.
Lolkoun is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 04-05-2020 , 08:31   Re: Looping through players help needed
Reply With Quote #2

What is line 181 182?
__________________
8guawong is offline
Lolkoun
Junior Member
Join Date: Dec 2017
Old 04-05-2020 , 08:32   Re: Looping through players help needed
Reply With Quote #3

Quote:
Originally Posted by 8guawong View Post
What is line 181 182?
181 GetMenuItem(param2, info, sizeof(info));
182 int userid = StringToInt(info);
Lolkoun is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 04-05-2020 , 09:01   Re: Looping through players help needed
Reply With Quote #4

Line 180 change to char info[32];
__________________
8guawong is offline
Lolkoun
Junior Member
Join Date: Dec 2017
Old 04-05-2020 , 09:55   Re: Looping through players help needed
Reply With Quote #5

Quote:
Originally Posted by 8guawong View Post
Line 180 change to char info[32];
Oh. I can't believe it was that stupid mistake. I was stuck on this for a few hours and was really sure I have it right. And this was clearly a thing I wrote wrong and didn't notice. Damn I really thought I set it as char.
Thank you very much
Lolkoun is offline
Lolkoun
Junior Member
Join Date: Dec 2017
Old 04-05-2020 , 10:12   Re: Looping through players help needed
Reply With Quote #6

Now it compiles without error, but when called, the menu doesn't appear. Can anyone give me a hint? I guess the problem is in the looping?
Lolkoun is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 04-05-2020 , 10:45   Re: Looping through players help needed
Reply With Quote #7

Check your error logs
__________________
8guawong is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 04-06-2020 , 07:53   Re: Looping through players help needed
Reply With Quote #8

Maybe you should check here:

GetClientTeam(i) == 1

Usually, Team = 1 means spectator.

Try to remove it and check if players appear on the menu.

Also, you don't need the GetClientName part, the %N already does that for you.
__________________

Last edited by Marttt; 04-06-2020 at 07:54.
Marttt is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:41.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode