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?
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?
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
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.
(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
(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.
(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_" ) ) ..?
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);
}