What's the meaning of vehicleid?and carid?
#1

The code is in LARP.
Код:
public IsAnOwnableCar(vehicleid)
{
	if(vehicleid >= 184 && vehicleid <= MAX_VEHICLES) { return 1; }
	return 0;
}
public IsACopCar(carid)
{
	if((carid >= 16) && (carid <= 38))
	{
		return 1;
	}
	return 0;
}
PS:carid and vehicleid don't need to define.

You can see this code.What's the meaning of vehicleid?and carid?Are they different?
It seem that carid 1-6 is CreateVehicle first time to sixth time.

How to use carid and vehicleid?

If i wanna add more CopCar in my sever,how to do

Sorry for my bad English.
Reply
#2

It's just named something different.
Reply
#3

hum...And could you tell me how to use?and their meaning?
Reply
#4

carid is custom defined in larp,

vehicle id, every vehicle has an id starting at 0
Reply
#5

And yet you're wrong again. Vehicleid and carid are just the same in this case, and they both refer to the vehicle's unique ID. That id is retrieved when the vehicle is first created. Vehicleids also start at 1, not zero.

But, since LARP is hard-coded and heavily relies on assumptions, it is not an easy task to add more vehicles.

As I see it, you have:
vehicleids 1 to 15: standard spawn vehicles
vehicleids 16 to 38: police vehicles
vehicleids 39 to 183: more standard spawn vehicles
vehicleids 184 to ??: ownable vehicles
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
And yet you're wrong again. Vehicleid and carid are just the same in this case, and they both refer to the vehicle's unique ID. That id is retrieved when the vehicle is first created. Vehicleids also start at 1, not zero.

But, since LARP is hard-coded and heavily relies on assumptions, it is not an easy task to add more vehicles.

As I see it, you have:
vehicleids 1 to 15: standard spawn vehicles
vehicleids 16 to 38: police vehicles
vehicleids 39 to 183: more standard spawn vehicles
vehicleids 184 to ??: ownable vehicles
Im not wrong, I mean, why would you use carid and vehicle id?

Its obvious that carid is custom defined to vehicleid, so dont say im yet wrong again
Reply
#7

Yes, I do say you're wrong again! Nearly every time I spot one of your posts, it contains wrong or terribly outdated information. Then, using either of these two functions will have the same effect:
pawn Код:
public IsACopCar(carid)
{
    if((carid >= 16) && (carid <= 38))
    {
        return 1;
    }
    return 0;
}

//OR

public IsACopCar(vehicleid)
{
    if((vehicleid >= 16) && (vehicleid <= 38))
    {
        return 1;
    }
    return 0;
}
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
Yes, I do say you're wrong again! Nearly every time I spot one of your posts, it contains wrong or terribly outdated information. Then, using either of these two functions will have the same effect:
pawn Код:
public IsACopCar(carid)
{
    if((carid >= 16) && (carid <= 38))
    {
        return 1;
    }
    return 0;
}

//OR

public IsACopCar(vehicleid)
{
    if((vehicleid >= 16) && (vehicleid <= 38))
    {
        return 1;
    }
    return 0;
}
Since when is carid a default function?
Atleast I never heared of it
Reply
#9

lol carid is not a function its a param for a function,
what makes it the cars ID is the code that calls this.

You should really look up the PAWN language ref and maybe just read some
basic programming fundamentals.
Reply
#10

pawn Код:
if(vehicleid >= 184 && vehicleid <= MAX_VEHICLES)
and
pawn Код:
if((carid >= 16) && (carid <= 38))
is so-called "hardcoding". that means, if you have lots of CreateVehicle(); in OnGamemodeInit, the vehicleid will increase from 1 to 2000 (2000 is the MAX_VEHICLES define), so imagine this GameModeInit:
pawn Код:
CreateVehicle(596,blablabla);
CreateVehicle(415,blablabla);
CreateVehicle(560,blablabla);
assuming that these 3 vehicles gets created first, they WILL get assigned vehicleid 1 to 3. remark this crappy code, i will refer to it later...

