Posts: 1,830
Threads: 104
Joined: Jan 2011
Reputation:
46
10-06-2011, 20:19
(This post was last modified: 10-06-2011, 20:26 by iAegle.)
so every map has its own dvar and first I register the allowed maps in a level. var and make the dvars "1" and then I make the rest of the map dvars "0". the beginning works, the allowed maps get set to "1" but then after that every dvar gets set to "0" o_O?
C++ Code
setMapvoteDvar( dvar ) { mvDvar = spawnStruct(); mvDvar.dvar = dvar; mvDvar.value = 1; level.MapvoteDvars[ level.MapvoteDvars.size ] = mvDvar; } setMapvoteDvars() { dvars = level.MapvoteDvars; for( i = 0; i < dvars.size; i++ ) self setClientDvar( dvars[i].dvar, dvars[i].value ); maps = strTok( "mp_array mp_nuked mp_crisis mp_cosmodrome mp_duga mp_cairo mp_cracked mp_firingrange mp_hanoi mp_havoc mp_mountain mp_radiation mp_russianbase mp_villa mp_stadium mp_kowloon mp_berlinwall2 mp_zoo mp_hotel mp_discovery", " " ); for( i = 0; i < maps.size; i++ ) for( x = 0; x < dvars.size; x++ ) if( maps[i] != dvars[x].dvar ) { self setClientDvar( maps[i], 0 ); break; } }
Am I just being very stupid or what?
Posts: 5,135
Threads: 241
Joined: Nov 2010
Reputation:
100
10-06-2011, 20:26
(This post was last modified: 10-06-2011, 20:28 by Pozzuh.)
You are using i as a far in 2 for loops
edit: not that it matters DERP nvm.
long shot but define the maps var as an array?
Posts: 619
Threads: 30
Joined: Oct 2010
Reputation:
85
10-06-2011, 20:30
(This post was last modified: 10-06-2011, 20:31 by Nukem.)
EDIT: @ Pozzuh , Y U NO POST RIGHT ANSWER?
yes it is a problem with your code it seems.
Code: if( maps[i] != dvars[x].dvar )
{
self setClientDvar( maps[i], 0 );
break;
}
basically you check if maps[i] ( any map name) and compare it with the dvar and if it is not the map, set it to 0
I would do this to fix the problem:
Code: for( i = 0; i < maps.size; i++ )
{
isGoodMapname = false;
for( x = 0; x < dvars.size; x++ )
if( maps[i] == dvars[x].dvar )
{
isGoodMapname = true;
break;
}
if(!isGoodMapname)
self setClientDvar( maps[i], 0 );
}
i'm not exactly sure if this code will actually do what you want to make it do
Posts: 1,830
Threads: 104
Joined: Jan 2011
Reputation:
46
10-06-2011, 20:31
(This post was last modified: 10-06-2011, 20:32 by iAegle.)
Posts: 67
Threads: 4
Joined: Jun 2011
Reputation:
3
10-06-2011, 20:52
(This post was last modified: 10-06-2011, 20:54 by Justin.)
It will almost always set it to zero.
Fix:
Code: for( i = 0; i < maps.size; i++ )
{
newvalue = 0;
for( x = 0; x < dvars.size; x++ )
if( maps[i] == dvars[x].dvar )
{
newvalue = 1;
break;
}
self setClientDvar(maps[i], newvalue );
}
edit: I see i should've refreshed some more cause i see there were already some people before me with answers.
Posts: 1,830
Threads: 104
Joined: Jan 2011
Reputation:
46
(10-06-2011, 20:26)Pozzuh Wrote: You are using i as a far in 2 for loops
edit: not that it matters DERP nvm.
long shot but define the maps var as an array?
Using a strTok basicly does the same and uses less code, I could use Array( "var1", "var2" ); but too lazy to change
Posts: 619
Threads: 30
Joined: Oct 2010
Reputation:
85
(10-06-2011, 20:54)iAegle Wrote: Using a strTok basicly does the same and uses less code, I could use Array( "var1", "var2" ); but too lazy to change
You could even use
Code: maps = strtok(GetDvar("sv_maprotation"), " map ");
Posts: 67
Threads: 4
Joined: Jun 2011
Reputation:
3
(10-06-2011, 20:59)Nukem Wrote: (10-06-2011, 20:54)iAegle Wrote: Using a strTok basicly does the same and uses less code, I could use Array( "var1", "var2" ); but too lazy to change
You could even use
Code: maps = strtok(GetDvar("sv_maprotation"), " map ");
How about the gametypes then? gametypes are also in sv_maprotation.
Posts: 1,830
Threads: 104
Joined: Jan 2011
Reputation:
46
(10-06-2011, 21:01)Justin Wrote: (10-06-2011, 20:59)Nukem Wrote: (10-06-2011, 20:54)iAegle Wrote: Using a strTok basicly does the same and uses less code, I could use Array( "var1", "var2" ); but too lazy to change
You could even use
Code: maps = strtok(GetDvar("sv_maprotation"), " map ");
How about the gametypes then? gametypes are also in sv_maprotation.
if( !isSubStr( maps[i], "mp_" ) ) ..?
Posts: 619
Threads: 30
Joined: Oct 2010
Reputation:
85
10-06-2011, 21:13
(This post was last modified: 10-06-2011, 21:21 by Nukem.)
EDIT: look @ bottom of post
(10-06-2011, 21:01)Justin Wrote: ...
How about the gametypes then? gametypes are also in sv_maprotation.
Well, that code wasn't intended for that but I would just use @ iAegle 's code then.
i'm bored so I coded this though (no idea what-so-ever if it works)
Code: //gametype tdm map mp_cosmodrome map mp_nuked
strings = StrTok(GetDvar("sv_maprotation"), "gametype " + GetDvar("g_gametype"));
for(a = 0; a < strings.size; a++)
new_mapstring += strings[a];
// map mp_cosmodrome map mp_nuked
maps = StrTok(new_mapstring, " map ");
//not sure if the space before the first 'map' (" map") is counted in the array, so I just start with array[1]
for( i = 1; i < maps.size; i++ )
{
//etc...
}
lol you can really just ignore the code now.
The above code that @ iAegle posted will probably not work as a string can have "gametype tdm map mp_lol" and it would return true.
if(GetSubStr(maps[i], 0, 3) == "mp_")
//code...
C++ equivalent:
Code: _strnicmp(string1, string2, max_index)
{
return(GetSubStr(string1, 0, max_index) == string2);
}
|