Help With a dcmd Command
#1

Well, I'm new to dcmd and a beginner with Pawno. I know the basics and what not but right now I'm just trying to script random things to get a bit better at it.
Right now I'm trying to script a command that works like this. If a player types /vspawn [Vehicle ID], the vehicle id they typed after the command will spawn for them. Really, I don't even know where to start on it. I'm using dcmd, which I know the basics of it and how it works but I don't know what to do for the vehicle ID part. I have no clue at all for if the player types /vspawn and a random ID, how to get that vehicle id and spawn it. Any help would be greatly appreciated.
Reply
#2

Try this:
pawn Код:
// You might need this, if so, add it onto of your gamemode
#if !defined isnull
    #define isnull(%1) \
                ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif

public OnPlayerCommandText(playerid, cmdtext[]) // Use ZCMD and save yourself from using this lines
{
    dcmd(vspawn, 6, cmdtext);
    return 0;
}

dcmd_vspawn(playerid, params[])
{
    if(!isnull(params)) return SendClientMessage(playerid, COLOR_RED, "Usage: /VSpawn < Vehicle ID >"); // If the player didn't typed anything after /vspawn

    new
        i_Vehicle = strval(params),
        Float:v_Pos[4]; // We will get the player's pos and create the vehicle at that same spot.

    GetPlayerPos(playerid, v_Pos[0], v_Pos[1], v_Pos[2]); // Getting X, Y, Z and storing it in v_Pos
    GetPlayerFacingAngle(playerid, v_Pos[3]); // Getting the facing angle
   
    new
        iVehicle = CreateVehicle(i_Vehicle, v_Pos[0], v_Pos[1], v_Pos[2], v_Pos[3], -1, -1, (60*30)); // Create our vehicle

    PutPlayerInVehicle(playerid, iVehicle, 0); // Putting the player inside the vehicle as a driver
    return 1;
}
I'm sleepy, so I might of missed some code.

Cheers.
Reply
#3

Quote:
Originally Posted by [L3th4l]
Посмотреть сообщение
Try this:
pawn Код:
// You might need this, if so, add it onto of your gamemode
#if !defined isnull
    #define isnull(%1) \
                ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif

public OnPlayerCommandText(playerid, cmdtext[]) // Use ZCMD and save yourself from using this lines
{
    dcmd(vspawn, 6, cmdtext);
    return 0;
}

dcmd_vspawn(playerid, params[])
{
    if(!isnull(params)) return SendClientMessage(playerid, COLOR_RED, "Usage: /VSpawn < Vehicle ID >"); // If the player didn't typed anything after /vspawn

    new
        i_Vehicle = strval(params),
        Float:v_Pos[4]; // We will get the player's pos and create the vehicle at that same spot.

    GetPlayerPos(playerid, v_Pos[0], v_Pos[1], v_Pos[2]); // Getting X, Y, Z and storing it in v_Pos
    GetPlayerFacingAngle(playerid, v_Pos[3]); // Getting the facing angle
   
    new
        iVehicle = CreateVehicle(i_Vehicle, v_Pos[0], v_Pos[1], v_Pos[2], v_Pos[3], -1, -1, (60*30)); // Create our vehicle

    PutPlayerInVehicle(playerid, iVehicle, 0); // Putting the player inside the vehicle as a driver
    return 1;
}
I'm sleepy, so I might of missed some code.

Cheers.
Thanks, I see what to do now. I've heard that dcmd is more simple so until I get at least a bit decent at scripting, I will switch to zcmd.
Reply
#4

I changed it up a bit and put it as this. I'm not sure what is wrong with it. It does not show the usage message if you just do /vspawn. However if you do /vspawn [Anything here] It will show the correct usage message. It does not spawn the vehicle either. I think it may have something to do with the player positioning coding. Here is the coding.

Код:
#if !defined isnull
    #define isnull(%1) \
                ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif

public OnPlayerCommandText(playerid, cmdtext[])
{
	dcmd(vspawn, 6, cmdtext);
	return 0;
}
	
dcmd_vspawn(playerid, params[])
{
	if(!isnull(params)) return SendClientMessage(playerid, 0x90EE90FF, "Correct Format: /vspawn [Vehicle ID]");
	
	new i_Vehicle = strval(params);
	new Float:x, Float:y, Float:z, Float:ROT;
	GetPlayerPos(playerid, x, y, z);
	GetPlayerFacingAngle(playerid, Float:ROT);
	
	new iVehicle = CreateVehicle(i_Vehicle, Float:x, Float:y, Float:z, Float:ROT, 3, 3, 15);
	
	PutPlayerInVehicle(playerid, iVehicle, 0);
	return 1;
}
Reply
#5

Bump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)