Skip to content

Commit

Permalink
Added real scoreboard + shake cam
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron1a12 committed Mar 2, 2021
1 parent 9d0b544 commit ab8fe50
Show file tree
Hide file tree
Showing 10 changed files with 476 additions and 34 deletions.
5 changes: 4 additions & 1 deletion __resource.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ client_scripts {
'respawn.lua',
'mood.lua',
'reticule.lua',
'cam.lua',
'client.lua',
'Client.net.dll',
}
Expand All @@ -26,10 +27,12 @@ ui_page('html/index.html')
files {
'html/index.html',
'html/img/reticle.png',
'html/img/reticle_shotgun.png',
'html/css/main.css',
'html/css/DIN-Medium.ttf',
'html/js/howler.min.js',
'html/sounds/death.ogg'
'html/sounds/death.ogg',
'html/sounds/wlf.ogg',
}


Expand Down
99 changes: 99 additions & 0 deletions cam.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
charCam = CreateCam('DEFAULT_SCRIPTED_CAMERA', true)

SetCamActive(charCam, false)

-- Blend in
--RenderScriptCams(true, true, 0, true, true)

--ShakeCam(charCam, "JOLT_SHAKE", 2.0)


local shakeAmount = 0.0
local bIsShaking = false

Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
SetGameplayCamShakeAmplitude(shakeAmount)
end
end)

Citizen.CreateThread(function()
while true do

Citizen.Wait(20)

if not bIsShaking and shakeAmount > 2.0 then
print("start shaking!?")

bIsShaking = true
end
end
end)



local shakeMinSpeed = 2.0
local shakeMaxSpeed = 6.0
local maxShakeAmount = 0.5

Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
local vel = GetEntityVelocity(GetPlayerPed(-1))
local speed = math.abs(vel.x) + math.abs(vel.y) + math.abs(vel.z)


local percentageMax = shakeMaxSpeed - shakeMinSpeed

local speedPercentage = speed/percentageMax*100


--print(speedPercentage)

if speed <= shakeMinSpeed then
shakeAmount = 0.0
bIsShaking = false
else
shakeAmount = (maxShakeAmount/100*speedPercentage) + 0.0
end
end
end)

Citizen.CreateThread(function()
while false do
--ShakeGameplayCam(‘SMALL_EXPLOSION_SHAKE’, 0.18)
--SetGameplayCamShakeAmplitude(5.0)
local camCoords = GetGameplayCamCoord()
local camRot = GetGameplayCamRot(2)
local camHeading = GetGameplayCamRelativeHeading()
--print(camHeading)

--local playerVector = GetEntityCoords(GetPlayerPed(-1))
local _, forwardVector, _, position = GetEntityMatrix(vehicle)

local forwardVector, rightVector, upVector, position = GetEntityMatrix(GetPlayerPed(-1))
local playerVector = (upVector * 0.5) + (rightVector * 0.5) + position


local midpoint = (playerVector + camCoords) / 2

local dist = #(position - midpoint)


-- -- Use Z


SetCamCoord(charCam, midpoint.x, midpoint.y, midpoint.z)

SetCamRot(charCam, camRot.x, camRot.y, camRot.z, 2)
SetCamFov(charCam, 60.0)

--SetGameplayCamShakeAmplitude(1.0)
--SetFollowPedCamThisUpdate(charCam, 0)
--SetFollowPedCamViewMode(1)
Citizen.Wait(0)


end
end)
100 changes: 92 additions & 8 deletions client.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
SendNUIMessage({
type = 'open'
})
local myScore = 0

local bScoreboardIsOpen = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)

if IsControlPressed(1, 243) and not bScoreboardIsOpen then
SendNUIMessage({name = 'showScoreboard'})
bScoreboardIsOpen = true
elseif bScoreboardIsOpen and IsControlReleased(1, 243) then
bScoreboardIsOpen = false
SendNUIMessage({name = 'hideScoreboard'})
end
end
end)

function onResetRound()
myScore = 0

TriggerEvent("factions:updateMood", Global.Round.CurrentMood)
respawnPed()
SetPlayerControl(PlayerId(), true)
SendNUIMessage({name = 'onResetRound'})
end

AddEventHandler('gameEventTriggered', function (name, args)
if name == 'CEventNetworkStartMatch' and Global.Round == nil then
end
end)

AddEventHandler("playerSpawned", function(spawn)
TriggerServerEvent('factions:playerJoined')

Call('factions:getRoundInfo', {}, function(RoundInfo)
Global.Round = RoundInfo
onResetRound()
end)
end)

