TorNix~|nR Posted July 9, 2016 Share Posted July 9, 2016 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
Captain Cody Posted July 9, 2016 Share Posted July 9, 2016 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
Captain Cody Posted July 9, 2016 Share Posted July 9, 2016 Walid, this is an Event handler being sent over from another script (Or the same script) I'm not sure it would include source. Link to comment
TorNix~|nR Posted July 9, 2016 Author Share Posted July 9, 2016 now everyone ( and me ) get 90 ammo I do not get 500 ammo Link to comment
Captain Cody Posted July 9, 2016 Share Posted July 9, 2016 You don't have you defined in this event handler. You need to send the reciver and the sender through. Link to comment
TorNix~|nR Posted July 9, 2016 Author Share Posted July 9, 2016 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
Captain Cody Posted July 9, 2016 Share Posted July 9, 2016 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
TorNix~|nR Posted July 9, 2016 Author Share Posted July 9, 2016 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
Captain Cody Posted July 9, 2016 Share Posted July 9, 2016 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
TorNix~|nR Posted July 9, 2016 Author Share Posted July 9, 2016 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? Link to comment
Walid Posted July 9, 2016 Share Posted July 9, 2016 @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
Captain Cody Posted July 9, 2016 Share Posted July 9, 2016 (edited) 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 July 9, 2016 by Guest Link to comment
Walid Posted July 9, 2016 Share Posted July 9, 2016 Thanks, worked, another final thing in my admin panelI 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
Captain Cody Posted July 9, 2016 Share Posted July 9, 2016 (edited) -- Nope Edited July 9, 2016 by Guest Link to comment
Captain Cody Posted July 9, 2016 Share Posted July 9, 2016 (edited) -- Nope Edited July 9, 2016 by Guest Link to comment
Walid Posted July 9, 2016 Share Posted July 9, 2016 (edited) 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. 3) it can be like this: local amount = ((plr == client) and 500) or 90 4) it can output some warnings because getText it can be a number or a string. Edited July 9, 2016 by Guest Link to comment
Captain Cody Posted July 9, 2016 Share Posted July 9, 2016 Ah the heck with it, I'm tired some one fix it. Link to comment
TorNix~|nR Posted July 9, 2016 Author Share Posted July 9, 2016 Fixed, thanks to Walid and CodyL 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