SA-MP Forums Archive
Cars. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Cars. (/showthread.php?tid=617817)



Cars. - CannonBolt - 26.09.2016

Hey guys i need help i tried creating some team cars base off a tutorial on the forums but to found that the tutorial is wrong i'm trying to create them cars.

Код:
new Cars[TeamCars];

enum TeamCars{
DRIVERS
};

Cars[DRIVERS] = AddStaticVehicle(...);
...

Tag Mismatch / invalid array size (negative, zero or out of bounds)

Should i do MAX_VEHICLES instead?


Re: Cars. - iLearner - 27.09.2016

You need to research a bit on enums


Re: Cars. - CannonBolt - 27.09.2016

You could explain more what's the problem?


Re: Cars. - Kaliber - 27.09.2016

Why you name this var DRIVERS?

Explain more..what you wanna do, then we can give you some efficent ways


Re: Cars. - Sew_Sumi - 27.09.2016

What line does the actual error turn up at?

As above said though, there could be a better way of doing this, as your enum, doesn't hold much info at all.


Re: Cars. - CannonBolt - 27.09.2016

Well I'm just trying to make team cars. the enum is to hold what type of cars they are.


Re: Cars. - Kaliber - 28.09.2016

Ah okay, then you should easily do sth like this:

PHP код:
enum
{
    
TEAM_GROVE//This is 0
    
TEAM_BALLAS//This is 1
    
TEAM_VAGOS,  //This is 2
    
MAX_TEAMS    //Just let this always @ the end of the enum :)
};
new 
Cars[MAX_TEAMS][2];
Cars[TEAM_GROVE][0] = AddStaticVehicle(...); //0 means the first car
AddStaticVehicle(...);
AddStaticVehicle(...);
AddStaticVehicle(...);
Cars[TEAM_GROVE][1] = AddStaticVehicle(...); //1 means the end car
//Its a segment of cars :)
//To check if a player is in the car:
#define IsPlayerInTeamCar(%0,%1) (Cars[%1][0] <= GetPlayerVehicleID(%0) <= Cars[%1][1])
//Usage:
if(IsPlayerInTeamCar(playeridTEAM_GROVE))
{
    
//Here he is in a Grove Car :)
}
//To Set Player in a team car:
PutPlayerInVehicle(playeridCars[TEAM_GROVE][0], 0);
PutPlayerInVehicle(playeridCars[TEAM_GROVE][0]+10); //For the next car
PutPlayerInVehicle(playeridCars[TEAM_GROVE][0]+20); //Just check that the number is smaller then Cars[x][1] 
I hope i could help you a bit


Re: Cars. - Sew_Sumi - 28.09.2016

Could you link the tutorial you used?


Re: Cars. - CannonBolt - 28.09.2016

https://sampforum.blast.hk/showthread.php?tid=160810


Re: Cars. - Sew_Sumi - 28.09.2016

When I did it, I simply used an array for the vehicles, used the team ID in that array for each vehicle, and checked it against the players team.


Enums are however a good thing to master.