Post: C++ if statements/mapname query
02-22-2015, 07:21 PM #1
seanhellen
Are you high?
(adsbygoogle = window.adsbygoogle || []).push({}); Hi all - I have managed to spawn myself a bunker and have gone through the maps and guessed where it should be. Some maps are fine with it being round 0,0,0 (center of the map) but on others it puts it under the map/in a building/somewhere.

So I thought about using if statements so I can put it in the right place depending on what map I am on so I have this;

    if(Func::MapName() == "mp_dome" || Func::MapName() == "mp_mogadishu"|| Func::MapName() == "mp_paris" || Func::MapName() == "mp_bootleg" || Func::MapName() == "mp_alpha" || Func::MapName() == "mp_village" || Func::MapName() == "mp_interchange" || Func::MapName() == "mp_underground" || Func::MapName() == "mp_terminal")
{
Bunker stuff
}
else if(Func::MapName() == "mp_lambeth")
{
Bunker stuff 2
}
else if(Func::MapName() == "mp_seatown" || Func::MapName() == "mp_exchange" || Func::MapName() == "mp_hardhat" || Func::MapName() == "mp_bravo")
{
Bunker stuff 3
}
else if(Func::MapName() == "mp_plaza2")
{
Bunker stuff 4
}
else if(Func::MapName() == "mp_carbon")
{
Bunker stuff 5
}
else if(Func::MapName() == "mp_radar")
{
Bunker Stuff 6
}
else
{
Func::iPrintln(client, "Not Happening!!!");
}


Bunker stuff is co-ords for bunkers...deleted them as this post would be a bit long!!! so as you can see, depending on the map, will determine what co-ords are used for the bunker.

Only problem is that no matter what map i am on, it doesn't spawn a bunker and always comes up with "Not Happening" which i coded to mean somethings wrong. I have used the mapname() function with weapons for dome/other maps so i know it works, but this is the first time I have needed to use else if or || and I am wondering if thats the problem.

To my mind, the coding is right (not missed a bracket or something) as "Not Happening" come up and vs2010 builds it so I dont know. Any help please, Thanks Smile

P.S. Suppose the mapnames could be wrong, but I found them on here, so I think they are right...can't have got them all wrong as bunker wont spawn on any map
(adsbygoogle = window.adsbygoogle || []).push({});
02-24-2015, 02:36 AM #2
SyGnUs
Give a F*** About Your Lifestyle
Originally posted by seanhellen View Post
Hi all - I have managed to spawn myself a bunker and have gone through the maps and guessed where it should be. Some maps are fine with it being round 0,0,0 (center of the map) but on others it puts it under the map/in a building/somewhere.

So I thought about using if statements so I can put it in the right place depending on what map I am on so I have this;

    if(Func::MapName() == "mp_dome" || Func::MapName() == "mp_mogadishu"|| Func::MapName() == "mp_paris" || Func::MapName() == "mp_bootleg" || Func::MapName() == "mp_alpha" || Func::MapName() == "mp_village" || Func::MapName() == "mp_interchange" || Func::MapName() == "mp_underground" || Func::MapName() == "mp_terminal")
{
Bunker stuff
}
else if(Func::MapName() == "mp_lambeth")
{
Bunker stuff 2
}
else if(Func::MapName() == "mp_seatown" || Func::MapName() == "mp_exchange" || Func::MapName() == "mp_hardhat" || Func::MapName() == "mp_bravo")
{
Bunker stuff 3
}
else if(Func::MapName() == "mp_plaza2")
{
Bunker stuff 4
}
else if(Func::MapName() == "mp_carbon")
{
Bunker stuff 5
}
else if(Func::MapName() == "mp_radar")
{
Bunker Stuff 6
}
else
{
Func::iPrintln(client, "Not Happening!!!");
}


Bunker stuff is co-ords for bunkers...deleted them as this post would be a bit long!!! so as you can see, depending on the map, will determine what co-ords are used for the bunker.

Only problem is that no matter what map i am on, it doesn't spawn a bunker and always comes up with "Not Happening" which i coded to mean somethings wrong. I have used the mapname() function with weapons for dome/other maps so i know it works, but this is the first time I have needed to use else if or || and I am wondering if thats the problem.

