Jump to content

Give weapon (admin panel)


Recommended Posts

hello everyone, thanks for all the helps :)

I have an admin panel, I can give weapon, I can give to all players weapon with ammo: 500 and to myself

I need when I give weapon, the players get ammo 90, and just I can get ammo with: 500 (myself)

--Give weapon 
addEvent("AdminPanel.giveWeap", true) 
function giveWeap(plr, getText, id) 
    outputChatBox("#FF0000" ..getPlayerName(source).."#00FF00 Te ha dado un Arma #0B00FF("..getText..") ", plr, r, g, b, true) 
    outputChatBox("#00FF00 Has dado a #FF0000" ..getPlayerName(plr).."#00FF00 un Arma #0B00FF(" ..getText..") ", source, r, g, b, true) 
    if (not isElement(plr)) then return end 
    local wepID = getWeaponIDFromName(getText) 
    local wepName = getWeaponNameFromID(getText) 
    if (wepID) then 
        giveWeapon(plr, wepID, 500, true) 
    end 
    if (wepName) then 
        giveWeapon(plr, wepName, 500, true) 
    end 
    end 
addEventHandler("AdminPanel.giveWeap", root, giveWeap)  

Link to comment

You need to send the sender through the event along with the receiver.

     --Give weapon 
    addEvent("AdminPanel.giveWeap", true) 
    function giveWeap(plr, getText, id, you) -- MAKE IT SEND OVER, THE SENDER 
        outputChatBox("#FF0000" ..getPlayerName(source).."#00FF00 Te ha dado un Arma #0B00FF("..getText..") ", plr, r, g, b, true) 
        outputChatBox("#00FF00 Has dado a #FF0000" ..getPlayerName(plr).."#00FF00 un Arma #0B00FF(" ..getText..") ", source, r, g, b, true) 
        if (not isElement(plr)) then return end 
        local wepID = getWeaponIDFromName(getText) 
        local wepName = getWeaponNameFromID(getText) 
        if (wepID) then 
            if plr = you then 
            giveWeapon(plr, wepID, 500, true) 
            else 
            giveWeapon(plr, wepID, 90, true) 
            end 
        end 
        if (wepName) then 
            if plr = you then 
            giveWeapon(plr, wepName, 500, true) 
            else 
            giveWeapon(plr, wepName, 90, true) 
            end 
        end 
        end 
    addEventHandler("AdminPanel.giveWeap", root, giveWeap)  

Link to comment

like always 90 ammo

     addEvent("AdminPanel.giveWeap", true) 
    function giveWeap(plr, getText, id, you) -- MAKE IT SEND OVER, THE SENDER 
        outputChatBox("#FF0000" ..getPlayerName(source).."#00FF00 Te ha dado un Arma #0B00FF("..getText..") ", plr, r, g, b, true) 
        outputChatBox("#00FF00 Has dado a #FF0000" ..getPlayerName(plr).."#00FF00 un Arma #0B00FF(" ..getText..") ", source, r, g, b, true) 
        if (not isElement(plr)) then return end 
        local wepID = getWeaponIDFromName(getText) 
        local wepName = getWeaponNameFromID(getText) 
        if (wepID) then 
            if plr == you then 
            giveWeapon(plr, wepID, 500, true) 
            else 
            giveWeapon(plr, wepID, 90, true) 
            end 
        end 
        if (wepName) then 
            if plr == you then 
            giveWeapon(plr, wepName, 500, true) 
            else 
            giveWeapon(plr, wepName, 90, true) 
            end 
        end 
        end 
    addEventHandler("AdminPanel.giveWeap", root, giveWeap)  

Link to comment
         addEvent("AdminPanel.giveWeap", true) 
        function giveWeap(plr, getText, id) -- MAKE IT SEND OVER, THE SENDER 
            outputChatBox("#FF0000" ..getPlayerName(source).."#00FF00 Te ha dado un Arma #0B00FF("..getText..") ", plr, r, g, b, true) 
            outputChatBox("#00FF00 Has dado a #FF0000" ..getPlayerName(plr).."#00FF00 un Arma #0B00FF(" ..getText..") ", source, r, g, b, true) 
            if (not isElement(plr)) then return end 
            local wepID = getWeaponIDFromName(getText) 
            local wepName = getWeaponNameFromID(getText) 
            if (wepID) then 
                if plr == client then 
                giveWeapon(plr, wepID, 500, true) 
                else 
                giveWeapon(plr, wepID, 90, true) 
                end 
            end 
            if (wepName) then 
                if plr == client then 
                giveWeapon(plr, wepName, 500, true) 
                else 
                giveWeapon(plr, wepName, 90, true) 
                end 
            end 
            end 
        addEventHandler("AdminPanel.giveWeap", root, giveWeap)  

Link to comment

I try use this for the ammo in outputChatbox and it won't work

         addEvent("AdminPanel.giveWeap", true) 
        function giveWeap(plr, getText, Ammo, id) -- MAKE IT SEND OVER, THE SENDER 
            outputChatBox("#FF0000" ..getPlayerName(source).."#00FF00 Te ha dado un Arma #0B00FF("..getText..") ("..Ammo..") ", plr, r, g, b, true) 
            outputChatBox("#00FF00 Has dado a #FF0000" ..getPlayerName(plr).."#00FF00 un Arma #0B00FF(" ..getText..") ("..Ammo..") ", source, r, g, b, true) 
            if (not isElement(plr)) then return end 
            local Ammo = getWeaponAmmo(Ammo) 
            local wepID = getWeaponIDFromName(getText) 
            local wepName = getWeaponNameFromID(getText) 
            if (wepID) then 
                if plr == client then 
                giveWeapon(plr, wepID, 500, true) 
                else 
                giveWeapon(plr, wepID, 90, true) 
                end 
            end 
            if (wepName) then 
                if plr == client then 
                giveWeapon(plr, wepName, 500, true) 
                else 
                giveWeapon(plr, wepName, 90, true) 
                end 
            end 
            end 
        addEventHandler("AdminPanel.giveWeap", root, giveWeap)  