RegisterNUICallback('getRoundTimeLeft', function(data, cb)
-- and so does callback response data
Expand All @@ -26,9 +61,58 @@ AddEventHandler("factions:cl_onRoundEnd", function(timeLeft, cbId)
end)
RegisterNetEvent("factions:cl_onRoundEnd")

AddEventHandler("factions:cl_onResetRound", function(RoundInfo)
respawnPed()
SetPlayerControl(PlayerId(), true)
SendNUIMessage({name = 'onResetRound'})
AddEventHandler("factions:cl_onResetRound", function(newRoundInfo)
Global.Round = newRoundInfo
onResetRound()
end)
RegisterNetEvent("factions:cl_onResetRound")

RegisterNUICallback('getScoreboard', function(data, cb)
Call('factions:getScoreboard', {}, function(scoreboard)

-- Stupid fix. Unlike Lua, javascript requires strings as keys NOT numbers
local sb = {}
for playerId, score in pairs(scoreboard) do
sb[tostring(playerId)] = scoreboard[playerId];
end

cb(sb)
end)
end)




AddEventHandler("getWeaponLoadout", function()
print("GET WEAPON LOADOUT!? ")


local loadout = {}
local playerPed = GetPlayerPed(-1)

for _, rank in ipairs(Config.Ranks) do
--rank.MinScore
--rank.Unlocks

for __, weapon in ipairs(rank.Unlocks) do
if weapon[2] == nil then weapon[2] = 1 end

GiveWeaponToPed(playerPed, GetHashKey( weapon[1] ), weapon[2], false, false)

if weapon[3] ~= nil then
GiveWeaponComponentToPed(playerPed, GetHashKey(weapon[1]), GetHashKey(weapon[3]))
end
end

print('rank.MinScore:' .. rank.MinScore .. ', myScore:'..myScore)

if rank.MinScore >= myScore then break end
end
end)

AddEventHandler("factions:cl_killReward", function(totalKills)
myScore = totalKills

TriggerEvent("getWeaponLoadout")
end)
RegisterNetEvent("factions:cl_onResetRound")
RegisterNetEvent("factions:cl_killReward")
39 changes: 38 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Config = {}

Config.Round = {
["DefaultTime"] = 60 * 4, --60 * 4,
["DefaultTime"] = (60 * 7) + 34,
}

Config.Moods = {
Expand All @@ -16,5 +16,42 @@ Config.Moods = {
['Look'] = 'lab_none_exit_OVR',
['Intensity'] = 0.95,
['Weather'] = 'FOGGY'
},
{
['Hour'] = 12,
['Look'] = 'mp_bkr_ware01',
['Intensity'] = 0.80,
['Weather'] = 'EXTRASUNNY'
}
}

Config.Models = {
{"joel", "Joel"},
{"ElliePatrol", "Ellie"},
{"s_m_y_dealer_01", "Hunter"},
{"csb_mweather", "Firefly"},
}

Config.Ranks = {
{
['MinScore'] = 0, ['Unlocks'] = {{'WEAPON_MACHETE'}, {'WEAPON_SMG', 64, 'COMPONENT_AT_PI_SUPP'}}
},
{
['MinScore'] = 1, ['Unlocks'] = {{'WEAPON_PISTOL', 1}}
},
{
['MinScore'] = 2, ['Unlocks'] = {{'WEAPON_PISTOL', 4}, {'WEAPON_MOLOTOV', 2}}
},
{
['MinScore'] = 4, ['Unlocks'] = {{'WEAPON_PISTOL', 8}, {'WEAPON_REVOLVER', 4}}
},
{
['MinScore'] = 8, ['Unlocks'] = {{'WEAPON_PISTOL', 14}, {'WEAPON_REVOLVER', 12}, {'WEAPON_PUMPSHOTGUN', 6}}
},
{
['MinScore'] = 16, ['Unlocks'] = {{'WEAPON_PUMPSHOTGUN', 12}, {'WEAPON_PIPEBOMB', 2}}
},
{
['MinScore'] = 32, ['Unlocks'] = {{'WEAPON_SMG', 64, 'COMPONENT_AT_SR_SUPP'}}
}
}
18 changes: 15 additions & 3 deletions global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ end
CallbackTable = {}

function Call(svEventName, args, callback)

if type(callback) == "function" then
local cbType = type(callback)
if cbType == "function" or cbType == "table" then
local callbackId = randomString(8)
CallbackTable[callbackId] = callback

Expand Down Expand Up @@ -69,4 +69,16 @@ AddEventHandler("factions:cl_onCallback_AnyParam", function(callbackId, ret1, re
end

CallbackTable[callbackId] = nil
end) RegisterNetEvent("factions:cl_onCallback_AnyParam")
end) RegisterNetEvent("factions:cl_onCallback_AnyParam")

-- For debuging mainly

function ShowNotification(text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(false, false)
end

-- Singleton for Client

Global = {}
Loading

0 comments on commit ab8fe50

Please sign in to comment.