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

Array not an array?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chiddy
Member
Join Date: Dec 2016
Old 02-03-2017 , 19:42   Array not an array?
Reply With Quote #1

(This is probably a rookie mistake)

So, I'm only new to arrays, and I tried making one

PHP Code:
new Handle:clientarray INVALID_HANDLE;

public 
void OnPluginStart()
{
    
clientarray CreateArray(MAXPLAYERS 1);

Then, I tried this

PHP Code:
decl String:IsInArray[MAX_NAME_LENGTH] = FindStringInArray(clientarray[attacker], dvictim); 
To act for this
PHP Code:
if (IsInArray != -1
Because

"FindStringInArray - Returns the index for the first occurrence of the provided string. If the string cannot be located, -1 will be returned."

But I get this
" error 028: invalid subscript (not an array or too many subscripts): "g_hArray" "

For the line when I declare the string

How would I fix this?

Last edited by Chiddy; 02-03-2017 at 19:42. Reason: Forgot to put the question
Chiddy is offline
Michael Shoe Maker
Senior Member
Join Date: Apr 2016
Old 02-03-2017 , 20:16   Re: Array not an array?
Reply With Quote #2

You're setting a string to an integer.

And even so, you're not indexing the array.

Last edited by Michael Shoe Maker; 02-03-2017 at 20:16.
Michael Shoe Maker is offline
Chiddy
Member
Join Date: Dec 2016
Old 02-03-2017 , 20:23   Re: Array not an array?
Reply With Quote #3

Forgot to mention
PHP Code:
decl String:dvictim[MAX_NAME_LENGTH];
GetClientName(victimdvictimsizeof(dvictim)); 
And what do you mean by indexing it?
Chiddy is offline
Michael Shoe Maker
Senior Member
Join Date: Apr 2016
Old 02-03-2017 , 20:28   Re: Array not an array?
Reply With Quote #4

Quote:
Originally Posted by Chiddy View Post
Forgot to mention
PHP Code:
decl String:dvictim[MAX_NAME_LENGTH];
GetClientName(victimdvictimsizeof(dvictim)); 
And what do you mean by indexing it?
PHP Code:
int Array[10];

Array[
0] = 1;
Array[
1] = 3;
Array[
2] = 566;

Ect... 
Michael Shoe Maker is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-03-2017 , 22:05   Re: Array not an array?
Reply With Quote #5

http://sourcemod.net/new-api/adt_array

You cannot make a String = something through a function. You have to use proper formatting.
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 02-03-2017 at 22:06.
OSWO is offline
Chiddy
Member
Join Date: Dec 2016
Old 02-03-2017 , 22:06   Re: Array not an array?
Reply With Quote #6

Quote:
Originally Posted by Michael Shoe Maker View Post
PHP Code:
int Array[10];

Array[
0] = 1;
Array[
1] = 3;
Array[
2] = 566;

Ect... 
Is there a tutorial on this? I don't exactly understand
Chiddy is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 02-03-2017 , 22:27   Re: Array not an array?
Reply With Quote #7

Quote:
Originally Posted by Chiddy View Post
Is there a tutorial on this? I don't exactly understand
https://wiki.alliedmods.net/Introduc...awn_1.7#Arrays
__________________
Chaosxk is offline
Chiddy
Member
Join Date: Dec 2016
Old 02-03-2017 , 23:40   Re: Array not an array?
Reply With Quote #8

How would I index it if the array is per player and is used to store data after the player attacks someone?
Chiddy is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 02-04-2017 , 01:59   Re: Array not an array?
Reply With Quote #9

Without seeing the rest of your code, i'm unsure whether of not you even need to use ArrayLists. I think you can just use a basic array.

Also you don't need to store strings, just store the victim index and retrieve it and use %N to get the name.

Code:
int clientarray[MAXPLAYERS + 1];

somefunction(int client, int victim)
{
	clientarray[client] = victim;
}

anotherfunction(int client)
{
	PrintToChat(client, "You killed %N", victim);
}
__________________
Chaosxk is offline
Chiddy
Member
Join Date: Dec 2016
Old 02-04-2017 , 06:19   Re: Array not an array?
Reply With Quote #10

Quote:
Originally Posted by Chaosxk View Post
Without seeing the rest of your code, i'm unsure whether of not you even need to use ArrayLists. I think you can just use a basic array.

Also you don't need to store strings, just store the victim index and retrieve it and use %N to get the name.

Code:
int clientarray[MAXPLAYERS + 1];

somefunction(int client, int victim)
{
	clientarray[client] = victim;
}

anotherfunction(int client)
{
	PrintToChat(client, "You killed %N", victim);
}
I need it to be able to carry more than one victim at any time, I tried basic arrays, but they don't work for what I need
Chiddy 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 03:09.


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