Link to comment
             addEvent("AdminPanel.giveWeap", true) 
            function giveWeap(plr, getText, Ammo, id) -- MAKE IT SEND OVER, THE SENDER 
            if plr == client then 
                outputChatBox("#FF0000" ..getPlayerName(source).."#00FF00 Te ha dado un Arma #0B00FF("..getText..") (500) ", plr, r, g, b, true) 
                outputChatBox("#00FF00 Has dado a #FF0000" ..getPlayerName(plr).."#00FF00 un Arma #0B00FF(" ..getText..") (500) ", source, r, g, b, true) 
               else 
                outputChatBox("#FF0000" ..getPlayerName(source).."#00FF00 Te ha dado un Arma #0B00FF("..getText..") (90) ", plr, r, g, b, true) 
                outputChatBox("#00FF00 Has dado a #FF0000" ..getPlayerName(plr).."#00FF00 un Arma #0B00FF(" ..getText..") (90) ", source, r, g, b, true) 
                end 
                if (not isElement(plr)) then return end 
                local Ammo = getWeaponAmmo(Ammo) 
                local wepID = getWeaponIDFromName(getText) 
                local wepName = getWeaponNameFromID(getText) 
                if (wepID) then 
                    if plr == client then 
                    giveWeapon(plr, wepID, 500, true) 
                    else 
                    giveWeapon(plr, wepID, 90, true) 
                    end 
                end 
                if (wepName) then 
                    if plr == client then 
                    giveWeapon(plr, wepName, 500, true) 
                    else 
                    giveWeapon(plr, wepName, 90, true) 
                    end 
                end 
                end 
            addEventHandler("AdminPanel.giveWeap", root, giveWeap)  

Link to comment

@CodyL try always to optimize your codes as much as you can.

addEvent("AdminPanel.giveWeap", true) 
    function giveWeap(plr, getText)  
        if plr and isElement(plr) then  
            if getText then  
                if type(getText) == "string" then  
                    wep = getWeaponIDFromName(getText) 
                elseif type(getText) == "number" then 
                    wep = getText 
                end  
                if plr == client then 
                    giveWeapon(plr, wep, 500, true) 
                else 
                giveWeapon(plr, wepID, 90, true) 
            end 
        end 
    end  
end  
addEventHandler("AdminPanel.giveWeap", root, giveWeap) 

Link to comment

Sorry, usually when fixing scripts of people I just fix what needs to be done unless it requires an entire rewrite.

Any ways, what you did knocked off an entire section of the code that he wanted working.

                 
                DonotInclude = {38,34} 
                 
                addEvent("AdminPanel.giveWeap", true) 
                function giveWeap(plr, getText) -- MAKE IT SEND OVER, THE SENDER 
                 if not isElement(plr) then return end 
                        local wepID,wepName = getWeaponIDFromName(getText),getWeaponNameFromID(getText) 
                         
                if wepID then 
                id = wepID 
                else 
                id = wepName 
                end 
                 
                for i,v in pairs(DonotInclude) do 
                if v = id then  
                no = true 
                end 
                end 
                 
                if no == true then return end 
                     
                if plr == client then 
                    amount = 500 
                    else 
                    amount = 90 
                end 
                 
                    outputChatBox("#FF0000" ..getPlayerName(client).."#00FF00 Te ha dado un Arma #0B00FF("..getText..") ("..amount..") ", plr, r, g, b, true) 
                    outputChatBox("#00FF00 Has dado a #FF0000" ..getPlayerName(plr).."#00FF00 un Arma #0B00FF(" ..getText..") ("..amount..") ", client, r, g, b, true) -- Changed source to client, this is coming from client side. 
                        giveWeapon(plr, id,amount, true) 
                        end 
                    end 
                addEventHandler("AdminPanel.giveWeap", root, giveWeap)  

Edited by Guest
Link to comment
Thanks, worked, another final thing in my admin panel

I need to cancelEvent in some weapons like ID: 38 and ID: 34 and Name: Minigun and Name: Sniper

how can I fix it?

Here is what you need

local inValidWeapons = {[38] = true , [34] = true} 
  
addEvent("AdminPanel.giveWeap", true) 
    function giveWeap(plr, getText)  
        if plr and isElement(plr) then  
            if getText then  
                if type(getText) == "string" then  
                    wep = getWeaponIDFromName(getText) 
                elseif type(getText) == "number" then 
                    wep = getText 
                end  
                if inValidWeapons[wep] then 
                    outputChatBox("You can't give him this type of weapons",client,255,0,0)  
                    return  
                end  
                 
                local ammo =  ((plr == client) and 500) or 90 
                giveWeapon(plr, wep, 500, true) 
                outputDebugString(ammo) 
             outputChatBox("#FF0000" ..getPlayerName(client).."#00FF00 Te ha dado un Arma #0B00FF("..getWeaponNameFromID(wep)..") ("..ammo..") ", plr, r, g, b, true) 
        end  
    end  
end  
addEventHandler("AdminPanel.giveWeap", root, giveWeap) 

Link to comment

85b7dce8f7.png

1) You Don't need to check if it's true because you already added it here in your table.

2) Try always to use local as much as you can.

11abdb25b4.png

3) it can be like this:

d6c1ec468d.png

local amount = ((plr == client) and 500) or 90 

4) it can output some warnings because getText it can be a number or a string.

85dec63c4c.png

Edited by Guest
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...