this:
pawn Код:
if(vehicleid>=1 && vehicleid <= 3)
..will directly check for the first 3 vehicleid-s, regardless of their model (vehicleid1==modelid597==LSPD car, vehicleid2==modelid415==cheetah, vehicleid3==modelid560==sultan). as you see, the modelid can be anything, even a boat, or a kart, or the sultan and cheetah. the script will fail to detect entering a "cop" car, because its depending on the vehicleid (1-3), but their modelid is not checked. by adding some more modelids 596 (LSPD car), will force you to rescript all direct checkings for vehicleid, since by inserting something into the CreateVehicle(); order, will mess up the order of vehidleid-s. if you add more cop cars at the trails end, you need to re-script the code aswell.
this way of "hard"-scripting/coding/programming means more trouble than benefits, so:
AVOID IT AT ALL COSTS!

if you check for the modelid instead of directly checking the vehicleid (and assuming the correct vehicle got created by creating the correct modelid), you can avoid that id-issues, PLUS: you can add more cop cars (we used modelid 596) anywhere in the script, the vehicleid ist not relevant anymore:
pawn Код:
CreateVehicle(596,blablabla);
CreateVehicle(415,blablabla);
CreateVehicle(560,blablabla);
CreateVehicle(596,blablabla);
CreateVehicle(596,blablabla);
CreateVehicle(560,blablabla);
CreateVehicle(415,blablabla);
CreateVehicle(596,blablabla);
this is not ordered well, but it wont matter by checking the modelid:
pawn Код:
public IsACopCar(carid)
{
    if(GetVehicleModel(vehicleid)==596 || GetVehicleModel(vehicleid)==597 || GetVehicleModel(vehicleid)==598)
    {
        return 1;
    }
    return 0;
}
already returns 1 at the cop cars 596,597 and 598, ignoring the order the vehicles got created. there is no loop for 2000 vehicles required, but the 3 checks (GetVehicleModel) already looks bad, if you want to add all cop vehicles, there would be needed like 20 checks.
an even better way is to waste (i prefer to call it "trade") some memory for speed. in order to let the CopCar check run in linear time (minimum time in this case), use an array, which already stores the return value:
pawn Код:
new IsCopVehicleModel[212];
this array is 212 big indeeddue to the fact that there are 212 vehicle ids. the simple trick to obtain the "correct" vehicle id, is to add 400 to the array. in reverse, the vehiclemodel 596 in game - 400 = 196. oh, 497,198are cop cars aswell. adding them into the array looks like
pawn Код:
IsCopVehicleModel[196]=1;
IsCopVehicleModel[197]=1;
IsCopVehicleModel[198]=1;
...added in GamemodeInit btw - the old cop car check function changed a bit,
pawn Код:
public IsACopCar(carid)
{
    if(IsCopVehicleModel[carid]==1)
    {
        return 1;
    }
    return 0;
}
but can be done quicker, without ANY check:
pawn Код:
public IsACopCar(carid)
{
    return IsCopVehicleModel[carid];
}
and this just looks just funny, a function returning the content of an array only. instead of
pawn Код:
IsACopCar(vehicleid)
you can simply use
pawn Код:
IsCopVehicleModel[vehicleid]
with no need to call an extra callback. the time is linear, regardless of the amount of cars in the server, or the vehicleid.
oh, it can be modified - even in-game:
pawn Код:
CMD:copcar(playerid,params[])
{
    new ModelID;
    if(!sscanf(params,"d",ModelID))
    {
        ModelID=ModelID%212;
        IsCopVehicleModel[ModelID-400]=1-IsCopVehicleModel[ModelID-400];
       
        new string[128];
        format(string,sizeof(string),"vehicle model %d is cop: %d",ModelID,IsCopVehicleModel[ModelID-400])
        SendClientMessage(playerid,0xffffffff,string);
    }
    return 1;
}
use the /dl to see some vehicle infos, then switch a cop car to civilian with
/copcar 596
..then enter it, repeat last 2 steps as often you want ^^

edit: the "ModelID=ModelID%212;" avoids invalid array cells, feel free to try to set modelid 123456
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)