#1

hey guys im new scripting and i want to make a cmd to my server about when i type /vehrotate , show me a dialog 90 - 180 - 270 and 360, and when i type for example /vehrotate 90 put that possition in my car, can u explain to me how can i do it? and of course its for an admin lvl 4 cmd
Reply
#2

Hi Jaua10!

Adding the command itself is not too hard. Either way, you can use "OnPlayerCommandText", or you can consider adding support for ZCMD or a different command processor. (it all comes down to preference and ease to use.

When you've added the command itself, you need to do the logic. In my example, I am using ZCMD.
First you can check if the player is an admin (here is an example)

PHP код:
CMD:vehrotate(playeridparams[])
{
    
//check if user is an administrator. Please replace with correct variable/method
    
if(!IsPlayerAdmin(playerid))
        return 
0//if he is not an admin, you can return 0 to show "unknown command". 

As you can see, we check with an if-statement whether the player is an admin, or not.


Next thing you can do, you can ensure that the player is inside a vehicle. Why? Well, because we can't rotate a vehicle if he is on foot, right? And since we need the vehicle id later on, we can save the vehicle he is in, in a variable.

PHP код:

CMD
:vehrotate(playeridparams[])
{
    
//check if user is an administrator. Please replace with correct variable/method
    
if(!IsPlayerAdmin(playerid))
        return 
0;
    new 
vehicleid;
    if(
IsPlayerInVehicle(playerid) == true)
    {
        
vehicleid GetPlayerVehicleID(playerid); //save to a variable
    
}   
    return 
1;

What now? You said you wanted to put a value for the rotation as a parameter (/vehrotate [number])
In order to do that, we should check if the user has put a value in the command.
for that, we will use "strval" and "strlen" on the "params[]" parameter, and see if it returns anything at all, and if it returns the correct values.

PHP код:
CMD:vehrotate(playeridparams[])
{
    
//check if user is an administrator. Please replace with correct variable/method
    
if(!IsPlayerAdmin(playerid))
        return 
0;
    new 
vehicleid;
    if(
IsPlayerInVehicle(playerid) == true)
    {
        
vehicleid GetPlayerVehicleID(playerid); //save to a variable
        
if(strlen(params) > /*if length is longer than 0*/)
        {
            if(
strval(params) == 90 || strval(params) == 180 || strval(params) == 270 || strval(params) == 360)
            {
            }
        }
        
    }   
    return 
1;


And when we are sure the values are okay, and they are the values we want - we can go ahead and affect the car of the player.


PHP код:
CMD:vehrotate(playeridparams[])
{
    
//check if user is an administrator. Please replace with correct variable/method
    
if(!IsPlayerAdmin(playerid))
        return 
0;
    new 
vehicleid;
    if( 
IsPlayerInVehicle(playerid) == true )
    {
        
vehicleid GetPlayerVehicleID(playerid); //save to a variable
        
if(strlen(params) > /*if length is longer than 0*/)
        {
            if(
strval(params) == 90 || strval(params) == 180 || strval(params) == 270 || strval(params) == 360)
            {
                
SetVehicleZAngle(vehicleidstrval(params)); //this will set the rotation of the car that we identified earlier
                
SendClientMessage(playerid, -1"Your car has been rotated");
            }
        }
    }  
    return 
1;

And now, just tidy up, add some messages and the command is done:

PHP код:
CMD:vehrotate(playeridparams[])
{
    
//check if user is an administrator. Please replace with correct variable/method
    
if(!IsPlayerAdmin(playerid))
        return 
0;
    new 
vehicleid;
    if(
IsPlayerInVehicle(playerid) == true)
    {
        
vehicleid GetPlayerVehicleID(playerid); //save to a variable
        
if(strlen(params) > /*if length is longer than 0*/)
        {
            if(
strval(params) == 90 || strval(params) == 180 || strval(params) == 270 || strval(params) == 360)
            {
                
SetVehicleZAngle(vehicleidstrval(params)); //this will set the rotation of the car that we identified earlier
                
SendClientMessage(playerid, -1"Your car has been rotated");
            }
            else
            {
                
SendClientMessage(playerid, -1"Please enter a value: 90, 180, 270, 360");
            }
        }
        else
        {
            
SendClientMessage(playerid, -1"Please enter a value: 90, 180, 270, 360");
        }
    }
    else
    {
        
SendClientMessage(playerid, -1"You need to be in a vehicle to rotate");
    }
    return 
1;    

That is how you could do it
Reply
#3

Excelent explanation man, thank you so much, you got my REP+.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)