Jump to content

sethp to me


TroyBoy

Recommended Posts

i have that script that if i write sethp and a playername and hp its set the player i write the hp i want but i want that if i will not write a player name it will set hp to me here the command:

addCommandHandler( "setphp", 
    function( player,_,name ) 
        local theHealth = tonumber(theHealth) 
        local playerTeam = getPlayerTeam ( player ) 
        if playerTeam then 
            local name = getTeamName ( playerTeam ) 
            if name == "Owner" or name == "Admin" then 
            local find = findPlayer( name ) 
            if not find then 
                outputChatBox ( "No player with that name." ) 
            else 
                 if (theHealth) then 
                setElementHealth( find, theHealth ) 
        end 
    end 
  end 
  end 
 end 
) 

please help me

Link to comment

Server

addCommandHandler( "setphp", 
    function( player,_,thePlayer,theHealth ) 
        if thePlayer and theHealth then 
            local theHealth = tonumber( theHealth ) 
            local playerTeam = getPlayerTeam ( player ) 
            if playerTeam then 
                local name = getTeamName ( playerTeam ) 
                if name == "Owner" or name == "Admin" then 
                    local find = findPlayer( thePlayer ) 
                    if not find then 
                        find = player 
                    end 
                    if theHealth then 
                        setElementHealth( find, theHealth ) 
                    end 
                end  
            end 
        else 
            outputChatBox( '/setphp [player name][amount]',player,255,0,0 ) 
        end  
    end 
) 

So if player not found then set health you.

Link to comment
function isNumber( value ) 
    if type( value ) == 'string' then 
        if tonumber( value ) then 
            return true 
        end 
        return false 
    end 
    return false 
end 
  
addCommandHandler( "setphp", 
    function( player,_,arg1,arg2 ) 
        local playerTeam = getPlayerTeam ( player ) 
        if playerTeam then 
            local name = getTeamName ( playerTeam ) 
            if name == "Owner" or name == "Admin" then 
                local health,find 
                if isNumber( arg1 ) and not arg2 then 
                    health = tonumber( arg1 ) 
                    find = player 
                elseif arg1 and isNumber( arg2 ) then 
                    health = tonumber( arg2 ) 
                    local finded = findPlayer( arg1 ) 
                    if finded then 
                        find = finded 
                    else 
                        find = false 
                    end 
                end 
                if find then 
                    setElementHealth( find, health ) 
                else 
                    outputChatBox( 'Player not found use: /setphp [amount] or /setphp [player name][amount]',player,255,0,0 ) 
                end  
            end  
        end 
    end 
) 

Updated.

Link to comment

Server

function isNumber( value ) 
    if type( value ) == 'string' then 
        if value:find( '^[0-9]' ) then 
            return true 
        end 
        return false 
    end 
    return false 
end 
  
function findPlayer(namepart) 
    local player = getPlayerFromName(namepart) 
    if player then 
        return player 
    end 
    for _,player in ipairs(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( "setphp", 
    function( player,_,arg1,arg2 ) 
        local playerTeam = getPlayerTeam ( player ) 
        if playerTeam then 
            local name = getTeamName ( playerTeam ) 
            if name == "Owner" or name == "Admin" then 
                local health,find 
                if isNumber( arg1 ) and not arg2 then 
                    health = tonumber( arg1 ) 
                    find = player 
                elseif arg1 and isNumber( arg2 ) then 
                    health = tonumber( arg2 ) 
                    local finded = findPlayer( arg1 ) 
                    if finded then 
                        find = finded 
                    else 
                        find = false 
                    end 
                end 
                if find then 
                    setElementHealth( find, health ) 
                else 
                    outputChatBox( 'Player not found use: /setphp [amount] or /setphp [player name][amount]',player,255,0,0 ) 
                end  
            end  
        end 
    end 
) 

Full code.

Tested.

cmd /setphp

Link to comment

i have problem with this command its not set my position z +5:

addCommandHandler( "flip", 
    function ( player,vehicle ) 
    local playerTeam = getPlayerTeam ( player ) 
        if playerTeam then 
            local name = getTeamName ( playerTeam ) 
            if name == "Owner" or name == "Admin" then 
            local x,y,z = getElementPosition( player ) 
                    setElementPosition ( vehicle, x, y, z + 5 ) 
                    end 
                end 
            end 
          ) 

Edited by Guest
Link to comment
addCommandHandler( "flip", 
    function ( player, cmd ) 
    local playerTeam = getPlayerTeam ( player ) 
    local veh = getPedOccupiedVehicle(player) 
        if playerTeam then 
            local name = getTeamName ( playerTeam ) 
            if name == "Owner" or name == "Admin" then 
            local x,y,z = getElementPosition( player ) 
                    setElementPosition ( veh, x, y, z + 5 ) 
                    end 
                end 
            end 
          ) 

Link to comment
addCommandHandler( "flip", 
    function ( player,vehicle ) 
    local playerTeam = getPlayerTeam ( player ) 
        if playerTeam then 
            local name = getTeamName ( playerTeam ) 
            if name == "Owner" or name == "Admin" then 
local vehicle = getPedOccupiedVehicle ( player ) 
            local x,y,z = getElementPosition( vehicle ) 
                    setElementPosition ( vehicle, x, y, z + 5 ) 
                    end 
                end 
            end 
          ) 

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...