Vehicle door control problems
#1

I tried to create a command which opens selected vehicles doors with number 1 meaning drivers door, number 2 meaning passenger door etc., but I can't make it work. I truly have no idea how to create such a complicated command. I already defined the SetVehicleParamsCarDoors, but it seems to have no effect.

Код:
CMD:vdoor(playerid, params[])
{
	new vehicleid, doorid;
	if(sscanf(params, "iii", vehicleid, doorid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /vdoor [vehicle ID] [door ID]");

	if(strcmp(params, "1", true)) == 0
	{
		SetVehicleParamsCarDoors(vehicleid, 1, 0, 0, 0);
	}
	
	else if(strcmp(params, "2", true)) == 0
	{
		SetVehicleParamsCarDoors(vehicleid, 0, 1, 0, 0);
	}
	
	else if(strcmp(params, "3", true)) == 0
	{
		SetVehicleParamsCarDoors(vehicleid, 0, 0, 1, 0);
	}
	
	else if(strcmp(params, "4", true)) == 0
	{
		SetVehicleParamsCarDoors(vehicleid, 0, 0, 0, 1);
	}
	return 1;
}
Код:
./includes/commands.pwn(55821) : error 029: invalid expression, assumed zero
./includes/commands.pwn(55821 -- 55822) : error 029: invalid expression, assumed zero
./includes/commands.pwn(55823) : error 029: invalid expression, assumed zero
./includes/commands.pwn(55823) : warning 215: expression has no effect
./includes/commands.pwn(55826) : error 029: invalid expression, assumed zero
./includes/commands.pwn(55826) : warning 215: expression has no effect
./includes/commands.pwn(55826) : error 001: expected token: ";", but found "if"
./includes/commands.pwn(55826) : error 029: invalid expression, assumed zero
./includes/commands.pwn(55826) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


7 Errors.
Reply
#2

You are close, look at parentheses ("(" and ")"), they have to match.

pawn Код:
if(strcmp(params, "1", true)) == 0 //wrong
if(strcmp(params, "1", true) == 0) //right
Reply
#3

There are more issues.

- 3 specifiers and 2 arguments in sscanf.
- comparing "params" to a single number. "params" will hold two parameters so the check will fail. Compare integers instead with "doorid".

A better way is to store the states of the doors and apply only to the specified. If it is closed, it will open and vice versa.

PHP код:
CMD:vdoor(playeridparams[]) 

    new 
vehicleiddoor
    if (
sscanf(params"ii"vehicleiddoor)) 
    { 
        
SendClientMessage(playerid, -1"Usage: /vdoor <vehicleid> <door>"); 
        
SendClientMessage(playerid, -1"Doors: 0 - driver | 1 - passenger | 2 - back left | 3 - back right"); 
        return 
1
    } 
    if (!
GetVehicleModel(vehicleid)) return SendClientMessage(playerid, -1"This vehicle does not exist."); 
    if (!(
<= door <= 3)) return SendClientMessage(playerid, -1"The value of 'door' parameter should be between 0 and 3"); 

    new 
driverpassengerbackleftbackright
    
GetVehicleParamsCarDoors(vehicleiddriverpassengerbackleftbackright); 

    switch (
door
    { 
        case 
0SetVehicleParamsCarDoors(vehicleid, !driverpassengerbackleftbackright); 
        case 
1SetVehicleParamsCarDoors(vehicleiddriver, !passengerbackleftbackright); 
        case 
2SetVehicleParamsCarDoors(vehicleiddriverpassenger, !backleftbackright); 
        case 
3SetVehicleParamsCarDoors(vehicleiddriverpassengerbackleft, !backright); 
    } 
    return 
1

Reply


Forum Jump:


Users browsing this thread: