VERY simple question probs Rep+
#1

Hey, I'm using this STOCK so I can tell which vehicle is a police vehicle (Instead of writing out them seperatly each time) but it says it needs to return a value, but I have return 1, why?

pawn Код:
stock PoliceVehicle(playerid)
{
    new carid = GetPlayerVehicleID(playerid);
    if(carid == copcar[0] || carid == copcar[1] || carid == copcar[2] || carid == copcar[3] || carid == copcar[4] || carid == copcar[5] || carid == copcar[6] || carid == copcar[7] || carid == copcar[8])
    if(carid == copcar[9] || carid == copcar[10] || carid == copcar[11] || carid == copcar[12] || carid == copcar[13] || carid == copcar[14] || carid == copcar[15] || carid == copcar[16] || carid == copcar[17])
    if(carid == copcar[18] || carid == copcar[19] || carid == copcar[20] || carid == copcar[21] || carid == copcar[22] || carid == copcar[23] || carid == copcar[24] || carid == copcar[25] || carid == copcar[26])
    if(carid == copcar[27] || carid == copcar[28] || carid == copcar[29] || carid == copcar[30] || carid == copcar[31] || carid == copcar[32] || carid == copcar[33] || carid == copcar[34] || carid == copcar[35])
    if(carid == copcar[36] || carid == copcar[37] || carid == copcar[38] || carid == copcar[39] || carid == copcar[40] || carid == copcar[41] || carid == copcar[42] || carid == copcar[43] || carid == copcar [44])
    if(carid == copcar[45] || carid == copcar[46] || carid == copcar[47] || carid == copcar[48] || carid == copcar[49] || carid == copcar[50] || carid == copcar[51] || carid == copcar[52])
    return 1;
}
Reply
#2

Instead of return 1; type return carid;
Reply
#3

Код:
C:\Documents and Settings\john\Desktop\Freeroam\gamemodes\funserver.pwn(1357) : warning 209: function "PoliceVehicle" should return a value
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
Reply
#4

You don't have a 'result' for the 'if' statement:
pawn Код:
stock PoliceVehicle(playerid)
{
    new carid = GetPlayerVehicleID(playerid);
    if(carid == copcar[0] || carid == copcar[1] || carid == copcar[2] || carid == copcar[3] || carid == copcar[4] || carid == copcar[5] || carid == copcar[6] || carid == copcar[7] || carid == copcar[8]) return carid;
    if(carid == copcar[9] || carid == copcar[10] || carid == copcar[11] || carid == copcar[12] || carid == copcar[13] || carid == copcar[14] || carid == copcar[15] || carid == copcar[16] || carid == copcar[17]) return carid;
    if(carid == copcar[18] || carid == copcar[19] || carid == copcar[20] || carid == copcar[21] || carid == copcar[22] || carid == copcar[23] || carid == copcar[24] || carid == copcar[25] || carid == copcar[26]) return carid;
    if(carid == copcar[27] || carid == copcar[28] || carid == copcar[29] || carid == copcar[30] || carid == copcar[31] || carid == copcar[32] || carid == copcar[33] || carid == copcar[34] || carid == copcar[35]) return carid;
    if(carid == copcar[36] || carid == copcar[37] || carid == copcar[38] || carid == copcar[39] || carid == copcar[40] || carid == copcar[41] || carid == copcar[42] || carid == copcar[43] || carid == copcar [44]) return carid;
    if(carid == copcar[45] || carid == copcar[46] || carid == copcar[47] || carid == copcar[48] || carid == copcar[49] || carid == copcar[50] || carid == copcar[51] || carid == copcar[52]) return carid;
}
More simple:
pawn Код:
stock PoliceVehicle(playerid)
{
    new carid = GetPlayerVehicleID(playerid);
    if(carid == copcar[0] || carid == copcar[1] || carid == copcar[2] || carid == copcar[3] || carid == copcar[4] || carid == copcar[5] || carid == copcar[6] || carid == copcar[7] || carid == copcar[8] || carid == copcar[9] || carid == copcar[10] || carid == copcar[11] || carid == copcar[12] || carid == copcar[13] || carid == copcar[14] || carid == copcar[15] || carid == copcar[16] || carid == copcar[17] || carid == copcar[18] || carid == copcar[19] || carid == copcar[20] || carid == copcar[21] || carid == copcar[22] || carid == copcar[23] || carid == copcar[24] || carid == copcar[25] || carid == copcar[26] || carid == copcar[27] || carid == copcar[28] || carid == copcar[29] || carid == copcar[30] || carid == copcar[31] || carid == copcar[32] || carid == copcar[33] || carid == copcar[34] || carid == copcar[35]) || carid == copcar[36] || carid == copcar[37] || carid == copcar[38] || carid == copcar[39] || carid == copcar[40] || carid == copcar[41] || carid == copcar[42] || carid == copcar[43] || carid == copcar [44])||carid == copcar[45] || carid == copcar[46] || carid == copcar[47] || carid == copcar[48] || carid == copcar[49] || carid == copcar[50] || carid == copcar[51] || carid == copcar[52]) return carid;
}
Reply
#5

