PDA

View Full Version : Vehicle loop problem :/


knackworst
31/08/2011, 08:22 AM
hi, I was writing something that when a player from a team steals a car he gets +1 wanted level, so I made a vehicle variable to check if the vehicle is stolen:
//other code
else if(vehicle == 516)
{
for(new iv; iv<MAX_VEHICLES; iv++)// a loop that goes though all vehicles
{
if(gTeam[playerid] == TEAM_BANDIT)
{
if(stolenveh[iv] == 0)
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "U stole a Drivers car, be carefull!");
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
new string[128];
format(string,sizeof(string),"%s has stolen a drivers car!",playerid);
SendClientMessageToAllCops(string);
stolenveh[iv] = 1;
return 1;
}
else if(stolenveh[iv] == 1)
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "This vehicle has been stolen!");
}
}
}
}//other code

this must protect the player from getting a double wanted level, while entered the same car...
however when I steal the car; it says the messages, u stolen a drivers car!
but when I enter that same car again, I get +1 wanted level and I get the u have stolen a drivers car message + this vehicle has been stolen message :/

TTJJ
31/08/2011, 08:34 AM
Hi Knackworst,

If I understand your code correctlly... You may be able to just do this:

if(gTeam[playerid] == TEAM_BANDIT)
{
if(stolenveh[GetPlayerVehicleID(playerid)] == 0)
{
//Do vehicle stolen stuff
}
else if(stolenveh[GetPlayerVehcileID(playerid)] == 1)
{
//Do Other Vehicle Stolen Stuff
}
}


Cheers,

TJ

=WoR=Varth
31/08/2011, 08:40 AM
new iv=1; iv<MAX_VEHICLES; iv++//There's no vehicleid 0


EDIT:Miss read.

knackworst
31/08/2011, 09:03 AM
Hi Knackworst,

If I understand your code correctlly... You may be able to just do this:

if(gTeam[playerid] == TEAM_BANDIT)
{
if(stolenveh[GetPlayerVehicleID(playerid)] == 0)
{
//Do vehicle stolen stuff
}
else if(stolenveh[GetPlayerVehcileID(playerid)] == 1)
{
//Do Other Vehicle Stolen Stuff
}
}


Cheers,

TJ

and what do I put in here? : stolenveh[vehicleid] = 1;

=WoR=Varth
31/08/2011, 09:05 AM
Your code ofc,

if(gTeam[playerid] == TEAM_BANDIT)
{
if(stolenveh[GetPlayerVehicleID(playerid)] == 0)
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "U stole a Drivers car, be carefull!");
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
new string[128];
format(string,sizeof(string),"%s has stolen a drivers car!",playerid);
SendClientMessageToAllCops(string);
stolenveh[iv] = 1;
return 1;
}
else if(stolenveh[GetPlayerVehcileID(playerid)] == 1) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "This vehicle has been stolen!");
}

knackworst
31/08/2011, 09:16 AM
Doesn't work... I get the same message when I steal it and when I enter it the second time

=WoR=Varth
31/08/2011, 09:20 AM
if(gTeam[playerid] == TEAM_BANDIT)
{
if(stolenveh[GetPlayerVehicleID(playerid)] == 0)
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "U stole a Drivers car, be carefull!");
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
new string[128];
format(string,sizeof(string),"%s has stolen a drivers car!",playerid);
SendClientMessageToAllCops(string);
stolenveh[iv] = 1;
return 1;
}
else return SendClientMessage(playerid, COLOR_LIGHTBLUE, "This vehicle has been stolen!");
}

FireCat
31/08/2011, 09:22 AM
else if(vehicle == 516)
{
for(new iv; iv<MAX_VEHICLES; iv++)// a loop that goes though all vehicles
{
if(gTeam[playerid] == TEAM_BANDIT)
{
if(stolenveh[iv] == 1) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "This vehicle has been stolen!");
if(stolenveh[iv] == 0)
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "U stole a Drivers car, be carefull!");
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
new string[128];
format(string,sizeof(string),"%s has stolen a drivers car!",playerid);
SendClientMessageToAllCops(string);
stolenveh[iv] = 1;
return 1;
}
}
}
}//other code

knackworst
31/08/2011, 09:26 AM
nope, still get same message when I reenter the car

FireCat
31/08/2011, 09:27 AM
else if(vehicle == 516)
{
for(new iv; iv<MAX_VEHICLES; iv++)// a loop that goes though all vehicles
{
if(gTeam[playerid] == TEAM_BANDIT)
{
if(stolenveh[iv] == 1) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "This vehicle has been stolen!");
if(stolenveh[iv] == 0)
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "U stole a Drivers car, be carefull!");
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
new string[128];
format(string,sizeof(string),"%s has stolen a drivers car!",playerid);
SendClientMessageToAllCops(string);
stolenveh[iv] = 1;
break;
}
}
}
}//other code

knackworst
31/08/2011, 09:31 AM
Thanks it works : D

=WoR=Varth
31/08/2011, 09:31 AM
My bad.

FireCat
31/08/2011, 09:35 AM
Thanks it works : D

Np :)
Rep? :D

knackworst
31/08/2011, 10:08 AM
I must spread other respf 1st it says :/
remind me when you get back online : )

FireCat
31/08/2011, 10:10 AM
I must spread other respf 1st it says :/
remind me when you get back online : )

Here :D