Jump to content

question


Recommended Posts

Hi i want to make script that if admin has set any player health to 20 or any value show in chatBox get the admin name and the player who given health with value

like outputChatBox("mta .. Has Set .. playerName .. Health to .. value")

what is the functions and event i want try to make it my self

Link to comment
addCommandHandler 
hasObjectPermissionTo 
setElementHealth 
outputChatBox 
getPlayerName 

Just a small fix for your outputChatBox function usage.

outputChatBox("You've set " .. getPlayerName(target) .. "'s health to " .. tonumber(health) .. ".", player, 255, 255, 255, false) 
outputChatBox(getPlayerName(player) .. " set your health to " .. tonumber(health) .. ".", target, 255, 255, 255, false) 

Remember to find the player's name first and make a local of the function like this.

getPlayerFromPartialName function.

local function getPlayerFromPartialName(name, player) 
    if name then 
        local matches = {} 
        for index, _player in ipairs(getElementsByType("player")) do 
            if getPlayerName(_player) == name then 
                return _player 
            end 
            if getPlayerName(_player):gsub("#%x%x%x%x%x%x", ""):lower():find(name:lower()) then 
                table.insert matches, _player) 
            end 
        end 
        if #matches == 1 then 
            return matches[1] 
        else 
            if player then 
                outputChatBox("Found " .. #matches .. " matches.", player, 255, 0, 0) 
            end 
        end 
    end 
end 

This is the local for the set health script.

local target = getPlayerFromPartialName(name, player) 

And the rest you'll need to do yourself.

addCommandHandler("sethp", 
     function(player, cmd, name, health) 
          if ?!?! then -- Something goes here 
               if ?!?! then -- Something goes here 
                    if ?!?! then -- Something goes here 
                         local target = getPlayerFromPartialName(name, player) 
                         if ?!?! then -- Something goes here 
                              -- Your script 
                         else 
                              -- Alternative outputs 
                         end 
                    else 
                         -- Alternative outputs 
                    end 
               else 
                    -- Alternative outputs 
               end 
          else 
               -- Alternative outputs 
          end 
     end 
) 
  
local function getPlayerFromPartialName(name, player) 
    if name then 
        local matches = {} 
        for index, _player in ipairs(getElementsByType("player")) do 
            if getPlayerName(_player) == name then 
                return _player 
            end 
            if getPlayerName(_player):gsub("#%x%x%x%x%x%x", ""):lower():find(name:lower()) then 
                table.insert matches, _player) 
            end 
        end 
        if #matches == 1 then 
            return matches[1] 
        else 
            if player then 
                outputChatBox("Found " .. #matches .. " matches.", player, 255, 0, 0) 
            end 
        end 
    end 
end 

Link to comment

no castillo

if you team 1 and i team 2 i give my self health with out you know i want script that show if i give my slef health to all players or i give health to any player

for example if you hit me +50 i give my slef with admin panle +50 health

i want outputChatBox("evil-coder.. teamName .. "Has Give himself health (he Cheat )

Link to comment

Or do you want it to output the message to all players in the server? Or yourself? Or your team?

No admin panel is mixed in this, leave it out. We'll do this with commands unless you make the GUI.

You want it like: /givehealth and check if he's in your team?

or /givehealth and give you health.

Or /givehealth or /givehealth

Explain better, please :)

Link to comment

As I entered an example before, here it is again with few changes...

outputChatBox(getPlayerName(player) .. " has given " .. getPlayerName(target) .. " health with value " .. tonumber(health) .. ".", root, 255, 0, 0, false) 

Gosh. I made a long reply and you didn't read it.

Link to comment
addCommandHandler("givehealth", 
    function (thePlayer, cmd, who, health) 
        local accountName = getAccountName(getPlayerAccount(thePlayer)) 
        if ( isObjectInACLGroup ( "user." .. accountName, aclGetGroup ( "Admin" ) ) ) then 
            local health = tonumber(health) 
            local player = getPlayerFromName(who) 
            if (health and player) then 
                setElementHealth(player, getElementHealth(player)+health) 
                outputChatBox(getPlayerName(thePlayer) .." has given ".. getPlayerName(player) .." ".. health .."% of health.",root,0,255,0) 
            end 
        end 
    end 
) 

Do you mean that?

/givehealth

Link to comment

This what i mean

function (thePlayer, who, health) 
        local accountName = getAccountName(getPlayerAccount(thePlayer)) 
        if ( isObjectInACLGroup ( "user." .. accountName, aclGetGroup ( "Admin" ) ) ) then 
            local health = tonumber(health) 
            local player = getPlayerFromName(who) 
            if (health and player) then 
                outputChatBox(getPlayerName(thePlayer) .." Has given ".. getPlayerName(player) .." ".. health .."% of health.",root,255,255,0) 
            end 
        end 
    end 
) 

Link to comment

its say expected: 1 name near (' ?

function (thePlayer, who, health) 
        local accountName = getAccountName(getPlayerAccount(thePlayer)) 
        if ( isObjectInACLGroup ( "user." .. accountName, aclGetGroup ( "Admin" ) ) ) then 
            local health = tonumber(health) 
            local player = getPlayerFromName(who) 
            if (health and player) then 
                outputChatBox(getPlayerName(thePlayer) .." Has given ".. getPlayerName(player) .." ".. health .."% of health.",root,255,255,0) 
            end 
        end 
    end 
) 

