Problem with spawning a vehicle
#1

Hello there. I have tried creating my own /veh command and it appears to be working wrong. So I decided to copy a /veh command from another script and it didnt work in the same way. It successfully creates the vehicle, but the vehicle is invisible for me.

Here is the command I tried to create by myself.
pawn Код:
CMD:veh(playerid, params[])
{
    new car;
    new string[128];
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
    if(sscanf(params,"i", car)) return SendClientMessage(playerid,0xff0000ff,"USAGE: /Veh <Vehicle ID 400 - 611>");
    else if(car < 400 || car >611) return SendClientMessage(playerid, 0xff0000ff, "ERROR: Cannot go under 400 or above 611.");
    {
    if(Vehicle[playerid] != 0)
        {
            DestroyVehicle(Vehicle[playerid]);
        }
            Vehicle[playerid] = CreateVehicle(car, X, Y, Z + 2.0, 0, -1, -1, 1);
            format(string,sizeof(string),"You Have Spawned Vehicle ID %i",car);
            SendClientMessage(playerid, 0xffffffff, string);
            PutPlayerInVehicle(playerid, Vehicle[playerid], 0);
    }
    return 1;
}
pawn Код:
new Vehicle[MAX_PLAYERS];
================================================== ================================================== ========

Now, here is the second command that is not working as well, the same problem. Its spawning the vehicle but the vehicle is actually not spawned.

I used this: https://sampforum.blast.hk/showthread.php?tid=346727

================================================== ================================================== ========

I even tried with one more command. The same thing happened.
pawn Код:
CMD:veh(playerid, params[])
{
    if(PlayerInfo[playerid][AdminLevel] >= 4)
    {
        new Vehicle[50];
        if(!sscanf(params, "s[50]", Vehicle))
        {
            new string[128], Float:Pos[4];
            GetPlayerPos(playerid, Pos[0],Pos[1],Pos[2]);
            GetPlayerFacingAngle(playerid, Pos[3]);
            new veh = GetVehicleModelID(Vehicle);
            if(veh < 400 || veh > 611) return SendClientMessage(playerid, GREY, "That wasn't a valid vehicle name.");
            if(!IsPlayerInAnyVehicle(playerid))
            {
                new vehicleid = CreateVehicle(veh, Pos[0], Pos[1], Pos[2], Pos[3], -1, -1, -1);
                PutPlayerInVehicle(playerid, vehicleid, 0);
                format(string, sizeof(string), "AdmCmd: %s has just spawned a %s (VID: %d)", RemoveUnderScore(playerid), GetVehicleName(GetPlayerVehicleID(playerid)), GetPlayerVehicleID(playerid));
                SendAdminMessage(RED, string);
            }
            else return SendClientMessage(playerid, GREY, "You mustn't be in a vehicle to use this command.");
        }
        else return SendClientMessage(playerid, GREY, "Usage: /veh [vehiclename]");
    }
    else return SendClientMessage(playerid, GREY, AdminOnly);
    return 1;
}
At the end, none of the commands worked. The same happened to every of them. It says the vehicle has been spawned but the vehicle is not there.
Reply
#2

if(Vehicle[playerid] != 0)
!= INVALID_VEHICLEID
What if the ID of it is 0?

Do the same under OnPlayerDisconnect:
if(Vehicle[playerid] != INVALID_PLAYER_ID) DestroyVehicle(Vehicle[playerid]);

If it continues to have issues, I will test it in my script and resolve the issue.
Reply
#3

Quote:
Originally Posted by bensmart469
Посмотреть сообщение
if(Vehicle[playerid] != 0)
!= INVALID_VEHICLEID
What if the ID of it is 0?

Do the same under OnPlayerDisconnect:
if(Vehicle[playerid] != INVALID_PLAYER_ID) DestroyVehicle(Vehicle[playerid]);

If it continues to have issues, I will test it in my script and resolve the issue.
Well, I highly doubt this has anything to do with the problem due to the fact I have tried a few different /veh commands. Not working. Please test it on your script.
Reply
#4

Anyone else with an idea?
Reply
#5

Quote:
Originally Posted by benjaminjones
Посмотреть сообщение
At the end, none of the commands worked. The same happened to every of them. It says the vehicle has been spawned but the vehicle is not there.
Have you checked the limit to create a car? Maybe you are trying to create more > 2000, forgetting that you already have placed on the server of vehicles so that you do not have enough slots

Check limits:
PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    if (
strcmp("/tottalcar"cmdtexttrue) == 0)
    {
        new
              
num
        
;
        for (new 
GetVehiclePoolSize(); >= 1; --v) {
              if (
GetVehicleModel(v) >= 400 && GetVehicleModel(v) <= 611num++;
        }
        new
             
msg[128]
        ;   
        
format(msgsizeof(msg), "Total of %d vehicles server"num);
        
SendClientMessange(playerid0xFF0000FFmsg);
        return 
true;
    }
    return 
false;

Reply
#6

Try this way:

Код:
CMD:veh(playerid, params[])
{
new car, Float:CarPos[3], string[32];

if(sscanf(params,"d", car)) return SendClientMessage(playerid,0xff0000ff,"USAGE: /Veh <Vehicle ID 400 - 611>");
if(car < 400 || car > 611) return SendClientMessage(playerid, 0xff0000ff, "ERROR: Cannot go under 400 or above 611.");	
if(GetPlayerInterior(playerid) != 0) return 1;

GetPlayerPos(playerid, CarPos[0], CarPos[1], CarPos[2]);
DestroyVehicle(Vehicle[playerid]);
Vehicle[playerid] = CreateVehicle(car, CarPos[0], CarPos[1], CarPos[2] + 2.0, 0, -1, -1, 1);
SetVehicleVirtualWorld(Vehicle[playerid], GetPlayerVirtualWorld(playerid));
PutPlayerInVehicle(playerid, Vehicle[playerid], 0);
format(string,sizeof(string),"You Have Spawned Vehicle ID %i",car);
SendClientMessage(playerid, 0xffffffff, string);
return 1;
}
Reply
#7

Quote:
Originally Posted by Boot
Посмотреть сообщение
Try this way:

Код:
CMD:veh(playerid, params[])
{
new car, Float:CarPos[3], string[32];

if(sscanf(params,"d", car)) return SendClientMessage(playerid,0xff0000ff,"USAGE: /Veh <Vehicle ID 400 - 611>");
if(car < 400 || car > 611) return SendClientMessage(playerid, 0xff0000ff, "ERROR: Cannot go under 400 or above 611.");	
if(GetPlayerInterior(playerid) != 0) return 1;

GetPlayerPos(playerid, CarPos[0], CarPos[1], CarPos[2]);
DestroyVehicle(Vehicle[playerid]);
Vehicle[playerid] = CreateVehicle(car, CarPos[0], CarPos[1], CarPos[2] + 2.0, 0, -1, -1, 1);
SetVehicleVirtualWorld(Vehicle[playerid], GetPlayerVirtualWorld(playerid));
PutPlayerInVehicle(playerid, Vehicle[playerid], 0);
format(string,sizeof(string),"You Have Spawned Vehicle ID %i",car);
SendClientMessage(playerid, 0xffffffff, string);
return 1;
}
This one appears to be working.
Reply
#8

If it doesn't work still the use this one.
Код:
COMMAND:vc(playerid, params[])
{
	if(playerData[playerid][playerLoggedIn])
	{
		if(playerData[playerid][playerLevel] >= 3)
		{
			new message[128], vehName[16], vehID, Float:jX, Float:jY, Float:jZ, Float:jA;

			if(!sscanf(params, "s[16]", vehName))
			{
				vehID = getVehicleModelFromName(vehName);
				
				if(vehID < 400 || vehID > 612)
				{
					SendClientMessage(playerid, COLOR_WHITE, "{B7B7B7}[SERVER] {FFFFFF}Unknown vehicle name provided!");
				}
				else
				{
					GetPlayerFacingAngle(playerid, jA);
					GetPlayerPos(playerid, jX, jY, jZ);
					
					if(vehID == 612)
					{
						if(playerData[playerid][playerLevel] >= 6)
						{
							SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USEJETPACK);
						}
						else
						{
							SendClientMessage(playerid, COLOR_WHITE, "{B7B7B7}[SERVER] {FFFFFF}Due to the anti-cheat method this server uses, you're unable to spawn a jetpack.");
						}
					}
					else
					{
						for(new v = 0; v < MAX_ADMIN_SPAWNED_VEHICLES; v++)
						{
							if(!adminSpawnedVehicles[v])
							{
								adminSpawnedVehicles[v] = CreateVehicle(vehID, jX, jY, jZ, jA, random(255), random(255), 120);
								LinkVehicleToInterior(adminSpawnedVehicles[v], GetPlayerInterior(playerid));
								SetVehicleVirtualWorld(adminSpawnedVehicles[v], GetPlayerVirtualWorld(playerid));
								ac_PutPlayerInVehicle(playerid, adminSpawnedVehicles[v], 0);
								format(message, sizeof(message), "{02FBF2}[ADMIN] {FFFFFF}You have spawned a %s", vehicleNames[vehID - 400]);
								SendClientMessage(playerid, COLOR_WHITE, message);
								
								break;
							}
							
							if(v == (MAX_ADMIN_SPAWNED_VEHICLES - 1))
							{
								SendClientMessage(playerid, COLOR_WHITE, "{B7B7B7}[SERVER] {FFFFFF}Too many administrator vehicles have been spawned, remove some before trying again.");
							}
						}
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_WHITE, "{B7B7B7}[SERVER] {FFFFFF}Usage: \"vc <vehicle name>\"");
			}
		}
		else
		{
			return 0;
		}
	}
	else
	{
		SendClientMessage(playerid, COLOR_WHITE, "{B7B7B7}[SERVER] {FFFFFF}You must be logged in to use commands.");
	}
	
	return 1;
}
Reply
#9

^ I will try this one later, as I am not home right now. But I need to define MAX_ADMIN_SPAWNED_VEHICLES. Please, add it below.
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)