Jump to content

[HELP] Heal request


Recommended Posts

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
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
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 by Galactix
  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...