├── README.md ├── fxmanifest.lua ├── .github └── FUNDING.yml ├── client.lua └── tools.lua /README.md: -------------------------------------------------------------------------------- 1 | # FiveM-Golf 2 | 3 | ![image](https://github.com/alberttheprince/FiveM-Golf/assets/85725579/b28b8b38-a59f-4559-a304-e8e190b68715) 4 | 5 | A simple golfing minigame. 6 | 7 | 8 | An update of Alberto-Golf, which is an update of Koil-Golf. 9 | 10 | **Original:** 11 | 12 | https://github.com/itsKoil/koil-public 13 | 14 | https://forum.cfx.re/t/koil-golf-updated-12-8/57957/ 15 | 16 | **Alberto's Update:** 17 | 18 | https://forum.cfx.re/t/koil-golf-updated-12-8/57957/33 19 | -------------------------------------------------------------------------------- /fxmanifest.lua: -------------------------------------------------------------------------------- 1 | games {'gta5'} 2 | 3 | fx_version 'cerulean' 4 | 5 | description 'A cleaned up version of Alberto Golf, which is an improved version of Koil Golf, by PrinceAlbert.' 6 | version '0.0.1' 7 | 8 | client_script { 9 | '@PolyZone/client.lua', 10 | 'tools.lua', 11 | 'client.lua' 12 | } 13 | 14 | export { 15 | 'trace', 16 | 'endGame', 17 | 'displayHelpText', 18 | 'blipsStartEndCurrentHole', 19 | 'createBall', 20 | 'idleShot', 21 | 'lookingForBall', 22 | 'addBallBlip', 23 | 'addblipGC' 24 | } 25 | 26 | server_scripts {} 27 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: popcornrp 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 12 | polar: # Replace with a single Polar username 13 | buy_me_a_coffee: # Replace with a single Buy Me a Coffee username 14 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 15 | -------------------------------------------------------------------------------- /client.lua: -------------------------------------------------------------------------------- 1 | --# Written by Alberto but based on koil-golf ! 2 | 3 | 4 | -- Is Golf open by manager ? 5 | isGolfOpen = true 6 | 7 | -- Add icon on map 8 | addblipGC() 9 | 10 | -- a player game is running ? 11 | isGameRunning = false 12 | 13 | -- starting hole 14 | golfHole = 1 15 | 16 | -- to store player balf entity 17 | mygolfball = nil 18 | 19 | -- golf club to use 0 for putter, 1 iron, 2 wedge, 3 driver. 20 | golfclub = 1 21 | 22 | clubname = "None" 23 | 24 | power = 0.1 25 | 26 | -- is ball in hole 27 | isBallInHole = false 28 | 29 | -- is ball moving 30 | isBallMoving = false 31 | 32 | -- do players play? Who watches the watchmen? link to ball / free to roam 33 | isPlaying = false 34 | 35 | -- does player want to drop 36 | doingdrop = false 37 | 38 | golfstrokes = 0 39 | totalgolfstrokes = 0 40 | 41 | -- -- golfstate, 2 on ball ready to swing, 1 free roam 42 | -- golfstate = 1 43 | 44 | -- holes data 45 | holes = { 46 | [1] = { ["par"] = 5, ["x"] = -1371.3370361328, ["y"] = 173.09497070313, ["z"] = 57.013027191162, ["x2"] = -1114.2274169922, ["y2"] = 220.8424987793, ["z2"] = 63.8947830200}, 47 | [2] = { ["par"] = 4, ["x"] = -1107.1888427734, ["y"] = 156.581298828, ["z"] = 62.03958129882, ["x2"] = -1322.0944824219, ["y2"] = 158.8779296875, ["z2"] = 56.80027008056}, 48 | [3] = { ["par"] = 3, ["x"] = -1312.1020507813, ["y"] = 125.8329391479, ["z"] = 56.4341888427, ["x2"] = -1237.347412109, ["y2"] = 112.9838562011, ["z2"] = 56.20140075683}, 49 | [4] = { ["par"] = 4, ["x"] = -1216.913208007, ["y"] = 106.9870910644, ["z"] = 57.03926086425, ["x2"] = -1096.6276855469, ["y2"] = 7.780227184295, ["z2"] = 49.73574447631}, 50 | [5] = { ["par"] = 4, ["x"] = -1097.859619140, ["y"] = 66.41466522216, ["z"] = 52.92545700073, ["x2"] = -957.4982910156, ["y2"] = -90.37551879882, ["z2"] = 39.2753639221}, 51 | [6] = { ["par"] = 3, ["x"] = -987.7417602539, ["y"] = -105.0764007568, ["z"] = 39.585887908936, ["x2"] = -1103.506958007, ["y2"] = -115.2364349365, ["z2"] = 40.55868911743}, 52 | [7] = { ["par"] = 4, ["x"] = -1117.0194091797, ["y"] = -103.8586044311, ["z"] = 40.8405838012, ["x2"] = -1290.536499023, ["y2"] = 2.7952194213867, ["z2"] = 49.34057998657}, 53 | [8] = { ["par"] = 5, ["x"] = -1272.251831054, ["y"] = 38.04283142089, ["z"] = 48.72544860839, ["x2"] = -1034.80187988, ["y2"] = -83.16706085205, ["z2"] = 43.0353431701}, 54 | [9] = { ["par"] = 4, ["x"] = -1138.319580078, ["y"] = -0.1342505216598, ["z"] = 47.98218917846, ["x2"] = -1294.685913085, ["y2"] = 83.5762557983, ["z2"] = 53.92817306518} 55 | } 56 | 57 | 58 | -- Ressource main loop 59 | CreateThread(function() 60 | 61 | while true do 62 | -- Refresh tick 63 | Wait(5) 64 | 65 | if isGolfOpen then 66 | -- DEBUG: Ressource running 67 | ----citizen.trace("Ressource is running".."\n") 68 | 69 | -- Marker on ground near hold number 1 to start/stop game 70 | DrawMarker(27,-1369.32, 167.24, 57.31, 0, 0, 0, 0, 0, 0, 1.5, 1.5, 10.3, 0, 519, 0, 105, 5.5, 0, 2, 1, 0, 0, 0) 71 | 72 | -- Player position 73 | local playerLoc = GetEntityCoords(GetPlayerPed(-1)) 74 | 75 | -- Distance betwyn player and marker 76 | local distanceFromMarker = GetDistanceBetweenCoords(-1369.51, 167.4, 58.01, playerLoc.x,playerLoc.y,playerLoc.z, false) 77 | 78 | -- If player going more than 500 from mark and game runing we stop it 79 | if distanceFromMarker > 500 and isGameRunning then 80 | endGame() 81 | end 82 | 83 | -- If player less than 1.5 from mark we ask and listen for start/stop game 84 | if distanceFromMarker < 1.5 then 85 | 86 | if isGameRunning then 87 | -- if game already running 88 | displayHelpText("Press ~g~~INPUT_CONTEXT~~s~ to end your golf game.") 89 | else 90 | displayHelpText("Press ~g~~INPUT_CONTEXT~~s~ to start golfing!") 91 | end 92 | if IsControlJustReleased(1, 38) then 93 | if isGameRunning then 94 | --citizen.trace("End game".."\n") 95 | endGame() 96 | else 97 | --citizen.trace("Run new game".."\n") 98 | isGameRunning = true 99 | newGame() 100 | end 101 | end 102 | end 103 | end -- (isGolfOpen) 104 | end 105 | end) 106 | 107 | function newGame() 108 | -- Game loop: partie en cours 109 | CreateThread(function() 110 | 111 | -- add start and end of the first hole as icons on map 112 | blipsStartEndCurrentHole() 113 | 114 | TriggerEvent("beginGolfHud") 115 | 116 | -- create the first ball 117 | createBall(holes[golfHole]["x"],holes[golfHole]["y"],holes[golfHole]["z"]) 118 | 119 | while isGameRunning == true do 120 | -- Refresh tick 121 | Wait(100) 122 | ----citizen.trace("Game is running".."\n") 123 | 124 | -- if ball is in current hole then we set up the next hole or endGame if current is 9 125 | if isBallInHole then 126 | if golfHole == 9 then 127 | --citizen.trace("Game is finish ball in last hole ! -> End game".."\n") 128 | endGame() 129 | else 130 | golfHole = golfHole + 1 131 | blipsStartEndCurrentHole() 132 | createBall(holes[golfHole]["x"],holes[golfHole]["y"],holes[golfHole]["z"]) 133 | isBallInHole = false 134 | end 135 | else 136 | -- Continue to play actual hole 137 | if isPlaying then 138 | idleShot() 139 | else 140 | lookingForBall() 141 | end 142 | end 143 | end 144 | 145 | return 146 | end) 147 | end 148 | 149 | golfArea = PolyZone:Create({ 150 | vector2(-1340.7989501953, 125.04475402832), 151 | vector2(-1342.5408935547, 142.90570068359), 152 | vector2(-1346.7891845703, 148.30410766602), 153 | vector2(-1358.3530273438, 147.7126159668), 154 | vector2(-1359.3299560547, 173.22514343262), 155 | vector2(-1361.2554931641, 186.72328186035), 156 | vector2(-1341.2399902344, 192.03338623047), 157 | vector2(-1257.6059570312, 198.9454498291), 158 | vector2(-1232.1319580078, 207.94815063477), 159 | vector2(-1220.5051269531, 212.04547119141), 160 | vector2(-1165.9887695312, 224.37823486328), 161 | vector2(-1141.7316894531, 231.72482299805), 162 | vector2(-1121.4205322266, 237.89305114746), 163 | vector2(-1111.814453125, 237.21472167969), 164 | vector2(-1104.8190917969, 224.671875), 165 | vector2(-1090.0133056641, 181.33894348145), 166 | vector2(-1069.1300048828, 143.39642333984), 167 | vector2(-998.81817626953, 29.568370819092), 168 | vector2(-974.93133544922, -9.6275100708008), 169 | vector2(-940.04583740234, -57.441383361816), 170 | vector2(-923.88690185547, -83.41340637207), 171 | vector2(-924.85229492188, -94.125183105469), 172 | vector2(-931.20184326172, -99.439292907715), 173 | vector2(-943.59545898438, -107.31571960449), 174 | vector2(-953.55932617188, -114.29402160645), 175 | vector2(-969.15112304688, -120.986328125), 176 | vector2(-993.65167236328, -128.79643249512), 177 | vector2(-1005.6416625977, -132.22966003418), 178 | vector2(-1021.0614624023, -132.50416564941), 179 | vector2(-1029.7065429688, -133.92350769043), 180 | vector2(-1043.037109375, -142.27110290527), 181 | vector2(-1062.0545654297, -148.04011535645), 182 | vector2(-1076.5524902344, -147.1325378418), 183 | vector2(-1095.5341796875, -137.80737304688), 184 | vector2(-1160.3674316406, -104.27989196777), 185 | vector2(-1212.0971679688, -75.49568939209), 186 | vector2(-1253.3757324219, -52.579933166504), 187 | vector2(-1280.6865234375, -40.263202667236), 188 | vector2(-1295.0959472656, -28.952693939209), 189 | vector2(-1302.4108886719, -17.745761871338), 190 | vector2(-1313.6827392578, 1.5130497217178), 191 | vector2(-1326.3939208984, 18.281391143799) 192 | }, { 193 | name="golfArea", 194 | --minZ = 38.554801940918, 195 | --maxZ = 67.755218505859 196 | }) 197 | 198 | etang1 = PolyZone:Create({ 199 | vector2(-1134.4281005859, 128.00877380371), 200 | vector2(-1132.0672607422, 129.18437194824), 201 | vector2(-1129.4871826172, 130.28790283203), 202 | vector2(-1126.662109375, 128.81904602051), 203 | vector2(-1121.6307373047, 126.82503509521), 204 | vector2(-1118.1671142578, 128.34255981445), 205 | vector2(-1113.091796875, 130.9047088623), 206 | vector2(-1107.564453125, 133.98193359375), 207 | vector2(-1103.7365722656, 136.53012084961), 208 | vector2(-1101.5626220703, 136.35597229004), 209 | vector2(-1098.8894042969, 138.79592895508), 210 | vector2(-1095.6279296875, 139.24281311035), 211 | vector2(-1093.5583496094, 137.46542358398), 212 | vector2(-1089.3717041016, 138.79299926758), 213 | vector2(-1086.9147949219, 139.03764343262), 214 | vector2(-1084.6042480469, 139.61727905273), 215 | vector2(-1081.2492675781, 135.89506530762), 216 | vector2(-1079.2491455078, 135.27127075195), 217 | vector2(-1077.2933349609, 132.19932556152), 218 | vector2(-1079.2985839844, 130.39083862305), 219 | vector2(-1081.8815917969, 130.55606079102), 220 | vector2(-1085.3358154297, 126.3839263916), 221 | vector2(-1086.853515625, 124.49081420898), 222 | vector2(-1088.3382568359, 122.53498840332), 223 | vector2(-1089.6600341797, 117.45861053467), 224 | vector2(-1091.1861572266, 110.32335662842), 225 | vector2(-1088.2283935547, 107.5378112793), 226 | vector2(-1084.1256103516, 105.68126678467), 227 | vector2(-1082.3533935547, 100.60806274414), 228 | vector2(-1084.4224853516, 98.759078979492), 229 | vector2(-1085.7900390625, 99.461280822754), 230 | vector2(-1091.8032226562, 94.265007019043), 231 | vector2(-1093.8503417969, 95.594360351562), 232 | vector2(-1099.2982177734, 95.145477294922), 233 | vector2(-1101.0875244141, 98.559143066406), 234 | vector2(-1104.4921875, 97.077644348145), 235 | vector2(-1108.2651367188, 102.88613891602), 236 | vector2(-1115.9671630859, 102.5909576416), 237 | vector2(-1118.2326660156, 104.42613220215), 238 | vector2(-1120.5920410156, 104.8443069458), 239 | vector2(-1121.1451416016, 107.97873687744), 240 | vector2(-1125.9927978516, 110.62202453613), 241 | vector2(-1126.5711669922, 112.87406921387), 242 | vector2(-1129.2536621094, 114.30466461182), 243 | vector2(-1130.6369628906, 114.57358551025), 244 | vector2(-1134.5255126953, 113.14373779297), 245 | vector2(-1136.5792236328, 114.86979675293), 246 | vector2(-1138.6878662109, 117.15356445312), 247 | vector2(-1136.2521972656, 123.37474060059), 248 | vector2(-1136.8511962891, 127.06150054932), 249 | vector2(-1134.0529785156, 127.12812805176) 250 | }, { 251 | name="etang1", 252 | --minZ = 57.961555480957, 253 | --maxZ = 59.931709289551 254 | }) 255 | 256 | etang2 = PolyZone:Create({ 257 | vector2(-1088.4818115234, 41.795265197754), 258 | vector2(-1078.5300292969, 42.965980529785), 259 | vector2(-1075.2073974609, 46.150661468506), 260 | vector2(-1070.5321044922, 43.826248168945), 261 | vector2(-1066.9249267578, 44.772144317627), 262 | vector2(-1058.4613037109, 43.476718902588), 263 | vector2(-1047.1806640625, 41.016578674316), 264 | vector2(-1039.8121337891, 45.874225616455), 265 | vector2(-1036.8669433594, 48.553405761719), 266 | vector2(-1030.2073974609, 47.187438964844), 267 | vector2(-1030.1745605469, 44.165035247803), 268 | vector2(-1025.5526123047, 37.764610290527), 269 | vector2(-1028.9963378906, 31.91198348999), 270 | vector2(-1033.3443603516, 33.152339935303), 271 | vector2(-1037.0438232422, 29.397964477539), 272 | vector2(-1037.3243408203, 26.630142211914), 273 | vector2(-1041.5235595703, 23.404758453369), 274 | vector2(-1040.6878662109, 20.769901275635), 275 | vector2(-1045.919921875, 15.49206829071), 276 | vector2(-1052.8859863281, 13.299273490906), 277 | vector2(-1056.5681152344, 4.1643619537354), 278 | vector2(-1060.3422851562, 4.0571284294128), 279 | vector2(-1061.2401123047, -0.53958123922348), 280 | vector2(-1066.0467529297, -2.2324686050415), 281 | vector2(-1067.9759521484, -4.8585305213928), 282 | vector2(-1075.7478027344, -1.5850523710251), 283 | vector2(-1079.1309814453, -4.0679569244385), 284 | vector2(-1080.2043457031, -5.9496817588806), 285 | vector2(-1083.1920166016, -14.085180282593), 286 | vector2(-1085.6109619141, -14.978125572205), 287 | vector2(-1087.4467773438, -18.027896881104), 288 | vector2(-1088.2353515625, -19.69056892395), 289 | vector2(-1091.4189453125, -21.516218185425), 290 | vector2(-1094.5286865234, -19.754083633423), 291 | vector2(-1097.9770507812, -20.183317184448), 292 | vector2(-1103.2139892578, -13.334311485291), 293 | vector2(-1102.7376708984, -10.723866462708), 294 | vector2(-1097.4294433594, -5.7387466430664), 295 | vector2(-1088.8294677734, -4.6842436790466), 296 | vector2(-1076.3458251953, 8.7851123809814), 297 | vector2(-1074.6862792969, 13.016589164734), 298 | vector2(-1081.1558837891, 23.260408401489), 299 | vector2(-1083.5269775391, 27.419729232788), 300 | vector2(-1087.5012207031, 28.808660507202), 301 | vector2(-1095.7131347656, 30.862897872925), 302 | vector2(-1093.8795166016, 35.945724487305) 303 | }, { 304 | name="etang2", 305 | --minZ = 49.457775115967, 306 | --maxZ = 50.787307739258 307 | }) 308 | 309 | etang3 = PolyZone:Create({ 310 | vector2(-1173.1820068359, -48.157444000244), 311 | vector2(-1172.3804931641, -54.680221557617), 312 | vector2(-1170.6058349609, -58.35718536377), 313 | vector2(-1166.1499023438, -61.570560455322), 314 | vector2(-1166.4907226562, -72.045204162598), 315 | vector2(-1171.9370117188, -77.781532287598), 316 | vector2(-1176.0206298828, -78.717041015625), 317 | vector2(-1180.9291992188, -75.672073364258), 318 | vector2(-1181.9155273438, -72.392379760742), 319 | vector2(-1183.9104003906, -69.689186096191), 320 | vector2(-1185.8588867188, -66.180084228516), 321 | vector2(-1185.3842773438, -62.21496963501), 322 | vector2(-1186.7886962891, -59.990081787109), 323 | vector2(-1191.4251708984, -61.82649230957), 324 | vector2(-1194.6578369141, -58.379070281982), 325 | vector2(-1197.3286132812, -56.337677001953), 326 | vector2(-1200.953125, -53.705654144287), 327 | vector2(-1203.3422851562, -52.325729370117), 328 | vector2(-1203.7781982422, -49.715316772461), 329 | vector2(-1205.5632324219, -47.617198944092), 330 | vector2(-1207.3010253906, -46.256011962891), 331 | vector2(-1210.6898193359, -45.884754180908), 332 | vector2(-1213.4860839844, -42.192852020264), 333 | vector2(-1217.1348876953, -42.245464324951), 334 | vector2(-1218.3298339844, -40.044422149658), 335 | vector2(-1222.5437011719, -36.827556610107), 336 | vector2(-1225.2727050781, -33.115600585938), 337 | vector2(-1231.7586669922, -31.009090423584), 338 | vector2(-1235.6610107422, -30.567623138428), 339 | vector2(-1238.5727539062, -26.949226379395), 340 | vector2(-1241.4462890625, -23.373443603516), 341 | vector2(-1241.3037109375, -17.470520019531), 342 | vector2(-1243.8333740234, -14.204926490784), 343 | vector2(-1246.2634277344, -10.213208198547), 344 | vector2(-1249.5438232422, -6.2493605613708), 345 | vector2(-1256.2030029297, -4.4095454216003), 346 | vector2(-1257.9655761719, -2.246643781662), 347 | vector2(-1261.8233642578, -0.24623660743237), 348 | vector2(-1264.8671875, 1.7654958963394), 349 | vector2(-1266.2385253906, 5.4950428009033), 350 | vector2(-1267.7186279297, 9.0236196517944), 351 | vector2(-1268.09765625, 11.253690719604), 352 | vector2(-1265.5919189453, 13.782306671143), 353 | vector2(-1262.7059326172, 17.727558135986), 354 | vector2(-1257.8228759766, 16.932100296021), 355 | vector2(-1252.5437011719, 13.166374206543), 356 | vector2(-1247.1131591797, 8.0136518478394), 357 | vector2(-1248.6756591797, 0.80859100818634), 358 | vector2(-1245.9645996094, -3.9010694026947), 359 | vector2(-1243.0593261719, -5.027811050415), 360 | vector2(-1241.8575439453, -7.434398651123), 361 | vector2(-1239.8343505859, -9.5314922332764), 362 | vector2(-1236.5639648438, -11.073376655579), 363 | vector2(-1230.0311279297, -8.7359228134155), 364 | vector2(-1227.6887207031, -8.8415155410767), 365 | vector2(-1217.9870605469, -10.208189964294), 366 | vector2(-1216.7473144531, -14.336300849915), 367 | vector2(-1221.4904785156, -16.417213439941), 368 | vector2(-1221.912109375, -18.444915771484), 369 | vector2(-1220.1774902344, -22.796669006348), 370 | vector2(-1221.1325683594, -25.25625038147), 371 | vector2(-1221.787109375, -27.175374984741), 372 | vector2(-1221.4052734375, -29.732799530029), 373 | vector2(-1218.4735107422, -32.702796936035), 374 | vector2(-1214.9586181641, -34.274166107178), 375 | vector2(-1212.3409423828, -35.583869934082), 376 | vector2(-1208.6354980469, -34.755802154541), 377 | vector2(-1206.0975341797, -36.683197021484), 378 | vector2(-1202.904296875, -37.297466278076), 379 | vector2(-1197.8325195312, -36.173377990723), 380 | vector2(-1195.8072509766, -34.90417098999), 381 | vector2(-1193.7540283203, -35.685253143311), 382 | vector2(-1187.8071289062, -34.247905731201), 383 | vector2(-1185.5510253906, -33.169471740723), 384 | vector2(-1177.5880126953, -35.697582244873), 385 | vector2(-1176.498046875, -34.261936187744), 386 | vector2(-1172.7877197266, -35.197689056396), 387 | vector2(-1170.3687744141, -42.043739318848), 388 | vector2(-1170.0341796875, -44.0569190979) 389 | }, { 390 | name="etang3", 391 | --minZ = 44.569702148438, 392 | --maxZ = 47.893482208252 393 | }) 394 | 395 | -- event listerner pour lancer le menu 396 | RegisterNetEvent('beginGolfHud') 397 | AddEventHandler('beginGolfHud', function() 398 | startGolfHud() 399 | --citizen.trace("HUD started".."\n") 400 | end) 401 | 402 | function startGolfHud() 403 | while isGameRunning do 404 | Wait(0) 405 | -- x, y, width, height 406 | DrawRect(0.115,0.39,0.2,0.45,0,0,0,140) -- game info 407 | if golfhole ~= 0 then 408 | local distance = math.ceil(GetDistanceBetweenCoords(GetEntityCoords(mygolfball), holes[golfHole]["x2"],holes[golfHole]["y2"],holes[golfHole]["z2"], true)) 409 | --drawGolfTxt(0.9193, 1.391, 1.0,1.0,0.4, "~s~" .. golfstrokes .. "~r~ - ~s~" .. totalgolfstrokes .. "~r~ - ~s~" .. clubname .. "~r~ - ~s~" .. distance .. " m", 255, 255, 255, 255) 410 | 411 | 412 | -- x,y ,width,height,scale, text, r,g,b,a 413 | -- game help text 414 | drawGolfTxtFixed(0.025, 0.18, 1.0,1.0,0.4, "How to Play:", 255, 255, 255, 255) 415 | drawGolfTxtFixed(0.025, 0.22, 1.0,1.0,0.3, "Walk up to the ball to begin", 255, 255, 255, 255) 416 | drawGolfTxtFixed(0.025, 0.25, 1.0,1.0,0.3, "Use Y to change clubs", 255, 255, 255, 255) 417 | drawGolfTxtFixed(0.025, 0.28, 1.0,1.0,0.3, "Use A and D to rotate", 255, 255, 255, 255) 418 | drawGolfTxtFixed(0.025, 0.31, 1.0,1.0,0.3, "Hold E to gain power and release to strike", 255, 255, 255, 255) 419 | -- game info text 420 | drawGolfTxtFixed(0.025, 0.38, 1.0,1.0,0.4, "Game Info:", 255, 255, 255, 255) 421 | drawGolfTxtFixed(0.025, 0.42, 1.0,1.0,0.3, "Strokes for current hole: " .. golfstrokes, 255, 255, 255, 255) 422 | drawGolfTxtFixed(0.025, 0.45, 1.0,1.0,0.3, "Distance between ball and hole: " .. distance .. " m", 255, 255, 255, 255) 423 | drawGolfTxtFixed(0.025, 0.48, 1.0,1.0,0.3, "Current hole: " .. golfHole, 255, 255, 255, 255) 424 | drawGolfTxtFixed(0.025, 0.51, 1.0,1.0,0.3, "Total strokes: " .. totalgolfstrokes, 255, 255, 255, 255) 425 | -- golf club text 426 | drawGolfTxtFixed(0.025, 0.56, 1.0,1.0,0.4, "Current club: " .. clubname, 255, 255, 255, 255) 427 | end 428 | end 429 | end 430 | 431 | function drawGolfTxt(x,y ,width,height,scale, text, r,g,b,a) 432 | SetTextFont(2) 433 | SetTextProportional(0) 434 | SetTextScale(scale, scale) 435 | SetTextColour(r, g, b, a) 436 | SetTextDropShadow(0, 0, 0, 0,255) 437 | SetTextEdge(1, 0, 0, 0, 255) 438 | SetTextDropShadow() 439 | SetTextOutline() 440 | SetTextEntry("STRING") 441 | AddTextComponentString(text) 442 | DrawText(x - width/2, y - height/2 + 0.025) 443 | end 444 | 445 | 446 | function drawGolfTxtFixed(x,y ,width,height,scale, text, r,g,b,a) 447 | SetTextFont(0) 448 | SetTextProportional(0) 449 | SetTextScale(scale, scale) 450 | SetTextColour(r, g, b, a) 451 | SetTextDropShadow(0, 0, 0, 0,255) 452 | SetTextEdge(1, 0, 0, 0, 255) 453 | SetTextDropShadow() 454 | SetTextOutline() 455 | SetTextEntry("STRING") 456 | AddTextComponentString(text) 457 | DrawText(x,y) 458 | end 459 | -------------------------------------------------------------------------------- /tools.lua: -------------------------------------------------------------------------------- 1 | 2 | function trace(str) 3 | --Citizen.Trace(str.."\n") 4 | end 5 | 6 | function addblipGC() 7 | gcblip = AddBlipForCoord(-1360.336,160.0437,57.4211) 8 | SetBlipAsFriendly(gcblip, true) 9 | SetBlipSprite(gcblip, 109) 10 | if isGolfOpen then 11 | SetBlipColour(gcblip, 2) 12 | else 13 | SetBlipColour(gcblip, 3) 14 | end 15 | SetBlipAsShortRange(gcblip,true) 16 | BeginTextCommandSetBlipName("STRING"); 17 | AddTextComponentString(tostring("Los Santos Golf Club")) 18 | EndTextCommandSetBlipName(gcblip) 19 | end 20 | 21 | function endGame() 22 | 23 | isGameRunning = false 24 | golfHole = 1 25 | DeleteObject(mygolfball) 26 | mygolfball = nil 27 | golfclub = 1 28 | clubname = "None" 29 | power = 0.1 30 | isBallInHole = false 31 | isBallMoving = false 32 | isPlaying = false 33 | doingdrop = false 34 | golfstrokes = 0 35 | totalgolfstrokes = 0 36 | TriggerEvent('destroyProp') 37 | 38 | _removeStartEndCurrentHole() 39 | _removeBallBlip() 40 | --Citizen.Trace("Golf game ended.".."\n") 41 | end 42 | 43 | function displayHelpText(str) 44 | SetTextComponentFormat("STRING") 45 | AddTextComponentString(str) 46 | DisplayHelpTextFromStringLabel(0, 0, 0, -1) 47 | end 48 | 49 | function blipsStartEndCurrentHole() 50 | --Citizen.Trace("BlipsStartEnd".."\n") 51 | if startblip ~= nil then 52 | --Citizen.Trace("BlipsStartEnd - RemoveBlip".."\n") 53 | RemoveBlip(startblip) 54 | RemoveBlip(endblip) 55 | end 56 | startblip = AddBlipForCoord(holes[golfHole]["x"],holes[golfHole]["y"],holes[golfHole]["z"]) 57 | SetBlipAsFriendly(startblip, true) 58 | SetBlipSprite(startblip, 379) 59 | BeginTextCommandSetBlipName("STRING"); 60 | AddTextComponentString(tostring("Start of Hole")) 61 | EndTextCommandSetBlipName(startblip) 62 | endblip = AddBlipForCoord(holes[golfHole]["x2"],holes[golfHole]["y2"],holes[golfHole]["z2"]) 63 | SetBlipAsFriendly(endblip, true) 64 | SetBlipSprite(endblip, 358) 65 | BeginTextCommandSetBlipName("STRING"); 66 | AddTextComponentString(tostring("End of Hole")) 67 | EndTextCommandSetBlipName(endblip) 68 | end 69 | 70 | function _removeStartEndCurrentHole() 71 | if startblip ~= nil then 72 | --Citizen.Trace("BlipsStartEnd - RemoveBlip".."\n") 73 | RemoveBlip(startblip) 74 | RemoveBlip(endblip) 75 | end 76 | end 77 | 78 | function _removeBallBlip() 79 | if ballBlip ~= nil then 80 | RemoveBlip(ballBlip) 81 | end 82 | end 83 | 84 | function createBall(x,y,z) 85 | 86 | --Citizen.Trace("Creating Ball".."\n") 87 | 88 | if ballBlip ~= nil then 89 | RemoveBlip(ballBlip) 90 | end 91 | 92 | DeleteObject(mygolfball) 93 | mygolfball = CreateObject(GetHashKey("prop_golf_ball"), x, y, z, true, true, false) 94 | 95 | SetEntityRecordsCollisions(mygolfball,true) 96 | SetEntityCollision(mygolfball, true, true) 97 | SetEntityHasGravity(mygolfball, true) 98 | FreezeEntityPosition(mygolfball, true) 99 | local curHeading = GetEntityHeading(GetPlayerPed(-1)) 100 | SetEntityHeading(mygolfball, curHeading) 101 | 102 | addBallBlip() 103 | end 104 | 105 | function addBallBlip() 106 | ballBlip = AddBlipForEntity(mygolfball) 107 | SetBlipAsFriendly(ballBlip, true) 108 | SetBlipSprite(ballBlip, 1) 109 | BeginTextCommandSetBlipName("STRING"); 110 | AddTextComponentString(tostring("Golf ball position")) 111 | EndTextCommandSetBlipName(ballBlip) 112 | end 113 | 114 | function idleShot() 115 | --Citizen.Trace("Idle Shot Enabled".."\n") 116 | power = 0.1 117 | --Citizen.Trace("POWER debut idleshot :"..power.."\n") 118 | --Citizen.Trace("mygolfball debut idleshot :"..mygolfball.."\n") 119 | 120 | local distance = GetDistanceBetweenCoords(GetEntityCoords(mygolfball), holes[golfHole]["x2"],holes[golfHole]["y2"],holes[golfHole]["z2"], true) 121 | if distance >= 200.0 then 122 | golfclub = 3 -- wood 200m-250m 123 | elseif distance >= 150.0 and distance < 200.0 then 124 | golfclub = 1 -- iron 1 140m-180m 125 | elseif distance >= 120.0 and distance < 250.0 then 126 | golfclub = 4 -- iron 3 -- 120m-150m 127 | elseif distance >= 90.0 and distance < 120.0 then 128 | golfclub = 5 -- -- iron 5 -- 70m-120m 129 | elseif distance >= 50.0 and distance < 90.0 then 130 | golfclub = 6 -- iron 7 -- 50m-100m 131 | elseif distance >= 20.0 and distance < 50.0 then 132 | golfclub = 2 -- wedge 50m-80m 133 | else 134 | golfclub = 0 -- else putter 135 | end 136 | 137 | _attachClub() 138 | RequestScriptAudioBank("GOLF_I", 0) 139 | 140 | while isPlaying do 141 | 142 | Wait(0) 143 | 144 | if (IsControlPressed(1, 38)) then 145 | addition = 0.5 146 | 147 | if power > 25 then 148 | addition = addition + 0.1 149 | end 150 | if power > 50 then 151 | addition = addition + 0.2 152 | end 153 | if power > 75 then 154 | addition = addition + 0.3 155 | end 156 | power = power + addition 157 | if power > 100.0 then 158 | power = 1.0 159 | end 160 | end 161 | 162 | 163 | 164 | local box = (power * 2) / 1000 165 | 166 | DrawRect(0.5,0.97,0.2,0.04,0,0,0,140)-- header 167 | if power > 90 then 168 | DrawRect(0.5,0.97,box,0.02,255,22,22,210) -- jauge 169 | else 170 | DrawRect(0.5,0.97,box,0.02,22,235,22,210) -- jauge 171 | end 172 | 173 | --DrawRect(x, y, width, height, r, g, b, a) 174 | 175 | local offsetball = GetOffsetFromEntityInWorldCoords(mygolfball, (power) - (power*2), 0.0, 0.0) 176 | 177 | DrawLine(GetEntityCoords(mygolfball), holes[golfHole]["x2"],holes[golfHole]["y2"],holes[golfHole]["z2"], 222, 111, 111, 0.2) 178 | 179 | DrawMarker(27,holes[golfHole]["x2"],holes[golfHole]["y2"],holes[golfHole]["z2"], 0, 0, 0, 0, 0, 0, 0.5, 0.5, 10.3, 212, 189, 0, 105, 0, 0, 2, 0, 0, 0, 0) 180 | 181 | -- 182 | 183 | if (IsControlJustPressed(1, 246)) then 184 | local newclub = golfclub+1 185 | --Citizen.Trace(golfclub.."\n") 186 | if newclub > 6 then 187 | newclub = 0 188 | end 189 | --Citizen.Trace(golfclub .. " | " .. newclub.."\n") 190 | golfclub = newclub 191 | --Citizen.Trace(golfclub.."\n") 192 | _attachClub() 193 | end 194 | 195 | if (IsControlPressed(1, 34)) then 196 | _rotateShot(true) 197 | end 198 | if (IsControlPressed(1, 9)) then 199 | _rotateShot(false) 200 | end 201 | 202 | if golfclub == 0 then 203 | AttachEntityToEntity(GetPlayerPed(-1), mygolfball, 20, 0.14, -0.62, 0.99, 0.0, 0.0, 0.0, false, false, false, false, 1, true) 204 | elseif golfclub == 3 then 205 | AttachEntityToEntity(GetPlayerPed(-1), mygolfball, 20, 0.3, -0.92, 0.99, 0.0, 0.0, 0.0, false, false, false, false, 1, true) 206 | elseif golfclub == 2 then 207 | AttachEntityToEntity(GetPlayerPed(-1), mygolfball, 20, 0.38, -0.79, 0.94, 0.0, 0.0, 0.0, false, false, false, false, 1, true) 208 | else 209 | AttachEntityToEntity(GetPlayerPed(-1), mygolfball, 20, 0.4, -0.83, 0.94, 0.0, 0.0, 0.0, false, false, false, false, 1, true) 210 | end 211 | if (IsControlJustReleased(1, 38)) then 212 | if golfclub == 0 then 213 | playAnim = puttSwing["puttswinglow"] 214 | else 215 | playAnim = ironSwing["ironswinghigh"] 216 | playGolfAnim(playAnim) 217 | playAnim = ironSwing["ironswinglow"] 218 | playGolfAnim(playAnim) 219 | playAnim = ironSwing["ironswinglow"] 220 | end 221 | 222 | isPlaying = false 223 | inLoop = false 224 | DetachEntity(GetPlayerPed(-1), true, false) 225 | else 226 | if not inLoop then 227 | TriggerEvent("loopStart") 228 | end 229 | end 230 | end 231 | 232 | PlaySoundFromEntity(-1, "GOLF_SWING_FAIRWAY_IRON_LIGHT_MASTER", GetPlayerPed(-1), 0, 0, 0) 233 | 234 | playGolfAnim(playAnim) 235 | swing() 236 | 237 | Wait(3380) 238 | endShot() 239 | 240 | if isBallInGolf == false or isBallInEtang1 == true or isBallInEtang2 == true or isBallInEtang3 == true then 241 | displayHelpText("Your ball is off-limits or in water. Replacing ball with a 1 point penality.") 242 | x,y,z = table.unpack(GetEntityCoords(GetPlayerPed(-1))) 243 | createBall(x,y,z-1) 244 | golfstrokes = golfstrokes + 1 245 | end 246 | end 247 | 248 | function swing() 249 | --Citizen.Trace("Swing Enabled".."\n") 250 | 251 | --Citizen.Trace("POWER DEBUT SWING :"..power.."\n") 252 | if golfclub ~= 0 then 253 | ballCam() 254 | end 255 | if not HasNamedPtfxAssetLoaded("scr_minigamegolf") then 256 | RequestNamedPtfxAsset("scr_minigamegolf") 257 | while not HasNamedPtfxAssetLoaded("scr_minigamegolf") do 258 | Wait(0) 259 | end 260 | end 261 | SetPtfxAssetNextCall("scr_minigamegolf") 262 | StartParticleFxLoopedOnEntity("scr_golf_ball_trail", mygolfball, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, false, false, false) 263 | 264 | local enabledroll = false 265 | 266 | dir = GetEntityHeading(mygolfball) 267 | local x,y = quickmafs(dir) 268 | FreezeEntityPosition(mygolfball, false) 269 | local rollpower = power / 3 270 | 271 | if golfclub == 0 then -- putter 272 | power = power / 3 273 | local check = 5.0 274 | while check < power do 275 | SetEntityVelocity(mygolfball, x*check,y*check,-0.1) 276 | Wait(20) 277 | check = check + 0.3 278 | end 279 | 280 | power = power 281 | while power > 0 do 282 | SetEntityVelocity(mygolfball, x*power,y*power,-0.1) 283 | Wait(20) 284 | power = power - 0.3 285 | end 286 | 287 | elseif golfclub == 1 then -- iron 1 140m-180m 288 | power = power * 1.85 289 | airpower = power / 2.6 290 | enabledroll = true 291 | rollpower = rollpower / 4 292 | elseif golfclub == 3 then -- wood 200m-250m 293 | power = power * 2.0 294 | airpower = power / 2.6 295 | enabledroll = true 296 | rollpower = rollpower / 2 297 | elseif golfclub == 2 then -- wedge -- 50m-80m 298 | power = power * 1.5 299 | airpower = power / 2.1 300 | enabledroll = true 301 | rollpower = rollpower / 4.5 302 | elseif golfclub == 4 then -- iron 3 -- 110m-150m 303 | power = power * 1.8 304 | airpower = power / 2.55 305 | enabledroll = true 306 | rollpower = rollpower / 5 307 | elseif golfclub == 5 then -- iron 5 -- 70m-120m 308 | power = power * 1.75 309 | airpower = power / 2.5 310 | enabledroll = true 311 | rollpower = rollpower / 5.5 312 | elseif golfclub == 6 then -- iron 7 -- 50m-100m 313 | power = power * 1.7 314 | airpower = power / 2.45 315 | enabledroll = true 316 | rollpower = rollpower / 6.0 317 | end 318 | 319 | --Citizen.Trace("POWER APRES COEF :"..power.."\n") 320 | --Citizen.Trace("AIRPOWER :"..airpower.."\n") 321 | --Citizen.Trace("ROLLPOWER :"..rollpower.."\n") 322 | 323 | while power > 0 do 324 | SetEntityVelocity(mygolfball, x*power,y*power,airpower) 325 | Wait(0) 326 | power = power - 1 327 | airpower = airpower - 1 328 | end 329 | 330 | if enabledroll then 331 | while rollpower > 0 do 332 | SetEntityVelocity(mygolfball, x*rollpower,y*rollpower,0.0) 333 | Wait(5) 334 | rollpower = rollpower - 1 335 | end 336 | end 337 | 338 | Wait(2000) 339 | 340 | SetEntityVelocity(mygolfball,0.0,0.0,0.0) 341 | 342 | if golfclub ~= 0 then 343 | ballCamOff() 344 | end 345 | 346 | FreezeEntityPosition(mygolfball, true) 347 | local x,y,z = table.unpack(GetEntityCoords(mygolfball)) 348 | createBall(x,y,z) 349 | --SetEntityCoords(GetPlayerPed(-1),GetEntityCoords(mygolfball)) 350 | 351 | -- CHECKBALL POSITION 352 | local mygolfballCoord = GetEntityCoords(mygolfball) 353 | 354 | isBallInGolf = golfArea:isPointInside(mygolfballCoord) 355 | isBallInEtang1 = etang1:isPointInside(mygolfballCoord) 356 | isBallInEtang2 = etang2:isPointInside(mygolfballCoord) 357 | isBallInEtang3 = etang3:isPointInside(mygolfballCoord) 358 | if isBallInGolf and isBallInEtang1 == false and isBallInEtang2 == false and isBallInEtang3 == false then 359 | displayHelpText("Ball still in area of play and not in water.") 360 | else 361 | displayHelpText("Ball outside area of play or in water.") 362 | end 363 | 364 | end 365 | 366 | function endShot() 367 | --Citizen.Trace("Ending Shot".."\n") 368 | TriggerEvent("attachItem","golfbag01") 369 | inTask = false 370 | golfstrokes = golfstrokes + 1 371 | local ballLoc = GetEntityCoords(mygolfball) 372 | local distance = GetDistanceBetweenCoords(ballLoc.x,ballLoc.y,ballLoc.z, holes[golfHole]["x2"],holes[golfHole]["y2"],holes[golfHole]["z2"], true) 373 | 374 | if distance < 0.5 then 375 | TriggerEvent("customNotification","You got the ball within range!") 376 | totalgolfstrokes = golfstrokes + totalgolfstrokes 377 | golfstrokes = 0 378 | isBallInHole = true 379 | end 380 | 381 | --Citizen.Trace("Ball seemed to have landed on: " .. GetCollisionNormalOfLastHitForEntity(mygolfball) .."\n") 382 | end 383 | 384 | function dropShot() 385 | --Citizen.Trace("Droping Shot".."\n") 386 | doingdrop = true 387 | while doingdrop do 388 | 389 | Wait(0) 390 | local distance = GetDistanceBetweenCoords(GetEntityCoords(mygolfball), GetEntityCoords(GetPlayerPed(-1)), true) 391 | local distanceHole = GetDistanceBetweenCoords(holes[golfHole]["x2"],holes[golfHole]["y2"],holes[golfHole]["z2"], GetEntityCoords(GetPlayerPed(-1)), true) 392 | if distance < 50.0 and distanceHole > 50.0 then 393 | DisplayHelpText("Press ~g~E~s~ to drop here.") 394 | if ( IsControlJustReleased(1, 38) ) then 395 | doingdrop = false 396 | x,y,z = table.unpack(GetEntityCoords(GetPlayerPed(-1))) 397 | createBall(x,y,z-1) 398 | golfstrokes = golfstrokes + 1 399 | end 400 | else 401 | DisplayHelpText("Press ~g~E~s~ to drop - ~r~ too far from ball or to close to hole.") 402 | end 403 | end 404 | end 405 | 406 | 407 | function quickmafs(dir) 408 | local x = 0.0 409 | local y = 0.0 410 | local dir = dir 411 | if dir >= 0.0 and dir <= 90.0 then 412 | local factor = (dir/9.2) / 10 413 | x = -1.0 + factor 414 | y = 0.0 - factor 415 | end 416 | 417 | if dir > 90.0 and dir <= 180.0 then 418 | dirp = dir - 90.0 419 | local factor = (dirp/9.2) / 10 420 | x = 0.0 + factor 421 | y = -1.0 + factor 422 | end 423 | 424 | if dir > 180.0 and dir <= 270.0 then 425 | dirp = dir - 180.0 426 | local factor = (dirp/9.2) / 10 427 | x = 1.0 - factor 428 | y = 0.0 + factor 429 | end 430 | 431 | if dir > 270.0 and dir <= 360.0 then 432 | dirp = dir - 270.0 433 | local factor = (dirp/9.2) / 10 434 | x = 0.0 - factor 435 | y = 1.0 - factor 436 | end 437 | return x,y 438 | end 439 | 440 | function _attachClub() 441 | 442 | if golfclub == 3 then 443 | TriggerEvent("attachItem","golfdriver01") 444 | clubname = "Wood" 445 | elseif golfclub == 2 then 446 | TriggerEvent("attachItem","golfwedge01") 447 | clubname = "Wedge" 448 | elseif golfclub == 1 then 449 | TriggerEvent("attachItem","golfiron01") 450 | clubname = "1 Iron" 451 | elseif golfclub == 4 then 452 | TriggerEvent("attachItem","golfiron03") 453 | clubname = "3 Iron" 454 | elseif golfclub == 5 then 455 | TriggerEvent("attachItem","golfiron05") 456 | clubname = "5 Iron" 457 | elseif golfclub == 6 then 458 | TriggerEvent("attachItem","golfiron07") 459 | clubname = "7 Iron" 460 | else 461 | TriggerEvent("attachItem","golfputter01") 462 | clubname = "Putter" 463 | end 464 | end 465 | 466 | function _rotateShot(moveType) 467 | local curHeading = GetEntityHeading(mygolfball) 468 | if curHeading >= 360.0 then 469 | curHeading = 0.0 470 | end 471 | if moveType then 472 | SetEntityHeading(mygolfball, curHeading-0.7) 473 | else 474 | SetEntityHeading(mygolfball, curHeading+0.7) 475 | end 476 | end 477 | 478 | RegisterNetEvent('customNotification') 479 | AddEventHandler('customNotification', function(response) 480 | TriggerEvent('chatMessage', 'GOLF: ', { 0, 11, 0 }, response) 481 | end) 482 | 483 | RegisterNetEvent('destroyProp') 484 | AddEventHandler('destroyProp', function() 485 | removeAttachedProp() 486 | end) 487 | 488 | RegisterNetEvent('attachProp') 489 | AddEventHandler('attachProp', function(attachModelSent,boneNumberSent,x,y,z,xR,yR,zR) 490 | removeAttachedProp() 491 | attachModel = GetHashKey(attachModelSent) 492 | boneNumber = boneNumberSent 493 | SetCurrentPedWeapon(GetPlayerPed(-1), 0xA2719263) 494 | local bone = GetPedBoneIndex(GetPlayerPed(-1), boneNumberSent) 495 | --local x,y,z = table.unpack(GetEntityCoords(GetPlayerPed(-1), true)) 496 | RequestModel(attachModel) 497 | while not HasModelLoaded(attachModel) do 498 | Wait(100) 499 | end 500 | attachedProp = CreateObject(attachModel, 1.0, 1.0, 1.0, 1, 1, 0) 501 | AttachEntityToEntity(attachedProp, GetPlayerPed(-1), bone, x, y, z, xR, yR, zR, 1, 1, 0, 0, 2, 1) 502 | end) 503 | 504 | attachPropList = { 505 | 506 | ["golfbag01"] = { 507 | ["model"] = "prop_golf_bag_01", ["bone"] = 24816, ["x"] = 0.12,["y"] = -0.3,["z"] = 0.0,["xR"] = -75.0,["yR"] = 190.0, ["zR"] = 92.0 508 | }, 509 | 510 | ["golfputter01"] = { 511 | ["model"] = "prop_golf_putter_01", ["bone"] = 57005, ["x"] = 0.0,["y"] = -0.05,["z"] = 0.0,["xR"] = 90.0,["yR"] = -118.0, ["zR"] = 44.0 512 | }, 513 | 514 | ["golfiron01"] = { 515 | ["model"] = "prop_golf_iron_01", ["bone"] = 57005, ["x"] = 0.125,["y"] = 0.04,["z"] = 0.0,["xR"] = 90.0,["yR"] = -118.0, ["zR"] = 44.0 516 | }, 517 | ["golfiron03"] = { 518 | ["model"] = "prop_golf_iron_01", ["bone"] = 57005, ["x"] = 0.126,["y"] = 0.041,["z"] = 0.0,["xR"] = 90.0,["yR"] = -118.0, ["zR"] = 44.0 519 | }, 520 | ["golfiron05"] = { 521 | ["model"] = "prop_golf_iron_01", ["bone"] = 57005, ["x"] = 0.127,["y"] = 0.042,["z"] = 0.0,["xR"] = 90.0,["yR"] = -118.0, ["zR"] = 44.0 522 | }, 523 | ["golfiron07"] = { 524 | ["model"] = "prop_golf_iron_01", ["bone"] = 57005, ["x"] = 0.128,["y"] = 0.043,["z"] = 0.0,["xR"] = 90.0,["yR"] = -118.0, ["zR"] = 44.0 525 | }, 526 | ["golfwedge01"] = { 527 | ["model"] = "prop_golf_pitcher_01", ["bone"] = 57005, ["x"] = 0.17,["y"] = 0.04,["z"] = 0.0,["xR"] = 90.0,["yR"] = -118.0, ["zR"] = 44.0 528 | }, 529 | 530 | ["golfdriver01"] = { 531 | ["model"] = "prop_golf_driver", ["bone"] = 57005, ["x"] = 0.14,["y"] = 0.00,["z"] = 0.0,["xR"] = 160.0,["yR"] = -60.0, ["zR"] = 10.0 532 | } 533 | 534 | } 535 | 536 | RegisterNetEvent('attachItem') 537 | AddEventHandler('attachItem', function(item) 538 | TriggerEvent("attachProp",attachPropList[item]["model"], attachPropList[item]["bone"], attachPropList[item]["x"], attachPropList[item]["y"], attachPropList[item]["z"], attachPropList[item]["xR"], attachPropList[item]["yR"], attachPropList[item]["zR"]) 539 | end) 540 | 541 | function playGolfAnim(anim) 542 | --ClearPedSecondaryTask(GetPlayerPed(-1)) 543 | loadAnimDict( "mini@golf" ) 544 | if IsEntityPlayingAnim(lPed, "mini@golf", anim, 3) then 545 | 546 | else 547 | length = GetAnimDuration("mini@golf", anim) 548 | TaskPlayAnim( GetPlayerPed(-1), "mini@golf", anim, 1.0, -1.0, length, 0, 1, 0, 0, 0) 549 | Wait(length) 550 | end 551 | -- ClearPedSecondaryTask(GetPlayerPed(-1)) 552 | end 553 | 554 | function playAudio(num) 555 | RequestScriptAudioBank("GOLF_I", 0) 556 | PlaySoundFromEntity(-1, sounds[num], GetPlayerPed(-1), 0, 0, 0) 557 | end 558 | 559 | sounds = { 560 | [1] = "GOLF_SWING_GRASS_LIGHT_MASTER", 561 | [2] = "GOLF_SWING_GRASS_PERFECT_MASTER", 562 | [3] = "GOLF_SWING_GRASS_MASTER", 563 | [4] = "GOLF_SWING_TEE_LIGHT_MASTER", 564 | [5] = "GOLF_SWING_TEE_PERFECT_MASTER", 565 | [6] = "GOLF_SWING_TEE_MASTER", 566 | [7] = "GOLF_SWING_TEE_IRON_LIGHT_MASTER", 567 | [8] = "GOLF_SWING_TEE_IRON_PERFECT_MASTER", 568 | [9] = "GOLF_SWING_TEE_IRON_MASTER", 569 | [10] = "GOLF_SWING_FAIRWAY_IRON_LIGHT_MASTER", 570 | [11] = "GOLF_SWING_FAIRWAY_IRON_PERFECT_MASTER", 571 | [12] = "GOLF_SWING_FAIRWAY_IRON_MASTER", 572 | [13] = "GOLF_SWING_ROUGH_IRON_LIGHT_MASTER", 573 | [14] = "GOLF_SWING_ROUGH_IRON_PERFECT_MASTER", 574 | [15] = "GOLF_SWING_ROUGH_IRON_MASTER", 575 | [16] = "GOLF_SWING_SAND_IRON_LIGHT_MASTER", 576 | [17] = "GOLF_SWING_SAND_IRON_PERFECT_MASTER", 577 | [18] = "GOLF_SWING_SAND_IRON_MASTER", 578 | [19] = "GOLF_SWING_CHIP_LIGHT_MASTER", 579 | [20] = "GOLF_SWING_CHIP_PERFECT_MASTER", 580 | [21] = "GOLF_SWING_CHIP_MASTER", 581 | [22] = "GOLF_SWING_CHIP_GRASS_LIGHT_MASTER", 582 | [23] = "GOLF_SWING_CHIP_GRASS_MASTER", 583 | [24] = "GOLF_SWING_CHIP_SAND_LIGHT_MASTER", 584 | [25] = "GOLF_SWING_CHIP_SAND_PERFECT_MASTER", 585 | [26] = "GOLF_SWING_CHIP_SAND_MASTER", 586 | [27] = "GOLF_SWING_PUTT_MASTER", 587 | [28] = "GOLF_FORWARD_SWING_HARD_MASTER", 588 | [29] = "GOLF_BACK_SWING_HARD_MASTER" 589 | } 590 | 591 | function lookingForBall() 592 | ----Citizen.Trace("Looking for Ball".."\n") 593 | Wait(0) 594 | if GetVehiclePedIsIn(GetPlayerPed(-1), false) == 0 then 595 | local ballLoc = GetEntityCoords(mygolfball) 596 | local playerLoc = GetEntityCoords(GetPlayerPed(-1)) 597 | local distance = GetDistanceBetweenCoords(ballLoc.x,ballLoc.y,ballLoc.z, playerLoc.x,playerLoc.y,playerLoc.z, true) 598 | -- if distance < 50.0 then 599 | -- DisplayHelpText("Move to your ball, press ~g~E~s~ to ball drop if you are stuck.") 600 | -- if ( IsControlJustReleased(1, 38) ) then 601 | -- dropShot() 602 | -- end 603 | -- end 604 | 605 | if (distance < 5.0) and not doingdrop then 606 | isPlaying = true 607 | --Citizen.Trace("Close to the Ball".."\n") 608 | end 609 | end 610 | end 611 | 612 | function removeAttachedProp() 613 | DeleteEntity(attachedProp) 614 | attachedProp = 0 615 | ClearPedTasks(PlayerPedId()) 616 | end 617 | 618 | function loadAnimDict( dict ) 619 | while ( not HasAnimDictLoaded( dict ) ) do 620 | RequestAnimDict( dict ) 621 | Wait( 5 ) 622 | end 623 | end 624 | 625 | function ballCam() 626 | ballcam = CreateCam("DEFAULT_SCRIPTED_CAMERA", true) 627 | --AttachCamToEntity(ballcam, mygolfball, -2.0,0.0,-2.0, false) 628 | SetCamFov(ballcam, 90.0) 629 | RenderScriptCams(true, true, 3, 1, 0) 630 | 631 | TriggerEvent("camFollowBall") 632 | end 633 | 634 | function ballCamOff() 635 | RenderScriptCams(false, false, 0, 1, 0) 636 | DestroyCam(ballcam, false) 637 | end 638 | 639 | RegisterNetEvent('camFollowBall') 640 | AddEventHandler('camFollowBall', function() 641 | local timer = 20000 642 | while timer > 0 do 643 | Wait(5) 644 | x,y,z = table.unpack(GetEntityCoords(mygolfball)) 645 | SetCamCoord(ballcam, x,y-10,z+9) 646 | PointCamAtEntity(ballcam, mygolfball, 0.0, 0.0, 0.0, true) 647 | timer = timer - 1 648 | end 649 | end) 650 | 651 | ironSwing = { 652 | ["ironshufflehigh"] = "iron_shuffle_high", 653 | ["ironshufflelow"] = "iron_shuffle_low", 654 | ["ironshuffle"] = "iron_shuffle", 655 | ["ironswinghigh"] = "iron_swing_action_high", 656 | ["ironswinglow"] = "iron_swing_action_low", 657 | ["ironidlehigh"] = "iron_swing_idle_high", 658 | ["ironidlelow"] = "iron_swing_idle_low", 659 | ["ironidle"] = "iron_shuffle", 660 | ["ironswingintro"] = "iron_swing_intro_high" 661 | } 662 | 663 | 664 | puttSwing = { 665 | ["puttshufflelow"] = "iron_shuffle_low", 666 | ["puttshuffle"] = "iron_shuffle", 667 | ["puttswinglow"] = "putt_action_low", 668 | ["puttidle"] = "putt_idle_low", 669 | ["puttintro"] = "putt_intro_low", 670 | ["puttintro"] = "putt_outro" 671 | } 672 | 673 | 674 | RegisterNetEvent('loopStart') 675 | AddEventHandler('loopStart', function() 676 | inLoop = true 677 | --Citizen.Trace("Idle Enabled".."\n") 678 | while inLoop do 679 | Wait(0) 680 | idleLoop() 681 | end 682 | end) 683 | 684 | function idleLoop() 685 | if golfclub == 0 then 686 | playAnim = puttSwing["puttidle"] 687 | else 688 | if (IsControlPressed(1, 38)) then 689 | playAnim = ironSwing["ironidlehigh"] 690 | else 691 | playAnim = ironSwing["ironidle"] 692 | end 693 | end 694 | playGolfAnim(playAnim) 695 | Wait(1200) 696 | end 697 | --------------------------------------------------------------------------------