Help It works, and then screws up
#1
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?

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?
(08-10-2011, 12:58)Pozzuh Wrote:
Se7en Wrote:Stealed, from cod4 mod ...
look who's talking

[Release] Old School Mod v2.2
[Release] Scroll menu

Reply

#2
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?
[Image: MaEIQ.png]
Reply

#3
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
[Image: b_560_95_1.png]
Reply

#4
I'm just thinking way too much... It would be much easier like this

Code:
for( i = 0; i < maps.size; i++ ) if( isDefined( dvars[ maps[i] ] ) && dvars[ maps[i] ] ) { self setDebugDvar( maps[i], true ); } else { self setDebugDvar( maps[i], false ); }

and define the level. vars as level.var[ "mapname" ] = true;

=.=

Thanks anyway ^^
(08-10-2011, 12:58)Pozzuh Wrote:
Se7en Wrote:Stealed, from cod4 mod ...
look who's talking

[Release] Old School Mod v2.2
[Release] Scroll menu

Reply

#5
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. Tongue
Reply

#6
(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
(08-10-2011, 12:58)Pozzuh Wrote:
Se7en Wrote:Stealed, from cod4 mod ...
look who's talking

[Release] Old School Mod v2.2
[Release] Scroll menu

Reply

#7
(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 ");
[Image: b_560_95_1.png]
Reply

#8
(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.
Reply

#9
(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_" ) ) ..?
(08-10-2011, 12:58)Pozzuh Wrote:
Se7en Wrote:Stealed, from cod4 mod ...
look who's talking

[Release] Old School Mod v2.2
[Release] Scroll menu

Reply

#10
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); }
[Image: b_560_95_1.png]
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  SecondaryWeaponAkimbo works but cant fire JoSchaap 12 11,352 07-06-2012, 16:59
Last Post: [Z00MBY] Alex
  How ItsMods works for me Arteq 15 11,241 05-29-2012, 07:52
Last Post: JariZ
  First the timer works, now it doesnt show up !? Xzite 2 2,946 03-17-2012, 00:28
Last Post: Xzite
  Code works, but after a while it doesnt !? Xzite 3 3,958 03-16-2012, 14:29
Last Post: Xzite
  Mod Menu for BO that works on ranked ModLover1 4 3,099 01-28-2012, 12:20
Last Post: d0h!
  Fixed! With English language it works! Elite_Nudel 10 9,323 12-19-2011, 06:46
Last Post: Elite_Nudel
  [Tutorial] Custom ranks in MW2 (Works on Steam and aIW) Nekochan 4 3,648 07-29-2011, 11:08
Last Post: d0h!
  [Tutorial] Color Name... It works... dropi 6 5,295 11-30-2010, 16:02
Last Post: Julio

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2026 Melroy van den Berg.