To my mind, the coding is right (not missed a bracket or something) as "Not Happening" come up and vs2010 builds it so I dont know. Any help please, Thanks Smile

P.S. Suppose the mapnames could be wrong, but I found them on here, so I think they are right...can't have got them all wrong as bunker wont spawn on any map


You can always use a switch statement as well to make it cleaner and it may work better in this example.

Thought that probably isn't going to help solve the problem, so have you tried just doing it on one map? As in not using your whole statement you have up there.

So something like -
    
SpawnBunker()
{
if(MapName() == "mp_terminal")
{
//Spawn Bunker
}
else
{
iPrintln(0, "Couldn't Spawn Bunker for Map");
}
}


You don't really need else-if you can just use if statements -
    
SpawnBunker()
{
if(MapName() == "mp_terminal")
//Spawn Bunker
if(MapName() == "mp_plaza2")
//Spawn Bunker
if(MapName() == "mp_carbon")
//Spawn Bunker
if(MapName() == "mp_radar")
//Spawn Bunker
}


So unless your MapName function isn't working properly it should be fine. You said that it worked for weapons, so in the weapons function put the code to spawn a bunker for a map.
02-24-2015, 05:41 PM #3
seanhellen
Are you high?
Originally posted by SyGnUs View Post


Snip



Hi. Thanks for that. I have just tried a single map but it is still not working. I c&p my working weapons code and changed it for bunker code but no luck;

     
If(Func::mapname() == "mp_dome")
{
Spawn bunker
}
Else
{
Func::iprintln(0,"not happening")
}
02-24-2015, 06:31 PM #4
SyGnUs
Give a F*** About Your Lifestyle
Originally posted by seanhellen View Post
Hi. Thanks for that. I have just tried a single map but it is still not working. I c&p my working weapons code and changed it for bunker code but no luck;

     
If(Func::mapname() == "mp_dome")
{
Spawn bunker
}
Else
{
Func::iprintln(0,"not happening")
}


Not really sure myself, so good luck.
02-24-2015, 11:13 PM #5
seanhellen
Are you high?
Ah well. Thanks anyways Smile I shall continue to have a play.

Anyone else see where ive gone wrong?
03-01-2015, 08:10 PM #6
seanhellen
Are you high?
Originally posted by SyGnUs View Post
You can always use a switch statement as well to make it cleaner and it may work better in this example.

Thought that probably isn't going to help solve the problem, so have you tried just doing it on one map? As in not using your whole statement you have up there.

So something like -
    
SpawnBunker()
{
if(MapName() == "mp_terminal")
{
//Spawn Bunker
}
else
{
iPrintln(0, "Couldn't Spawn Bunker for Map");
}
}


You don't really need else-if you can just use if statements -
    
SpawnBunker()
{
if(MapName() == "mp_terminal")
//Spawn Bunker
if(MapName() == "mp_plaza2")
//Spawn Bunker
if(MapName() == "mp_carbon")
//Spawn Bunker
if(MapName() == "mp_radar")
//Spawn Bunker
}


So unless your MapName function isn't working properly it should be fine. You said that it worked for weapons, so in the weapons function put the code to spawn a bunker for a map.


I think my mapname function might be wrong but it did work for weapons, now it doesn't so something has happened. I have checked;

-typed the function right in weapons/bunker code.
-clicked go to definition in vs2010 and the function seems to be fine - copied it from OSM's script thread in case.
-c&p the dvar_getstring from OSM's script thread and replaced just in case again.
-can't find any extra/missing { or } which is what normally happens to me...but then vs2010 wouldn't build it so that was on the off-chance.

I'm a bit stuck. Even more worrying is that weapons doesnt work anymore when it used to :(
03-10-2015, 08:44 PM #7
seanhellen
Are you high?
Ok, for those who are interested - thanks to OSM, I managed to get this working...

Originally posted by OldSchoolModz
strcmp. You cant compare a const char* with ==


so the finished code ended up being

                  if(strcmp(Func::MapName(), "mp_dome") == 0)
{
Func::iPrintln(client, "We Are In Dome");
}
else
{
Func::iPrintln(client, "We Are Not In Dome");
}


Hopefully this will be helpful to people in the same situation. Once again, thanks to OSM :yes:

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo