跳到主要内容

SetVehicleParamsEx

描述

设置车辆的全局参数,对所有玩家生效。

参数名说明
vehicleid目标车辆的 ID
bool:engine引擎状态(0=关闭,1=启动)
bool:lights车灯状态(0=关闭,1=开启)
bool:alarm警报状态(1=触发警报声)
bool:doors车门锁状态(0=解锁,1=上锁)
bool:bonnet引擎盖状态(0=关闭,1=开启)
bool:boot行李箱状态(0=关闭,1=开启)
bool:objective目标箭头显示(0=隐藏,1=显示)

返回值

true - 函数执行成功

false - 函数执行失败(通常表示车辆不存在)

示例代码

// 全局变量声明
new
gVehicleAlarmTimer[MAX_VEHICLES] = {0, ...};

// 修改单个参数时需先获取当前状态
new
bool:engine, bool:lights, bool:alarm, bool:doors, bool:bonnet, bool:boot, bool:objective;

// 创建车辆时的设置
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, lights, alarm, doors, bonnet, boot, objective); // 仅修改引擎状态

// 带警报自动关闭的增强函数
SetVehicleParamsEx_Fixed(vehicleid, &bool:engine, &bool:lights, &bool:alarm, &bool:doors, &bool:bonnet, &bool:boot, &bool:objective)
{
SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
if (alarm)
{
// 重置定时器实现20秒后自动关闭警报
KillTimer(gVehicleAlarmTimer[vehicleid]);
gVehicleAlarmTimer[vehicleid] = 0;
gVehicleAlarmTimer[vehicleid] = SetTimerEx("DisableVehicleAlarm", 20000, false, "d", vehicleid);
}
}

forward DisableVehicleAlarm(vehicleid);
public DisableVehicleAlarm(vehicleid)
{
new
bool:engine, bool:lights, bool:alarm, bool:doors, bool:bonnet, bool:boot, bool:objective;

GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
if (alarm == VEHICLE_PARAMS_ON)
{
SetVehicleParamsEx(vehicleid, engine, lights, VEHICLE_PARAMS_OFF, doors, bonnet, boot, objective);
}

gVehicleAlarmTimer[vehicleid] = 0;
}

定义常量

  • VEHICLE_PARAMS_UNSET (-1) 未设置
  • VEHICLE_PARAMS_OFF (0) 关闭
  • VEHICLE_PARAMS_ON (1) 开启

注意事项

提示
  • 警报触发后不会自动停止,需手动调用本函数关闭
  • 启用ManualVehicleEngineAndLights后,车灯在白天也会保持开启状态

相关函数