spawning vehicle help needed :D
#1

hey, i only just started pawno recently (had experience with python before mind you) and was wondering if anyone could help me. i want to make it so when someone types /spawn (vehicleid) that it spawns it at them, and puts them in drivers seat. i got this far for making teh car, but couldnt get the player in the car. any help?
Код:
dcmd_spawn(playerid, params[])
{
	new Car = strval(params);
	if (strlen(params))
	{
		new Float:angle, Float:x, Float:y, Float:z;
		GetPlayerPos(playerid, x, y, z);
		GetPlayerFacingAngle(playerid, angle);
		CreateVehicle(Car, x, y, z+2, angle, -1, -1, -1);
		return 1;
	}
	else
	{
	  SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/spawn [vehicle id]\"");
	}
	
	return 1;
}
Reply
#2

Try this:
pawn Код:
dcmd_spawn(playerid, params[])
{
    Car = strval(params);
    if (strlen(params))
    {
        new Float:angle, Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, angle);
        new car2 = CreateVehicle(Car, x, y, z+2, angle, -1, -1, -1);
             PutPlayerInVehicle(playerid, car2, 0);
        return 1;
    }
    else
    {
      SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/spawn [vehicle id]\"");
    }
   
    return 1;
}
Reply
#3

ok sweet that works, but what can i add that tests to make sure that the input id is a valid vehicle id?after a few tests (spawning 5 andromadas is not good), i crashed my game because i tried /spawn 1. what can i put in to check that it is a vehicle id, and return a message just like this 1:
Код:
else
{
    SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/spawn [vehicle id]\"");
}
Reply
#4

Use an if statement to check if the Id is within the correct range. For example:
pawn Код:
if(Car < lowestid || Car > highestid) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/spawn [vehicle id]\"");
That checks if the Car ID entered is less than the lowest possible Id, or greater than the highest possible ID.
You should replace 'lowestid' and 'highestid' with the correct Ids for those positions.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)