Galactix Posted July 9, 2018 Share 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? Link to comment
Moderators IIYAMA Posted July 9, 2018 Moderators Share 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. Link to comment
Galactix Posted July 9, 2018 Author Share 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 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