08.12.2011, 03:03
Quote:
Thanks, Rep+, And yeah i see alot of roleplay scripts use something similar, how would i do is a cop car?
pawn Код:
|
Return is to return a value, for example:
pawn Код:
stock Return46()
{
return 46;
}
main()
{
// this will print 46 since we returned 46
// if we returned 69, it would print 69.
printf("I am %d years old.", Return46());
}
pawn Код:
if(Return46() == 45)
// we're returning 46, then we're checking if it's 45, but it's not
print("46 is not 45");
pawn Код:
stock IsACopCar(vehicleid)
{
switch(vehicleid):
{
case 599: true;
case 569: true;
}
return 1;
}
It will return 1, even if it's NOT a cop car, here's a fixed version.
pawn Код:
stock IsACopCar(vehicleid)
{
// You put a : at the end of the 0 on the code below, don't do it.
// Also, you have to check the model, not the vehicle ID.
// Because if you do switch(vehicleid), and ID 599 or ID 569
// doesn't exist, the code won't work.
switch(GetVehicleModel(vehicleid))
{
case 599: return 1;
case 569: return 1;
}
return 0;
}
When the vehicle's model is 599 or 569, it will return 1, but if it's not, it will return 0.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/iscopcar", true) == 0)
{
if(!IsPlayerInAnyVehicle(playerid)) return 1;
if(IsACopCar(GetPlayerVehicleID(playerid)) == 1) // checks if the player's vehicle is model 599 or 569. Notice the 1 here? That's what was returned.
print("Yep"); // IsACopCar returned 1, so the player is in a cop car!
else if(IsACopCar(GetPlayerVehicleID(playerid)) == 0) // if the player's vehicle is not 599 or 569. See the 0? That's what was returned, since we're not in a cop car.
print("Nope"); // IsACopCar returned 0, since we're not in a cop car!
return 1;
}
return 0;
}