Stock Function - Simple - Yes Or No Answer
#4

Quote:
Originally Posted by xMichaelx
Посмотреть сообщение
Thanks, Rep+, And yeah i see alot of roleplay scripts use something similar, how would i do is a cop car?
pawn Код:
stock IsACopCar(vehicleid)
{
    switch(vehicleid):
    {
        case 599: true;
        case 569: true;
    }
    return 1;
}
And just continue like that?
Nope.

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());
}
Or..

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");
So, look at this code:

pawn Код:
stock IsACopCar(vehicleid)
{
    switch(vehicleid):
    {
        case 599: true;
        case 569: true;
    }
    return 1;
}
There are a bit of things wrong with that code, but no problem, let's fix them.
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;
}
Let's explain the code.
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;
}
Some parts are hard to explain; sorry for that.
Reply


Messages In This Thread
Stock Function - Simple - Yes Or No Answer - by xMichaelx - 08.12.2011, 02:26
Re: Stock Function - Simple - Yes Or No Answer - by Emmet_ - 08.12.2011, 02:40
Re: Stock Function - Simple - Yes Or No Answer - by xMichaelx - 08.12.2011, 02:49
Re: Stock Function - Simple - Yes Or No Answer - by Emmet_ - 08.12.2011, 03:03
Re: Stock Function - Simple - Yes Or No Answer - by xMichaelx - 08.12.2011, 03:11

Forum Jump:


Users browsing this thread: 1 Guest(s)