PDA

View Full Version : Problem with map changing system


SpikY_
13/06/2015, 11:06 AM
Hi,
There are two team attackers and defenders. attackers have to steal the vehicle from defenders. i have a problem: when attackers can't steal the vehicle and mission timer got over so attackers team get mission failed gametext and defending team get mission passed gametext but after 5-6 seconds again a Gametext appears for attackers and defenders in which attackers get mission passed and defenders get mission failed and the gamemode also don't change to get forward on next mission.

Codes:
forward NoExplode(playerid);
public NoExplode(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
PlayerPlaySound(playerid, 1185, 0.0, 0.0, 0.0);
SetTimer("Finshed",6000,false);
if(gTeam[i] == TEAM_ATTACKERS)
{
GameTextForPlayer(i, "~g~ ~n~Mission Passed", 6000, 4);
PlayerPlaySound(i, 1185, 0.0, 0.0, 0.0);
GivePlayerMoney(i, 10000);
SetPlayerScore(i,GetPlayerScore(i)+5);
SendClientMessage(playerid,yellow,"{7C7C7C} You've Recieved 5 Points and $10,000 for Completing the mission Objective.");
SetPlayerCameraPos(i, 1930.1677,-571.0945,23.8120);
SetPlayerCameraLookAt(i, 1911.5667,-563.5245,25.0610);
}
else if(gTeam[i] == TEAM_DEFENDERS)
{
GameTextForPlayer(i, "~r~ ~n~Mission Failed", 6000, 4);
PlayerPlaySound(i, 1185, 0.0, 0.0, 0.0);
SendClientMessage(playerid,yellow,"{FF0000} You've Lost -$2000 Money for Not completing the Mission Objective.");
SetPlayerCameraPos(i, 1930.1677,-571.0945,23.8120);
GivePlayerMoney(i,-2000);
SetPlayerCameraLookAt(i, 1911.5667,-563.5245,25.0610);
}
SetTimer("Finshed",2000,false);
}
}
return 1;
}

forward NoExplode2(playerid);
public NoExplode2(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
PlayerPlaySound(playerid, 1185, 0.0, 0.0, 0.0);
if(gTeam[i] == TEAM_DEFENDERS)
{
GameTextForPlayer(i, "~g~ ~n~Mission Passed", 6000, 4);
SendClientMessage(playerid,yellow,"{7C7C7C} You've Recieved 5 Points and $10,000 for Completing the mission Objective.");
GivePlayerMoney(i, 10000);
SetPlayerScore(i,GetPlayerScore(i)+5);
SetTimer("Finshed", 6000, 0);
PlayerPlaySound(i, 1185, 0.0, 0.0, 0.0);
SetPlayerCameraPos(i, 1276.0552,-788.1879,96.9662);
SetPlayerCameraLookAt(i, 1288.8605,-788.3223,96.4609);
}
else if(gTeam[i] == TEAM_ATTACKERS)
{
GameTextForPlayer(i, "~r~ ~n~Mission Failed", 6000, 4);
SendClientMessage(playerid,yellow,"{FF0000} You've Lost -$2000 Money for Not completing the Mission Objective.");
SetPlayerCameraPos(i, 1276.0552,-788.1879,96.9662);
SetPlayerCameraLookAt(i, 1288.8605,-788.3223,96.4609);
PlayerPlaySound(i, 1185, 0.0, 0.0, 0.0);
GivePlayerMoney(i, -2000);
SetTimer("Finshed",6000,false);
}
PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
SendClientMessage(playerid,0xFF00FFFFF,"{55FF00} Success : {FFFFFF}Your Stats have been Successfully Saved.");
SetTimer("Finshed",2000,false);
}
}
return 1;
}

public Finshed(playerid)
{
SendRconCommand("changemode next-mission-name-here");
return 1;
}

public Finshed2(playerid)
{
for(new i = 0; playerid < MAX_PLAYERS; playerid++)
{
if(IsPlayerConnected(i))
{
if(gTeam[i] == TEAM_DEFENDERS)
{
GameTextForPlayer(i, "~r~ Mission Failed", 6000, 4);
SendClientMessageToAll(COLOR_RED, "{E4E05D} The Security Guards have Successfully defend the Helicopter from the Thieves.");
SetTimer("Finshed", 2000, 0);
}
else if(gTeam[i] == TEAM_ATTACKERS)
{
GameTextForPlayer(i, "~g~ Mission Passed", 6000, 4);
GivePlayerMoney(i, 10000);
SetPlayerScore(playerid,GetPlayerScore(playerid)+5 );
}
}
}
SetTimer("Finshed", 2000, 0);
return 1;
}

forward Load(playerid);
public Load(playerid)
{
SetTimerEx("NoExplode2",290000,false,"i", playerid);
}

MohammedZ
13/06/2015, 11:20 AM
I can help you with the gamemode changing but with others im not sure

SendRconCommand("changemode You must type here your next mission name ");

