Galactix Posted July 9, 2018 Posted July 9, 2018 Hello, I made a script that makes player able to make a request to heal others but I couldn't get my script to work properly. function findPlayer( namepart ) local player = getPlayerFromName( namepart ) if player then return player end for _,player in pairs( getElementsByType 'player' ) do if string.find( string.gsub( getPlayerName( player ):lower( ),"#%x%x%x%x%x%x", "" ), namepart:lower( ), 1, true ) then return player end end return false end addCommandHandler( 'heal', function( source,_,player ) local find = findPlayer( player ) if find then setElementData(find,"healrequest", "pending") outputChatBox("The doctor is willing to heal you. Do you accept?", find) else outputChatBox("Player not found!", source, 255, 0, 0) end end) function acceptHeal() local requestStatus = getElementData(source, "healrequest") if (requestStatus == "pending") then setElementData(source,"healrequest", "unpending") setElementHealth(source, 100) outputChatBox("You have been healed by the doctor.", player) else outputChatBox("You have no pending request.", player) end end addCommandHandler("aheal", acceptHeal) the part with if requestStatus doesn't work, it just outputs all the time that the player has no pending request. How could I fix that and also make players unable to heal themselves? If I helped you, make sure you click the reaction button on the right to support me! It will grant me more visibility and will help me to help others!If you have any kind of request or subject you would like to discuss about with me, don't hesitate to send me a private message about it!
Moderators IIYAMA Posted July 9, 2018 Moderators Posted July 9, 2018 function acceptHeal() local requestStatus = getElementData(player, "healrequest") if (requestStatus == "pending") then setElementData(player,"healrequest", nil) -- delete it! setElementHealth(player, 100) outputChatBox("You have been healed by the doctor.", player) else outputChatBox("You have no pending request.", player) end end addCommandHandler("aheal", acceptHeal) Wrong named variables. addCommandHandler doesn't have the pre-defined source variable. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Galactix Posted July 9, 2018 Author Posted July 9, 2018 (edited) 16 minutes ago, IIYAMA said: function acceptHeal() local requestStatus = getElementData(player, "healrequest") if (requestStatus == "pending") then setElementData(player,"healrequest", nil) -- delete it! setElementHealth(player, 100) outputChatBox("You have been healed by the doctor.", player) else outputChatBox("You have no pending request.", player) end end addCommandHandler("aheal", acceptHeal) Wrong named variables. addCommandHandler doesn't have the pre-defined source variable. Actually I still get the "no pending request" thing, it says bad argument at getElementData, element expected, got nil @IIYAMA Edited July 9, 2018 by Galactix 1 If I helped you, make sure you click the reaction button on the right to support me! It will grant me more visibility and will help me to help others!If you have any kind of request or subject you would like to discuss about with me, don't hesitate to send me a private message about it!
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