Is that stock use to see if it's a Police vehicle or not?

If so then just return 1; after if statement and return 0; at the end.
Reply
#6

TY repped+
Reply
#7

it'd look a lot neater like this
pawn Код:
stock PoliceVehicle(playerid)
{
    new carid = GetPlayerVehicleID(playerid);
    for(new i=0;i<53;i++)
    {
        if(carid == copcar[i]) return 1;
    }
    return 0;
}
Reply
#8

Zomg, inefficient, much?
pawn Код:
stock PoliceVehicle(playerid)
{
    new carid = GetPlayerVehicleID(playerid);
    for(new i; i < sizeof(copcar); i++)
        if(copcar[i] == carid) return true;

    return false;
}
And again I get beaten by Cessil.
Reply
#9

Rofl wow, thanks, Guess I don't know the "efficient" way to script yet
Reply
#10

thats called spaghetti code:
pawn Код:
stock PoliceVehicle(playerid)
{
    new carid = GetPlayerVehicleID(playerid);
    if(
    carid == copcar[0] ||
    carid == copcar[1] ||
    carid == copcar[2] ||
    carid == copcar[3] ||
    carid == copcar[4] ||
    carid == copcar[5] ||
    carid == copcar[6] ||
    carid == copcar[7] ||
    carid == copcar[8] ||
    carid == copcar[9] ||
    carid == copcar[10] ||
    carid == copcar[11] ||
    carid == copcar[12] ||
    carid == copcar[13] ||
    carid == copcar[14] ||
    carid == copcar[15] ||
    carid == copcar[16] ||
    carid == copcar[17] ||
    carid == copcar[18] ||
    carid == copcar[19] ||
    carid == copcar[20] ||
    carid == copcar[21] ||
    carid == copcar[22] ||
    carid == copcar[23] ||
    carid == copcar[24] ||
    carid == copcar[25] ||
    carid == copcar[26] ||
    carid == copcar[27] ||
    carid == copcar[28] ||
    carid == copcar[29] ||
    carid == copcar[30] ||
    carid == copcar[31] ||
    carid == copcar[32] ||
    carid == copcar[33] ||
    carid == copcar[34] ||
    carid == copcar[35] ||
    carid == copcar[36] ||
    carid == copcar[37] ||
    carid == copcar[38] ||
    carid == copcar[39] ||
    carid == copcar[40] ||
    carid == copcar[41] ||
    carid == copcar[42] ||
    carid == copcar[43] ||
    carid == copcar[44] ||
    carid == copcar[45] ||
    carid == copcar[46] ||
    carid == copcar[47] ||
    carid == copcar[48] ||
    carid == copcar[49] ||
    carid == copcar[50] ||
    carid == copcar[51] ||
    carid == copcar[52])
    {
        return 1;
    }
    return 0;
}
the suggested loop LOOKS better:
pawn Код:
for(new i=0;i<53;i++)
    {
        if(carid == copcar[i]) return 1;
    }
...but its not going to be faster (assuming that not only the first few cars gets used).

since you hardcoded the vehicle ids, i suggest you to create an array: (sidenote: you could change a car faction ingame by changing a cell in the array)
pawn Код:
new CopVehicle[MAX_VEHICLES];
and at each
pawn Код:
copcar[]=CreateVehicle();
also set an entry in the array for holding the information whether the car IS a copcar (=1), or not (no need to set it 0 then, since the array got initialized empty):
pawn Код:
CopVehicle[CopCar[]]=1;
later then, when you check if the entered car is a cop one, you can use the vehicleid as a pointer into the CopVehicle[vehicleid] array, storing a "yes" or "no" (1 or 0):
pawn Код:
new carid=GetPlayerVehicleID(playerid);
if(CopVehicle[carid]==1)
{
    //yep
}
so far, so good, but...

it can be done even better:
pawn Код:
new carid=GetPlayerVehicleID(playerid);
return CopVehicle[carid];
thats a not even linear runtime, its 1 call only, regardless how many cars have the cop-flag set.
always try to trade RAM vs CPU. RAM is "unlimited" (almost), this array wont blow up your gamemode, and later you could add admin cars (set to 2?)..

oh btw, if you use the stock many times already, just insert the upper part , so you dont need to replace all your stock calls then - but i would do it, for speeds sake ^^
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)