Vehicle loop problem
#1

So what I'm trying to do are faction vehicles.

I created a new variable.

Код:
new pizzaboy[8];
And I assigned them to those vehicles

Код:
pizzaboy[0] = AddStaticVehicleEx(448,202.1516,-155.5842,1.1784,179.4629,3,6,-1); // pizzaboy
	pizzaboy[1] = AddStaticVehicleEx(448,199.7199,-155.3315,1.1755,181.0785,3,6,-1); // pizzaboy
	pizzaboy[2] = AddStaticVehicleEx(448,196.6695,-155.1234,1.1779,176.7418,3,6,-1); // pizzaboy
	pizzaboy[3] = AddStaticVehicleEx(448,219.0956,-170.7992,1.1758,88.1145,3,6,-1); // pizzaboy
	pizzaboy[4] = AddStaticVehicleEx(448,219.2544,-173.0674,1.1779,87.9659,3,6,-1); // pizzaboy
	pizzaboy[5] = AddStaticVehicleEx(448,219.2123,-175.7683,1.1752,89.5281,3,6,-1); // pizzaboy
	pizzaboy[6] = AddStaticVehicleEx(448,219.3485,-178.3569,1.1776,90.5812,3,6,-1); // pizzaboy
	pizzaboy[7] = AddStaticVehicleEx(448,218.9106,-180.5808,1.1767,85.6638,3,6,-1); // pizzaboy
In OnPlayerStateChange I wanted to check if the player is inside this vehicle, and I do that by using a loop

Код:
new vehicleid = GetPlayerVehicleID(playerid);
for(new i = 0; i < MAX_VEHICLES; i++)
{
    if(vehicleid == pizzaboy[i]) //pizzaboy
    {
	//Do stuff
	SendClientMessage(playerid,COLOR_WHITE,"Pizzaboy w00t");
    }
 }
Now, the problem is that when I get into most of the pizzaboys, I get the message "Pizzaboy w00t", but some of them don't give me the message, as if the variable was not assigned to the vehicle. Anyone know what's the problem, or better yet, does anyone know any other way to create faction vehicles?
Reply
#2

Why do you need to loop through MAX_VEHICLES? Try doing the following instead

pawn Код:
new vehicleid = GetPlayerVehicleID(playerid);
for(new i = 0; i < 8; i++)
{
    if(vehicleid == pizzaboy[i])
    {
    //Do stuff
    SendClientMessage(playerid,COLOR_WHITE,"Pizzaboy w00t");
    }
 }
You'll still probably be having issues. Try printing out the ID of each of the pizzaboy variables after creating them like:

pawn Код:
for(new i=0; i<8; i++)
printf("%d", pizzaboy[i]);
And then try print the vehicleid on OnPlayerStateChange.
Reply
#3

Alright, when the server starts the pizzaboys are created, so I get:

28
29
30
31
32
33
34
35

These are the ID's of the pizzaboy vehicles, and now when I enter one I get:

28
29
30
31
32
33

And what's even more weird is that I use /dl command to see the IDs of the vehicles, and when I enter the 33rd pizzaboy, it still doesn't respond with the message, only the 28,29,30,31,32 do
Reply
#4

Try this

pawn Код:
for(new i = 0; i < sizeof(pizzaboy); i++)
{
    if(IsPlayerInVehicle(playerid,pizzaboy[i]))
    {
        //Do stuff
        SendClientMessage(playerid,COLOR_WHITE,"Pizzaboy w00t");
    }
 }
Reply
#5

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 448)
    {
        SendClientMessage(playerid,COLOR_WHITE,"Pizzaboy w00t");
    }
    return 1;
}
Reply
#6

Quote:
Originally Posted by Michael@Belgium
Посмотреть сообщение
Try this

pawn Код:
for(new i = 0; i < sizeof(pizzaboy); i++)
{
    if(IsPlayerInVehicle(playerid,pizzaboy[i]))
    {
        //Do stuff
        SendClientMessage(playerid,COLOR_WHITE,"Pizzaboy w00t");
    }
 }

IT WORKS! Thanks mate!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)