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

Error 006: Must be assigned to an array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thecount
Veteran Member
Join Date: Jul 2013
Old 07-09-2013 , 18:57   Error 006: Must be assigned to an array
Reply With Quote #1

Some reason my mapcycle.txt/.cfg don't work and the map has to be changed manually otherwise the server will stay on the same map. So, I decided to program a plugin that flips through all the arena maps at the end of each map's time. And I get the error in the title for whenever I attempt to put a string into an array's cell. Below is the code.

Code:
#include <sourcemod>

public Plugin:myinfo = {
	name = "Automatic Vote",
	author = "The Count",
	description = "Creates a vote for next map at the current map's end.",
	url = ""
}

new String:nowMap[64];
new ListMap[9];
new iMapCount = 9;
new iMapNumber = 0;

public OnPluginStart() {
	ListMap[0] = "arena_lumberyard";
	ListMap[1] = "arena_ravine";
	ListMap[2] = "arena_badlands";
	ListMap[3] = "arena_granary";
	ListMap[4] = "arena_well";
	ListMap[5] = "arena_watchtower";
	ListMap[6] = "arena_sawmill";
	ListMap[7] = "arena_nucleus";
	ListMap[8] = "arena_offblast_final";
	
	RegConsoleCmd("sm_followmap", Command_FollowMap, "");
}

public OnMapEnd() {
	GetCurrentMap(nowMap, sizeof(nowMap));
	while (iMapNumber<9) {
		if ((strcmp(nowMap, ListMap[iMapNumber]))==true) {
			iMapNumber++;
			ServerCommand("sm_map %s", ListMap[iMapNumber]);
			iMapNumber=9;
		}else {
			iMapNumber++;
		}
	}
	iMapNumber = 0;
}


public Action:Command_FollowMap (client) {


		GetCurrentMap(nowMap, sizeof(nowMap));
	while (iMapNumber<9) {
		if ((strcmp(nowMap, ListMap[iMapNumber]))==true) {
			PrintToChat(client, "[SM] The following map: %s", ListMap[iMapNumber]);
			iMapNumber = 9;
		}else {
			iMapNumber++;
		}
	}
	
	iMapNumber = 0;
	
}


Logically, I thought it would work fine but apparently I have a problem with putting strings in the array. I already looked around the interwebs for answers to this problem but nothing seems to really help and I would just like someone to answer to my problem directly. Sorry if I'm being stupid, but this is like my third day of trying to program plugins.

Last edited by thecount; 07-09-2013 at 19:02.
thecount is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-09-2013 , 19:17   Re: Error 006: Must be assigned to an array
Reply With Quote #2

You've declared ListMap as a one-dimensional array of numbers.

In fact, you probably want to do this instead:

PHP Code:
new String:ListMap[][] = {
    
"arena_lumberyard",
    
"arena_ravine",
    
"arena_badlands",
    
"arena_granary",
    
"arena_well",
    
"arena_watchtower",
    
"arena_sawmill",
    
"arena_nucleus",
    
"arena_offblast_final"
 
}; 
A point to note: Strings are technically an array. So, an array of strings is a two-dimensional array. I don't need to give it the dimension sizes there because I delcared the array in-line.

Now, having said that... are there any errors related to mapcycle.txt in your server's log or the SourceMod log? Maybe something about the SourceMod NextMap plugin?
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 07-09-2013 at 19:25.
Powerlord is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 07-09-2013 , 19:30   Re: Error 006: Must be assigned to an array
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
Now, having said that... are there any errors related to mapcycle.txt in your server's log or the SourceMod log? Maybe something about the SourceMod NextMap plugin?

All I know is that whenever I start the server, it says that it is using mapcycle.txt, but it doesn't work. Whenever I type in !nextmap it just gives me the currentmap, because that is what it uses next.
thecount is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 07-09-2013 , 20:07   Re: Error 006: Must be assigned to an array
Reply With Quote #4

Well, the plugin doesn't work anyways. :/
thecount is offline
mcpan313
Senior Member
Join Date: Mar 2010
Old 07-10-2013 , 00:53   Re: Error 006: Must be assigned to an array
Reply With Quote #5

PHP Code:
new Handle:g_hMapList;
new 
String:g_szNextMap[64];

