- 168
- 182
Как реализовать курд через синхру в SF? Почему это не дает никакого результата?
Тоже самое, но на луа. Работает как часы:
это:
void __stdcall test(std::string arg) {
bNop = !bNop;
bTest = !bTest;
AddChat(ColorYellow bNop ? "Start" : "Stop");
}
bool __stdcall onSendPacket(stRakNetHookParams* pRakHook) {
if (pRakHook->packetId == ID_VEHICLE_SYNC)
if (bNop)
return false;
return true;
}
void __stdcall mainloop()
{
static bool initialized = false;
if (bTest) {
if (PEDSELF->GetVehicle()) {
if (GetTickCount() - 30 > timer) {
stInCarData incar;
memset(&incar, 0, sizeof(stInCarData));
incar = SF->getSAMP()->getPlayers()->pLocalPlayer->inCarData;
if (GetDistance(incar.fPosition[0], incar.fPosition[1], incar.fPosition[2], 2422.2329101563, 1705.0350341797, 10.751810073853) < 5) {
PEDSELF->GetVehicle()->Teleport(2422.2329101563, 1705.0350341797, 10.751810073853);
bTest = false;
bNop = false;
}
CVector vec(2422.2329101563 - incar.fPosition[0], 1705.0350341797 - incar.fPosition[1], 10.751810073853 - incar.fPosition[2]);
vec.Normalize();
incar.fMoveSpeed[0] = 0.1000100107375;
incar.fMoveSpeed[1] = 0.0130210005875;
incar.fMoveSpeed[2] = 0.00000000195313;
incar.fPosition[0] = incar.fPosition[0] + (vec.fX * 4.5);
incar.fPosition[1] = incar.fPosition[1] + (vec.fY * 4.5);
incar.fPosition[2] = incar.fPosition[2] + (vec.fZ * 4.5);
BitStream bs;
bs.Write((BYTE)ID_VEHICLE_SYNC);
bs.Write((PCHAR)&incar, sizeof(stInCarData));
SF->getRakNet()->SendPacket(&bs);
timer = GetTickCount();
}
}
else {
AddChat(ColorYellow, "Необходимо сесть в машину!");
bTest = false;
}
}
if (!initialized)
{
if (GAME && GAME->GetSystemState() == eSystemState::GS_PLAYING_GAME && SF->getSAMP()->IsInitialized())
{
initialized = true;
SF->getSAMP()->registerChatCommand("test", test);
SF->getRakNet()->registerRakNetCallback(RakNetScriptHookType::RAKHOOK_TYPE_OUTCOMING_PACKET, onSendPacket);
}
}
}
Тоже самое, но на луа. Работает как часы:
Lua:
function main()
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand("test", function()
_, x, y, z = getTargetBlipCoordinates()
if _ then
car = storeCarCharIsInNoSave(PLAYER_PED)
if car then
Nop = true
Kaka(x, y, z, car)
end
end
end)
end
function Kaka(x, y, z, car)
local data = samp_create_sync_data('vehicle')
lua_thread.create(function()
while true do wait(30)
xx, yy, zz = x - data.position.x, y - data.position.y, z - data.position.z
vectorPlayer = vector3D(xx, yy, zz)
vectorPlayer:normalize()
data.moveSpeed.x = 0.1000100107375
data.moveSpeed.y = 0.0130210005875
data.moveSpeed.z = 0.00000000195313
data.position.x = data.position.x + (vectorPlayer.x * 4.5)
data.position.y = data.position.y + (vectorPlayer.y * 4.5)
data.position.z = data.position.z + (vectorPlayer.z * 4.5)
data.send()
if getDistanceBetweenCoords2d(data.position.x, data.position.y, x, y) < 5 then
setCarCoordinates(car, x, y, z)
wait(100)
Nop = false
break
end
end
end)
end
function ev.onSendVehicleSync(data)
if Nop then return false end
end
Последнее редактирование: