thund3rbird23 Posted September 17, 2019 Share Posted September 17, 2019 Why can't find the player? --- client --- registerEvent("healSuccess", root, function(player) triggerServerEvent("s_medicS:healPlayer", player, player) end) --- server --- registerEvent("s_medicS:healPlayer", root, function(targetPlayer) healPlayer(targetPlayer) end) healPlayer function: function healPlayer(playerElement) if isElement(playerElement) then setElementHealth(playerElement, 100) setElementData(playerElement, "isPlayerDeath", false) setElementData(playerElement, "bulletDamages", false) setElementData(playerElement, "bloodLevel", 100) setElementData(playerElement, "deathReason", false) setElementData(playerElement, "customDeath", false) end end Link to comment
Furzy Posted September 17, 2019 Share Posted September 17, 2019 (edited) what is this ''registerEvent'' ?' change player to source Edited September 17, 2019 by Furzy Link to comment
thund3rbird23 Posted September 17, 2019 Author Share Posted September 17, 2019 9 minutes ago, Furzy said: what is this ''registerEvent'' ?' change player to source I want to heal the clicked element (player) not myself. Link to comment
thund3rbird23 Posted September 17, 2019 Author Share Posted September 17, 2019 The "registerEvent" is: function registerEvent(event, element, xfunction) addEvent(event, true) addEventHandler(event, element, xfunction) end Link to comment
Furzy Posted September 18, 2019 Share Posted September 18, 2019 6 hours ago, thund3rbird23 said: Why can't find the player? --- client --- registerEvent("healSuccess", root, function(player) triggerServerEvent("s_medicS:healPlayer", player, player) end) --- server --- registerEvent("s_medicS:healPlayer", root, function(targetPlayer) healPlayer(targetPlayer) end) healPlayer function: function healPlayer(playerElement) if isElement(playerElement) then setElementHealth(playerElement, 100) setElementData(playerElement, "isPlayerDeath", false) setElementData(playerElement, "bulletDamages", false) setElementData(playerElement, "bloodLevel", 100) setElementData(playerElement, "deathReason", false) setElementData(playerElement, "customDeath", false) end end if is targetPlayer then u should use that, no? Link to comment
thund3rbird23 Posted September 18, 2019 Author Share Posted September 18, 2019 7 hours ago, Furzy said: if is targetPlayer then u should use that, no? No. I'm triggering the function from another client.Lua: triggerEvent("s_medicC:playerHeal", sourcePlayer, sourcePlayer) That's triggering this: addEvent("s_medicC:playerHeal", true) addEventHandler("s_medicC:playerHeal", getRootElement(), function (sourcePlayer) if sourcePlayer then if not isPedDead(sourcePlayer) then exports.s_minigames:startMinigame("balance", "healSuccess", "healFailed", 1, 10000) else outputChatBox("The player is dead.") end end end) So if the player is not dead, then start's a minigame. If the minigame is success then I triggering this server event: registerEvent("healSuccess", root, function(sourcePlayer) triggerServerEvent("s_medicS:healPlayer", sourcePlayer, sourcePlayer) -- already tried thePlayer, targetPlayer, player, sourcePlayer none of them working end) Link to comment
Moderators IIYAMA Posted September 18, 2019 Moderators Share Posted September 18, 2019 2 hours ago, thund3rbird23 said: So if the player is not dead, then start's a minigame. You go from your code. To the Minigame code And back to Your code But currently your target player, is not passed in to the minigame. See: exports.s_minigames:startMinigame("balance", "healSuccess", "healFailed", 1, 10000) There is no sourcePlayer included in to the export. Which means it is not available there and also not available to where you want to re-use that specific player. So what you need to figure out is the syntax of this export function and if it allows you to add your own data to it. If not, then you need to modify it, so that it does: Yes We Can. Link to comment
thund3rbird23 Posted September 18, 2019 Author Share Posted September 18, 2019 7 minutes ago, IIYAMA said: You go from your code. To the Minigame code And back to Your code But currently your target player, is not passed in to the minigame. See: exports.s_minigames:startMinigame("balance", "healSuccess", "healFailed", 1, 10000) There is no sourcePlayer included in to the export. Which means it is not available there and also not available to where you want to re-use that specific player. So what you need to figure out is the syntax of this export function and if it allows you to add your own data to it. If not, then you need to modify it, so that it does: Yes We Can. Okay, so the minigame function not contains the target player. function startMinigame(gameType, successEvent, failEvent, ...) stopMinigame() local args = {...} minigameData = {} if gameType == "buttons" then minigameData.buttons = {} minigameData.spawnedButtons = 0 minigameData.renderTarget = dxCreateRenderTarget(622, 55, true) minigameData.RobotoFont = dxCreateFont("files/Roboto.ttf", 12, false, "antialiased") minigameData.speed = args[1] or 0.15 minigameData.endSpeed = (args[2] or 0.2) - minigameData.speed minigameData.density = args[3] or 105 minigameData.maxButtonNum = args[4] or 75 minigameData.interpolateSpeedSet = false minigameData.currentBtn = false minigameData.btnInKey = false minigameData.failCount = 0 minigameData.successCount = 0 minigameData.lastRing = false minigameData.spawnNextButtonTimer = setTimer(spawnNextButton, 2000, 1) elseif gameType == "balance" then minigameData.difficulty = args[1] or 1 minigameData.accelerationMultipler = 0.5 minigameData.startGame = getTickCount() + 1000 minigameData.direction = false minigameData.lastKey = false minigameData.currentX = 10 minigameData.acceleration = 0.3 minigameData.endGameTime = args[2] or 10000 if math.random(10) <= 5 then minigameData.currentX = minigameData.currentX * -1 minigameData.acceleration = minigameData.acceleration * -1 end end if successEvent then minigameData.successEvent = successEvent end if failEvent then minigameData.failEvent = failEvent end minigameState = gameType end Example: startMinigame("balance", "successPlayerHelpup", "failedPlayerHelpup", 1, 10000) So, how can I add the targer player arg? Link to comment
Moderators IIYAMA Posted September 18, 2019 Moderators Share Posted September 18, 2019 (edited) 1 hour ago, thund3rbird23 said: So, how can I add the targer player arg? This is a bit complex. Note: ... = leftover parameter that doesn't have variables to store in. Doesn't matter how much arguments you pass in to the function. function functionName (parameter1, parameter2) end functionName(argument1, argument2) -- calling the function There are the first 3 parameters:(line 1) (gameType, successEvent, failEvent, ...) This table(arguments) will collect all leftover parameters: (line 4) local args = {...} After: gameType, successEvent, failEvent From those leftover parameters, until the 4e are used for something. (line 17) minigameData.maxButtonNum = args[4] or 75 If we want to be able to save everything after parameter 4. We can use the select function. print(select(5,"arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9","arg10")) Run this code here, to see how it works: https://www.Lua.org/cgi-bin/demo So what you need to do, is modifying it, so that it saves data in the minigameData. The function select, will select from a specific index (5) it's item and all items that come after that. minigameData.customData = {select(5, ...)} Add it for example on line 10. In your code: startMinigame("balance", "successPlayerHelpup", "failedPlayerHelpup", 1, 10000, nil, nil, playerSource, "you can add here something else", "etc...") Arguments 1. "balance", 2. "successPlayerHelpup", 3: "failedPlayerHelpup" ... 4 | 1: 1 5 | 2: 10000 6 | 3: nil 7 | 4: nil 8 | 5: playerSource < saving from here. 9 | 6: more? The thing left to do, is sending it with the triggerClientEvent. But that code is not visible for me. Edited September 18, 2019 by IIYAMA Link to comment
thund3rbird23 Posted September 18, 2019 Author Share Posted September 18, 2019 17 minutes ago, IIYAMA said: The thing left to do, is sending it with the triggerClientEvent. But that code is not visible for me. What do you mean sending it with the triggerClientEvent? everything in client side. Except the s_medicS:healPlayer function function healPlayer(playerElement) if isElement(playerElement) then setElementHealth(playerElement, 100) setElementData(playerElement, "isPlayerDeath", false) setElementData(playerElement, "bulletDamages", false) setElementData(playerElement, "bloodLevel", 100) setElementData(playerElement, "deathReason", false) setElementData(playerElement, "customDeath", false) end end Link to comment
Moderators IIYAMA Posted September 18, 2019 Moderators Share Posted September 18, 2019 (edited) 15 minutes ago, thund3rbird23 said: What do you mean sending it with the triggerClientEvent? everything in client side. Except the s_medicS:healPlayer function Correction. Trigger the event on clientside. This successEvent. minigameData.successEvent = successEvent Which is not triggering anything in the code you posted. Edited September 18, 2019 by IIYAMA Link to comment
thund3rbird23 Posted September 18, 2019 Author Share Posted September 18, 2019 12 minutes ago, IIYAMA said: Correction. Trigger the event on clientside. This successEvent. minigameData.successEvent = successEvent Which is not triggering anything in the code you posted. if args[1] == "success" then if minigameData.successEvent then triggerEvent(minigameData.successEvent, localPlayer) end else if minigameData.failEvent then triggerEvent(minigameData.failEvent, localPlayer) end end Maybe that? Link to comment
Moderators IIYAMA Posted September 18, 2019 Moderators Share Posted September 18, 2019 (edited) 8 minutes ago, thund3rbird23 said: Maybe that? Yup. if args[1] == "success" then if minigameData.successEvent then triggerEvent(minigameData.successEvent, localPlayer, unpack(minigameData.customData)) end else if minigameData.failEvent then triggerEvent(minigameData.failEvent, localPlayer, unpack(minigameData.customData)) end end From saving minigameData.customData = {select(5, ...)} to loading + unpacking as arguments. unpack(minigameData.customData) Edited September 18, 2019 by IIYAMA 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now