Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Human:getVehicleSeat() could returns nil instead of -1 #113

Open
Deewarz opened this issue Jan 12, 2025 · 8 comments
Open

Human:getVehicleSeat() could returns nil instead of -1 #113

Deewarz opened this issue Jan 12, 2025 · 8 comments
Labels
enhancement New feature or request priority:low question Further information is requested

Comments

@Deewarz
Copy link
Contributor

Deewarz commented Jan 12, 2025

Description

When the player is not in a vehicle, could we return nil instead of -1?

int Human::GetVehicleSeat() const {
const auto updateData = _ent.get<MafiaMP::Shared::Modules::HumanSync::UpdateData>();
const auto carEnt = flecs::entity(_ent.world(), updateData->carPassenger.carId);
if (carEnt.is_valid() && carEnt.is_alive()) {
return updateData->carPassenger.seatId;
}
return -1;
}

What do you think about it?

Reproduction

When not in vehicle, connected to a server, type /seat in chat

listenEvent("onChatCommand", function (player, message, command, args)
  if command == "seat" then
    local seat = player:getVehicleSeat() -- returns -1 currently, could returns nil
  end
end)
@Kamzik123
Copy link

Doesn't it return -1 in the original game's lua too? I know it does in Mafia 2.

@Deewarz
Copy link
Contributor Author

Deewarz commented Jan 13, 2025

This is a very interesting remark that I often ask myself, should we be similar to the behavior and naming of the original Mafia code or make it as clear as possible for the end user in the sdk layer? cc @zpl-zak @Segfaultd

@zpl-zak
Copy link
Member

zpl-zak commented Jan 13, 2025

I'd split the function to two, one providing Seat index (or -1 if empty), other a valid Human object (or nil in case it's empty).

@Segfaultd
Copy link
Member

Agree with @zpl-zak. If the function expected outcome is an index, then -1 is the answer. If it's supposed to return an instance then nil, a string then "" etc...

@Segfaultd Segfaultd changed the title [Discussion] [Scripting] Human:getVehicleSeat() could returns nil instead of -1 Human:getVehicleSeat() could returns nil instead of -1 Jan 14, 2025
@Segfaultd Segfaultd added enhancement New feature or request question Further information is requested priority:low labels Jan 14, 2025
@Deewarz
Copy link
Contributor Author

Deewarz commented Jan 14, 2025

So not applicable then. Can I close the issue?

@zpl-zak
Copy link
Member

zpl-zak commented Jan 14, 2025

So not applicable then. Can I close the issue?

I'd keep it open since I feel it would be beneficial to split this method. User might want to access the Human object directly, which this method does not provide. I envision having this method renamed to something like getVehicleSeatIndex probably, while the original name would get repurposed for grabbing Human ref.

@zpl-zak zpl-zak added this to the racing gamemode milestone Jan 14, 2025
@Deewarz
Copy link
Contributor Author

Deewarz commented Jan 14, 2025

Ok for the renaming to GetVehicleSeatIndex, I'll do it.

Howerver, I don't understand the role of the second function?
Do you mean a function that would be more on the vehicle, like Vehicle::GetHumanAtSeatIndex(seatIndex)?

@zpl-zak
Copy link
Member

zpl-zak commented Jan 14, 2025

Ok for the renaming to GetVehicleSeatIndex, I'll do it.

Howerver, I don't understand the role of the second function? Do you mean a function that would be more on the vehicle, like Vehicle::GetHumanAtSeatIndex(seatIndex)?

oh yea sorry, something like that would work, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority:low question Further information is requested
Projects
Status: No status
Development

No branches or pull requests

4 participants