Raised This Month: $32 Target: $400
 8% 

Storing UserIds in an Array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kasikadam
Member
Join Date: Jun 2016
Old 06-19-2019 , 09:12   Storing UserIds in an Array
Reply With Quote #1

I want to make a plugin, when a player types !join, plugin will store players userid in an array and randomly select 2 userids. I wrote this piece of code but when i try to compile i get this error :
error 035: argument type mismatch (argument 2) at PushArrayString line
Code:
public Action Join(client, args)
{
	CPrintToChat(client, "Okay..");
	new String:struserid = GetClientUserId(client);
	PushArrayString(arr, struserid);
	return Plugin_Continue;
}
kasikadam is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 06-19-2019 , 09:23   Re: Storing UserIds in an Array
Reply With Quote #2

Use PushArrayCell() instead PushArrayString(). And don't try convert int to string.
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...

Last edited by CrazyHackGUT; 06-19-2019 at 09:23.
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 06-19-2019 , 09:45   Re: Storing UserIds in an Array
Reply With Quote #3

Code:
public Action Join(client, args)
{
	CPrintToChat(client, "Okay..");
	new struserid = GetClientUserId(client);
	PushArrayCell(arr, struserid);
	return Plugin_Continue;
}
__________________
8guawong is offline
kasikadam
Member
Join Date: Jun 2016
Old 06-19-2019 , 09:59   Re: Storing UserIds in an Array
Reply With Quote #4

Thank you it works now but players can join multiple times how can i prevent this?
kasikadam is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 06-19-2019 , 10:10   Re: Storing UserIds in an Array
Reply With Quote #5

Quote:
Originally Posted by kasikadam View Post
Thank you it works now but players can join multiple times how can i prevent this?
you loop through the array and check if userid is in already in it or not
if not then PushArrayCell
__________________
8guawong is offline
kasikadam
Member
Join Date: Jun 2016
Old 06-19-2019 , 10:24   Re: Storing UserIds in an Array
Reply With Quote #6

Quote:
Originally Posted by 8guawong View Post
you loop through the array and check if userid is in already in it or not
if not then PushArrayCell
something like that ?
Code:
	new abc;
	for (abc = 1; abc <= GetArraySize(arr); ++abc){
		if FindValueInArray(arr, strone) == -1{
			PushArrayCell(arr, strone);
		}
	}
kasikadam is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 06-19-2019 , 11:23   Re: Storing UserIds in an Array
Reply With Quote #7

No. Just use FindValueInArray().

Something like this:
Code:
public Action Join(client, args)
{
	int iUserID = GetClientUserId(client);
	if (FindValueInArray(arr, iUserID) == -1)
	{
		CPrintToChat(client, "Okay..");
		PushArrayCell(arr, iUserID);
	} else {
		CPrintToChat(client, "Not okay. You already joined.");
	}
	return Plugin_Handled;
}
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...

Last edited by CrazyHackGUT; 06-19-2019 at 11:29.
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 06-19-2019 , 13:30   Re: Storing UserIds in an Array
Reply With Quote #8

Quote:
Originally Posted by CrazyHackGUT View Post
No. Just use FindValueInArray().

Something like this:
Code:
public Action Join(client, args)
{
	int iUserID = GetClientUserId(client);
	if (FindValueInArray(arr, iUserID) == -1)
	{
		CPrintToChat(client, "Okay..");
		PushArrayCell(arr, iUserID);
	} else {
		CPrintToChat(client, "Not okay. You already joined.");
	}
	return Plugin_Handled;
}
didn't know about FindValueInArray()
__________________
8guawong is offline
kasikadam
Member
Join Date: Jun 2016
Old 06-19-2019 , 16:54   Re: Storing UserIds in an Array
Reply With Quote #9

Quote:
Originally Posted by CrazyHackGUT View Post
No. Just use FindValueInArray().

Something like this:
Code:
public Action Join(client, args)
{
	int iUserID = GetClientUserId(client);
	if (FindValueInArray(arr, iUserID) == -1)
	{
		CPrintToChat(client, "Okay..");
		PushArrayCell(arr, iUserID);
	} else {
		CPrintToChat(client, "Not okay. You already joined.");
	}
	return Plugin_Handled;
}
makes more sense thank you !
kasikadam is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 06-25-2019 , 18:27   Re: Storing UserIds in an Array
Reply With Quote #10

Quote:
Originally Posted by kasikadam View Post
makes more sense thank you !
Don't forget:

public OnClientDisconnect(client)
{
new slot = FindValueInArray(Array, GetClientUserId(client));

if(slot != -1)
RemoveFromArray(Array, slot);
}

Note that I may mistaken the names of the functions.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Reply


Thread Tools
Display Modes

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 02:06.


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