Link to comment

Try this.

addCommandHandler("givehealth", 
     function(player, cmd, name, value) 
          if hasObjectPermissionTo(player, "command.ban") then 
               if name and value then 
                    if tonumber(value) then 
                         local target = getPlayerFromPartialName(name, player) 
                         if target then 
                              if tonumber(value) > 0 and tonumber(value) <= 100 then 
                                   setElementHealth(target, getElementHealth(target) + tonumber(value)) 
                                   outputChatBox(getPlayerName(player) .. " has given " .. getPlayerName(target) .. " health with value " .. tonumber(value) .. ".", root, 220, 220, 0, false) 
                              else 
                                   outputChatBox("Health's minimum value is 1 and maximum is 100.", player, 255, 0, 0, false) 
                              end 
                         else 
                              outputChatBox("No players or multiple were found.", player, 255, 0, 0, false) 
                         end 
                    else 
                         outputChatBox("Health value must be numbers.", player, 255, 0, 0, false) 
                    end 
               else 
                    outputChatBox("Syntax: /givehealth .", player, 220, 220, 0, false) 
               end 
          else 
               outputChatBox("No sufficent privileges (admin level required).", player, 255, 0, 0, false) 
          end 
     end 
) 
  
local function getPlayerFromPartialName(name, player) 
    if name then 
        local matches = {} 
        for index, _player in ipairs(getElementsByType("player")) do 
            if getPlayerName(_player) == name then 
                return _player 
            end 
            if getPlayerName(_player):gsub("#%x%x%x%x%x%x", ""):lower():find(name:lower()) then 
  
                table.insert matches, _player) 
            end 
        end 
        if #matches == 1 then 
            return matches[1] 
        else 
            if player then 
                outputChatBox("Found " .. #matches .. " matches.", player, 255, 0, 0) 
            end 
        end 
    end 
end 

Edited by Guest
Link to comment

not command to give health !!

i want get the like this

but with out a commad

function what (thePlayer, who, health) 
        local accountName = getAccountName(getPlayerAccount(thePlayer)) 
        if ( isObjectInACLGroup ( "user." .. accountName, aclGetGroup ( "Admin" ) ) ) then 
            local health = tonumber(health) 
            local player = getPlayerFromName(who) 
            local thePlayer = (source) 
            if (health and player) then 
            outputChatBox(getPlayerName(thePlayer) .." Has given ".. getPlayerName(player) .." ".. health .. getElementHealth(source)"% of health.",root,255,255,0) 
end 
addEventHandler ( "onResourceStart", getRootElement(), what ) 

Edited by Guest
Link to comment

You want it to be a function? not a command?

function giveHealth(thePlayer, who, health) 
    local accountName = getAccountName(getPlayerAccount(thePlayer)) 
    if ( isObjectInACLGroup ( "user." .. accountName, aclGetGroup ( "Admin" ) ) ) then 
        local health = tonumber(health) 
        local player = getPlayerFromName(who) 
        if (health and player) then 
            outputChatBox(getPlayerName(thePlayer) .." Has given ".. getPlayerName(player) .." ".. health .."% of health.",root,255,255,0) 
        end 
    end 
end 

Link to comment
function giveHealth(player, name, value) 
     local accountName = getAccountName(getPlayerAccount(player)) 
     if isObjectInACLGroup("user." .. accountName, aclGetGroup("Admin")) then 
           local health = tonumber(value) 
           local target = getPlayerFromName(name) 
           if health and target then 
                outputChatBox(getPlayerName(player) .. " has given " .. getPlayerName(target) .. " " .. health .. "% of health.", root, 255, 255, 0) 
           end 
     end 
end 

Edited by Guest
Link to comment

:2: Bad argument @ 'getPlayerAccount'[Expected element at arguemnt 1 got resource-data]

:2: Bad argument @ 'getAccountName'[Expected element at arguemnt 1 got boolean]

:3: attempt to coucatenate local 'accountName' a boolean value

function what (thePlayer, who, health) 
        local accountName = getAccountName(getPlayerAccount(thePlayer)) 
        if ( isObjectInACLGroup ( "user." .. accountName, aclGetGroup ( "Admin" ) ) ) then 
            local health = tonumber(health) 
            local player = getPlayerFromName(who) 
            local thePlayer = (source) 
            if (health and player) then 
            outputChatBox(getPlayerName(thePlayer) .." Has given ".. getPlayerName(player) .." ".. health .. getElementHealth(source)"% of health.",root,255,255,0) 
end 
end 
end 
addEventHandler ( "onResourceStart", getRootElement(), what ) 

Link to comment

lool i sould learn english i told you

if i team 1 and you team 2 we play in my server Solidsnake14 vs Evil

i give my self Health ( i cheat ) i want to outputMsg

("evil Has Set His health to ... ") i want all players see it

or i give you health

("evil has give Solidsnake14 health")

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