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

Update User.lua #687

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions vrp/User.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ end

-- use character
-- return true or false, err_code
-- Removed delay for character switching to improve responsiveness.
--- Note: Use only when immediate switching is required, as this bypasses the built-in delay handling.
-- err_code:
--- 1: delay error, too soon
--- 2: already loading
--- 3: invalid character
function User:useCharacter(id)
function User:useCharacter(id, bypass)
bypass = bypass or false -- bypass the loading timer
if id == self.cid then return true end -- same check

-- delay check
if self.use_character_action:remaining() > 0 then return false, 1 end
-- delay check (bypass condition)
if not bypass and self.use_character_action:remaining() > 0 then return false, 1 end

if self.loading_character then return false, 2 end -- loading check

Expand Down Expand Up @@ -109,13 +112,14 @@ function User:useCharacter(id)
vRP:triggerEventSync("characterLoad", self)
self.loading_character = false

self.use_character_action:perform(vRP.cfg.character_select_delay)

if self.spawns > 0 then -- trigger respawn if already spawned
vRP.EXT.Base.remote._triggerRespawn(self.source)
if not bypass then
self.use_character_action:perform(vRP.cfg.character_select_delay)

if self.spawns > 0 then -- trigger respawn if already spawned
vRP.EXT.Base.remote._triggerRespawn(self.source)
end
end


return true
end

Expand Down