-- 判断是否为服务器,如果不是则返回 if not isServer() then return end

-- 处理客户端命令的函数 local function RV_B_OnClientCommand(module, command, player,arguments) -- 如果模块是'RV_Entercarhouse',表示玩家要进入车库 if module=='RV_Entercarhouse' then -- 获取要进入的车辆 local vehicle = getVehicleById(arguments[1]) -- 初始化车库编号和车库数据 if getGameTime():getModData().RVservercarhousenum==nil then getGameTime():getModData().RVservercarhousenum=0 end if getGameTime():getModData().RVservercarhouse==nil then getGameTime():getModData().RVservercarhouse={} end -- 如果该车辆还没有分配车库编号,则分配一个 if vehicle:getModData().RVservercarhousenum==nil then vehicle:getModData().RVservercarhousenum=getGameTime():getModData().RVservercarhousenum+1 getGameTime():getModData().RVservercarhousenum=getGameTime():getModData().RVservercarhousenum+1 getGameTime():getModData().RVservercarhouse[vehicle:getModData().RVservercarhousenum]={} end -- 如果车库编号已经达到上限,则返回 if vehicle:getModData().RVservercarhousenum>25 then return end -- 发送进入车库命令给客户端 sendServerCommand(player,'RV_B_Entercarhouse', 'true',{vehicle:getModData().RVservercarhousenum,arguments[1]}) -- 将玩家位置记录到车库数据中 if getGameTime():getModData().RVserverhouseplayerpos==nil then getGameTime():getModData().RVserverhouseplayerpos={} end getGameTime():getModData().RVserverhouseplayerpos[player:getUsername()]=vehicle:getModData().RVservercarhousenum -- 如果模块是'RV_carhouseExit',表示玩家要离开车库 elseif module == 'RV_carhouseExit' then -- 如果玩家已经进入车库,则发送离开车库命令给客户端 if getGameTime():getModData().RVserverhouseplayerpos[player:getUsername()]~=nil then local housecarpos=getGameTime():getModData().RVservercarhouse[getGameTime():getModData().RVserverhouseplayerpos[player:getUsername()] ] sendServerCommand(player,'RV_B_carhouseExit', 'true',housecarpos) end -- 如果模块是'RVpartcondition',表示要更新车辆部件的耐久度 elseif module=='RVpartcondition' then -- 获取车辆和部件 local vehiclezb = getVehicleById(arguments[1]) local partzb = vehiclezb:getPartById(command) -- 将部件耐久度减2 partzb:setCondition(partzb:getCondition()-2) -- 发送更新耐久度命令给客户端 sendServerCommand(module, command,{arguments[1],partzb:getCondition()}) -- 如果模块是'RV_B_railgun',表示要更新轨道炮状态 elseif module=='RV_B_railgun' then -- 获取车辆 local vehicleza = getVehicleById(arguments[1]) -- 如果车辆存在,则更新轨道炮状态 if vehicleza then vehicleza:getModData().RV_B_railgundic = arguments[2] sendServerCommand('RV_B_railgun', 'true',{vehicleza:getId(),arguments[2]}) end end end

-- 添加客户端命令处理函数到事件监听器中 Events.OnClientCommand.Add(RV_B_OnClientCommand)

-- 定时处理函数,用于更新车库数据 local function RV_OnTick(numberTicks) -- 如果车库数据存在,则遍历每个车库 if getGameTime():getModData().RVservercarhouse~=nil then for i=1,#getGameTime():getModData().RVservercarhouse do -- 获取所有车辆 local vehicles=getCell():getVehicles() -- 初始化标志位,用于判断是否找到对应车库的车辆 local spnumber=0 -- 遍历所有车辆 for k=1,vehicles:size() do -- 获取当前车辆 local vehiclez=vehicles:get(k-1) -- 获取车辆的车库编号 local vehiclesnum = vehiclez:getModData().RVservercarhousenum -- 如果车辆有车库编号,且编号与当前循环的车库编号一致 if vehiclesnum ~=nil then if vehiclesnum==i then -- 更新车库数据,将车辆位置和车辆ID保存到车库数据中 getGameTime():getModData().RVservercarhouse[vehiclesnum]={vehiclez:getX(),vehiclez:getY(),vehiclez:getZ(),{true,vehiclez:getId()}} -- 设置标志位,表示找到了对应车库的车辆 spnumber=1 end end end -- 如果没有找到对应车库的车辆,则将车库数据中的车辆存在标志设置为false if spnumber==0 then if getGameTime():getModData().RVservercarhouse[i]==nil then getGameTime():getModData().RVservercarhouse[i]={} end getGameTime():getModData().RVservercarhouse[i][4]=false end end end end

-- 添加定时处理函数到事件监听器中 Events.OnTick.Add(RV_OnTick)

Project Zomboid Mod: RV 车库管理系统 - 服务器端代码

原文地址: https://www.cveoy.top/t/topic/nnAv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录