public 
OnPluginStart()
{
    
g_hMapList CreateArray(64);

    
PushArrayString(g_hMapList"arena_lumberyard");
    
PushArrayString(g_hMapList"arena_ravine");
    
PushArrayString(g_hMapList"arena_badlands");
    
PushArrayString(g_hMapList"arena_granary");
    
PushArrayString(g_hMapList"arena_well");
    
PushArrayString(g_hMapList"arena_watchtower");
    
PushArrayString(g_hMapList"arena_sawmill");
    
PushArrayString(g_hMapList"arena_nucleus");
    
PushArrayString(g_hMapList"arena_offblast_final");

    
RegConsoleCmd("sm_followmap"Command_FollowMap);

    
// And you can
    // RegServerCmd("sm_addmap", SrvCmd_AddMapToList);
    // RegServerCmd("sm_delmap", SrvCmd_RemoveMapFromList);
}

public 
OnMapStart()
{
    
GetFollowMap(g_szNextMapsizeof(g_szNextMap));
}

public 
OnMapEnd()
{
    
// NOT THIS? ServerCommand("changelevel %s", g_szNextMap);
    
ServerCommand("sm_map %s"g_szNextMap);
}

public 
Action:Command_FollowMap(clientargs)
{
    if (
client && IsClientInGame(client))
    {
        
PrintToChat(client"[SM] The following map: %s"g_szNextMap);
    }

    return 
Plugin_Handled;
}

stock GetFollowMap(String:follow[], maxlength)
{
    
decl String:current[64];
    
GetCurrentMap(currentsizeof(current));

    new 
arraySize GetArraySize(g_hMapList);
    new 
index FindStringInArray(g_hMapListcurrent);
    if (
index == -1)
    {
        
// Current map not in list :(
        
index GetRandomInt(0arraySize 1);
    }
    else if (++
index == arraySize)
    {
        
index 0;
    }

    return 
GetArrayString(g_hMapListindexfollowmaxlength);
}

/*
public Action:SrvCmd_AddMapToList(args)
{
    if (args != 1)
    {
        PrintToServer("Usage: sm_addmap <mapname>");
        return;
    }

    decl String:mapname[64];
    GetCmdArg(1, mapname, sizeof(mapname));

    if (FindStringInArray(g_hMapList, mapname) != -1)
    {
        PrintToServer("Map:(%s) already in list", mapname);
        return;
    }

    if (!IsMapValid(mapname))
    {
        PrintToServer("Map:(%s) is invalid", mapname);
        return;
    }

    PushArrayString(g_hMapList, mapname);
    PrintToServer("Map:(%s) add success", mapname);
}

public Action:SrvCmd_RemoveMapFromList(args)
{
    if (args != 1)
    {
        PrintToServer("Usage: sm_delmap <mapname>");
        return;
    }

    decl String:mapname[64];
    GetCmdArg(1, mapname, sizeof(mapname));

    new index = FindStringInArray(g_hMapList, mapname);
    if (index == -1)
    {
        PrintToServer("Map:(%s) not in list", mapname);
        return;
    }

    RemoveFromArray(g_hMapList, index);
    PrintToServer("Map:(%s) remove success", mapname);

    // we need refresh next map;
    OnMapStart();
}
*/ 
__________________
sorry, for my poor english.

Last edited by mcpan313; 07-10-2013 at 01:19.
mcpan313 is offline
Send a message via MSN to mcpan313
thecount
Veteran Member
Join Date: Jul 2013
Old 07-10-2013 , 10:05   Re: Error 006: Must be assigned to an array
Reply With Quote #6

Thanks for making a plugin, but um... well when the maps change it gets stuck in an endless cycle of changing the maps constantly and won't let anyone on because it changes the maps so fast.

I think OnMapEnd is not a good time to change the map. Is there any sort of OnRoundEnd? Then we could do something like:

Code:
plugin OnRoundEnd() {
     GetMapTimeLeft(iTimeLeft);
     if (iTimeLeft == 0) {
          ServerCommand("sm_map ListMap[][]");
     }
}

Last edited by thecount; 07-10-2013 at 10:08.
thecount is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 07-10-2013 , 11:24   Re: Error 006: Must be assigned to an array
Reply With Quote #7

Ok so I was messing with the plugin and all the mapcycle files then suddenly it started working. So, I'm just going to leave it alone and try not to break it. Thanks for your help anyways lol
thecount 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:43.


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