SpikY_
13/06/2015, 11:24 AM
" SendRconCommand("changemode You must type here your next mission name "); "
this is already in my gamemode. i didn't mentioned the next map name. see the codes carefully :c

SpaceX
13/06/2015, 11:34 AM
Why do you have two functions doing the same thing?

All you did was replace Mission Passed by Mission Failed or vice-versa for Attackers/Defenders in your public NoExplode2() function... Obviously, you'll get the opposite message repeated.

Just remove NoExplode2 and make a new team (for ex. fTeam) which checks for the failure and add it with else-if using the right conditions in NoExplode. Modify the GameText and SendClientMessage as per needs.

SpaceX
13/06/2015, 11:37 AM
Remember to make pairs in your else if conditions (You'll have 4 else if blocks)

Ex:

if(gTeam[i] == TEAM_DEFENDERS && fTeam[i] == TEAM_ATTACKERS)
{
//print the win message for defenders and fail message for attackers.
}

EDIT: Sorry for the double post, can't see what I'm exactly doing on my Mobile.

SpikY_
13/06/2015, 11:50 AM
you mean i need to add
if(gTeam[i] == TEAM_DEFENDERS && fTeam[i] == TEAM_ATTACKERS)
{
//print the win message for defenders and fail message for attackers.
}

instead of

for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
PlayerPlaySound(playerid, 1185, 0.0, 0.0, 0.0);
if(gTeam[i] == TEAM_DEFENDERS)
{
GameTextForPlayer(i, "~g~ ~n~Mission Passed", 6000, 4);
SendClientMessage(playerid,yellow,"{7C7C7C} You've Recieved 5 Points and $10,000 for Completing the mission Objective.");
GivePlayerMoney(i, 10000);
SetPlayerScore(i,GetPlayerScore(i)+5);
SetTimer("Finshed", 6000, 0);
PlayerPlaySound(i, 1185, 0.0, 0.0, 0.0);
SetPlayerCameraPos(i, 1276.0552,-788.1879,96.9662);
SetPlayerCameraLookAt(i, 1288.8605,-788.3223,96.4609);
}
else if(gTeam[i] == TEAM_ATTACKERS)
{
GameTextForPlayer(i, "~r~ ~n~Mission Failed", 6000, 4);
SendClientMessage(playerid,yellow,"{FF0000} You've Lost -$2000 Money for Not completing the Mission Objective.");
SetPlayerCameraPos(i, 1276.0552,-788.1879,96.9662);
SetPlayerCameraLookAt(i, 1288.8605,-788.3223,96.4609);
PlayerPlaySound(i, 1185, 0.0, 0.0, 0.0);
GivePlayerMoney(i, -2000);
SetTimer("Finshed",6000,false);
}
PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
SendClientMessage(playerid,0xFF00FFFFF,"{55FF00} Success : {FFFFFF}Your Stats have been Successfully Saved.");
SetTimer("Finshed",2000,false);

Under
forward NoExplode2(playerid);
public NoExplode2(playerid)
{

SpaceX
13/06/2015, 01:19 PM
you mean i need to add
if(gTeam[i] == TEAM_DEFENDERS && fTeam[i] == TEAM_ATTACKERS)
{
//print the win message for defenders and fail message for attackers.
}

instead of

for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
PlayerPlaySound(playerid, 1185, 0.0, 0.0, 0.0);
if(gTeam[i] == TEAM_DEFENDERS)
{
GameTextForPlayer(i, "~g~ ~n~Mission Passed", 6000, 4);
SendClientMessage(playerid,yellow,"{7C7C7C} You've Recieved 5 Points and $10,000 for Completing the mission Objective.");
GivePlayerMoney(i, 10000);
SetPlayerScore(i,GetPlayerScore(i)+5);
SetTimer("Finshed", 6000, 0);
PlayerPlaySound(i, 1185, 0.0, 0.0, 0.0);
SetPlayerCameraPos(i, 1276.0552,-788.1879,96.9662);
SetPlayerCameraLookAt(i, 1288.8605,-788.3223,96.4609);
}
else if(gTeam[i] == TEAM_ATTACKERS)
{
GameTextForPlayer(i, "~r~ ~n~Mission Failed", 6000, 4);
SendClientMessage(playerid,yellow,"{FF0000} You've Lost -$2000 Money for Not completing the Mission Objective.");
SetPlayerCameraPos(i, 1276.0552,-788.1879,96.9662);
SetPlayerCameraLookAt(i, 1288.8605,-788.3223,96.4609);
PlayerPlaySound(i, 1185, 0.0, 0.0, 0.0);
GivePlayerMoney(i, -2000);
SetTimer("Finshed",6000,false);
}
PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
SendClientMessage(playerid,0xFF00FFFFF,"{55FF00} Success : {FFFFFF}Your Stats have been Successfully Saved.");
SetTimer("Finshed",2000,false);

Under
forward NoExplode2(playerid);
public NoExplode2(playerid)
{

You do not remove the whole thing.
Only replace your if-elses with mine and keep the for loops and other callbacks like SendClientMessage, SetTimer.etc.
(change the messages for each case since it would be different.)

What I have done is basically like switch-case.

You'll have a total of 3 if else statements:

1. if(gTeam[i] == TEAM_DEFENDERS && fTeam[i] == TEAM_ATTACKERS)
{
//body
}
2. else if(gTeam[i] == TEAM_ATTACKERS && fTeam[i] == TEAM_DEFENDERS)
{
//body
}
3. else
{
//body when no one wins (timer runs out)
}


I'm pretty sure including this in NoExplode should fix one of your problems you mentioned. (remember to make NoExplode2 as a comment and test out what I have provided once to make sure everything is running alright.)

Points to remember:
1. You have to make a new team like gTeam called fTeam.
2. gTeam is the team which wins and fTeam is the team which loses.
3. Keep the for loops and if-else body but change the if statements with mine.
4. Change the messages for each if else body since the outcome is different.
5. Include everything within for loop and if(IsPlayerConnnected(i))

I hope you're understanding what I'm saying.

Regards,
SpaceX.

SpikY_
15/06/2015, 07:47 AM
1. if(gTeam[i] == TEAM_DEFENDERS && fTeam[i] == TEAM_ATTACKERS)
{
//body
}
2. else if(gTeam[i] == TEAM_ATTACKERS && fTeam[i] == TEAM_DEFENDERS)
{
//body
}
3. else
{
//body when no one wins (timer runs out)
}

1. If Team attackers successfully steal the vehicle and deliever it so they win ok.
2. If team attackers got unsuccessfull so the team defenders will win.

The point 2 is same as point 3. that you have mentioned the your codes.





Sorry for the bump. :c

SpikY_
15/06/2015, 07:55 AM
So here i have replace gTeam = Defender TO fTeam = Defender in my whole script

is it correct?

SpaceX
15/06/2015, 11:05 AM
You have not read my post correctly.

1. if(gTeam[i] == TEAM_DEFENDERS && fTeam[i] == TEAM_ATTACKERS)
{
//body
}
2. else if(gTeam[i] == TEAM_ATTACKERS && fTeam[i] == TEAM_DEFENDERS)
{
//body
}
3. else
{
//body when no one wins (timer runs out)
}

1. Defenders win and attackers lose.
2. Attackers win and defenders lose.
3. Timer runs out -> no-one wins or loses. (it's a tie)

Like you've made gTeam in your main post for winners, make an fTeam or any other variable for losers and use the if-else commands above.
Leave the body the same as it is.

Leave the other body part the same but modify as per needs. (the modify part is the messages I'm talking about.)

I've summarized it all in my post above, please go through it again.

SpikY_
15/06/2015, 12:39 PM
I made fTeam and the problem was fixed but there is a team balancer which do not let the player spawn.
the server got bug after making fTeam. :c

SpaceX
15/06/2015, 12:46 PM
Does it work without the team balancer?

Also, I don't think your team balancer conflicts with the code I gave you.
Anyhow, provide the team balancer code to me.

SpikY_
15/06/2015, 01:43 PM
public OnPlayerRequestSpawn(playerid)
{
new team1count, team2count;
for(new i, m = GetMaxPlayers(); i < m; i++)
{
if (IsPlayerConnected(i))
{
if (fTeam[i] == TEAM_ATTACKERS) team1count++;
else if (gTeam[i] == TEAM_DEFENDERS) team2count++;
}
}
if (fTeam[playerid] == TEAM_ATTACKERS)
{
if (team1count > (team2count+1)){
SendClientMessage(playerid, COLOR_YELLOW, "{FF0000} Balancer: {FF8484}This team is Currently full, Kindly choose the other Team.");
return 0;
}

}
else if (gTeam[playerid] == TEAM_DEFENDERS)
{
if ((team1count+1) < team2count){
SendClientMessage(playerid, COLOR_YELLOW, "{FF0000} Balancer: {FF8484}This team is Currently full, Kindly choose the other Team.");
return 0;
}
}
return 1;
}

These are the team balancer codes.

SpaceX
15/06/2015, 01:49 PM
I think we're doing something wrong here.

Can you explain what is exactly 'TEAM_ATTACKERS' & 'TEAM_DEFENDERS'? What are they define's?

How do you check if the car is stolen or not?

SpaceX
15/06/2015, 02:07 PM
Also,

replace:
new team1count, team2count;
with:
new team1count=0;
new team2count=0;

Do you know that variables don't have default value zero?

SpikY_
15/06/2015, 02:28 PM
I think we're doing something wrong here.

Can you explain what is exactly 'TEAM_ATTACKERS' & 'TEAM_DEFENDERS'? What are they define's?

How do you check if the car is stolen or not?

Team ATTACKERS AND DEFENDERS were define as(before):
gTeam[playerid] = TEAM_ATTACKERS;
gTeam[playerid] = TEAM_DEFENDERS;

For checking the vehicle is it stolen or not, i use:
public OnPlayerStateChange(playerid, newstate, oldstate)