Yunix Posted March 31, 2014 Share Posted March 31, 2014 (edited) Is there a function that checks if the player is holding a gun? Or is there any other way to do so? Edited April 3, 2014 by Guest Link to comment
Yunix Posted March 31, 2014 Author Share Posted March 31, 2014 Thanks, i searched the wiki for "weapon" but that one didn't came across. Link to comment
Alexs Posted March 31, 2014 Share Posted March 31, 2014 Thanks, i searched the wiki for "weapon" but that one didn't came across. YAW ^^ Link to comment
Yunix Posted April 1, 2014 Author Share Posted April 1, 2014 I made a function for checking the player's weapons when scrolling the weapon but it doesn't seem to work.. local guntable = { 23, 30, 32, 20, 9 } -- random id's function weaponDisable() weapon = getPedWeapon(localPlayer) if guntable[weapon] then else cancelEvent() end end addEventHandler ("onClientPlayerWeaponSwitch", getRootElement(), weaponDisable) Someone able to help me with this? Link to comment
Jaysds1 Posted April 1, 2014 Share Posted April 1, 2014 try this: local guntable = { 23, 30, 32, 20, 9 } -- random id's function weaponDisable(preSlot) local weapon = getPedWeapon(localPlayer) if not guntable[weapon] then setPedWeaponSlot(localPlayer,preSlot) end end addEventHandler ("onClientPlayerWeaponSwitch",localPlayer, weaponDisable) --only trigger this event for local player Link to comment
Yunix Posted April 1, 2014 Author Share Posted April 1, 2014 (edited) Tried it, and it does not work. EDIT: It doesn't allow the scrolling even when scrolling to a allowed weapon. Edited April 1, 2014 by Guest Link to comment
Jaysds1 Posted April 1, 2014 Share Posted April 1, 2014 Isn't that what you wanted? The function is triggered when a player tries to switch to a weapon; and in the function, if the player doesn't have the valid weapon that's not in the table then it switches the player weapon back to what they had before. Link to comment
Yunix Posted April 1, 2014 Author Share Posted April 1, 2014 Well, what i mean is when you have the valid weapon it doesn't allow you. Link to comment
xXMADEXx Posted April 2, 2014 Share Posted April 2, 2014 Try this local guntable = { [23]=true, [30]=true, [32]=true, [20]=true, [9]=true } function weaponDisable(preSlot) local weapon = getPedWeapon(localPlayer) if not guntable[weapon] then setPedWeaponSlot(localPlayer,preSlot) end end addEventHandler ("onClientPlayerWeaponSwitch",localPlayer, weaponDisable) --only trigger this event for local player Link to comment
Yunix Posted April 2, 2014 Author Share Posted April 2, 2014 Doesn't work, it does not allow to scroll with any weapon Link to comment
.:HyPeX:. Posted April 2, 2014 Share Posted April 2, 2014 This is a bit inneficient due to the loop, but try it. local guntable = { 23, 30, 32, 20, 9 } function weaponDisable(preSlot, NewSlot) local weapon = getPedWeapon(getLocalPlayer()) clear = nil for i,v in pairs(guntable) do if v == weapon then clear = true end end if clear then pre = nil for i,v in pairs(guntable) do if preSlot == v then pre = true end end if pre then setPedWeaponSlot(getLocalPlayer(),preSlot) else setPedWeaponSlot(getLocalPlayer(), guntable[math.random(#guntable)]) end end end addEventHandler ("onClientPlayerWeaponSwitch",getRootElement(), weaponDisable) Link to comment
Yunix Posted April 2, 2014 Author Share Posted April 2, 2014 Doesn't work, every weapon is now allowed Link to comment
Moderators IIYAMA Posted April 3, 2014 Moderators Share Posted April 3, 2014 Of course it isn't working it is much more complicated then that. You can try this, which I am 10% sure it will work. I have build something like this before, except I can't remember me how I wrote it. local gunTable = { 23, 30, 32, 20, 9 } local weaponDisable = function (slotChange) local validSlots = {0,1,2,3,4,5,6,7,8,9,10,11,12} local lastSlot = getPedWeaponSlot ( localPlayer ) for slot=0,12 do local weapon = getPedWeapon(localPlayer,slot) for wI=#gunTable,1,-1 do--inverse loop > table.remove if weapon == gunTable[wI] then table.remove(validSlots,slot) break end end end local lastSlotFound = false if slotChange == 1 then local saveTheLastPositions = {} for i=1,#validSlots do-- don't break this loop local slot = validSlots[i] if slot == lastSlot then lastSlotFound = i end saveTheLastPositions[i]=slot end if lastSlotFound then if saveTheLastPositions[lastSlotFound+1] then setPedWeaponSlot(localPlayer,saveTheLastPositions[lastSlotFound+1]) elseif saveTheLastPositions[1] then setPedWeaponSlot(localPlayer,saveTheLastPositions[1]) else error("something went very bad....") end elseif saveTheLastPositions[1] then error("player is not using a valid slot.") setPedWeaponSlot(localPlayer,saveTheLastPositions[1]) end elseif slotChange == -1 then local saveTheLastPositions = {} for i=#validSlots,1,-1 do-- don't break this loop local slot = validSlots[i] if slot == lastSlot then lastSlotFound = i end saveTheLastPositions[i]=slot end if lastSlotFound then if saveTheLastPositions[lastSlotFound-1] then setPedWeaponSlot(localPlayer,saveTheLastPositions[lastSlotFound-1]) elseif saveTheLastPositions[#saveTheLastPositions] then setPedWeaponSlot(localPlayer,saveTheLastPositions[#saveTheLastPositions]) else error("something went very bad....") end elseif saveTheLastPositions[#saveTheLastPositions] then error("player is not using a valid slot.") setPedWeaponSlot(localPlayer,saveTheLastPositions[#saveTheLastPositions]) end end end addEventHandler("onClientResourceStart",resourceRoot, function () bindKey("next_weapon","both",weaponDisable,1) bindKey("previous_weapon","both",weaponDisable,-1) end) addEventHandler("onClientResourceStop",resourceRoot, function () toggleControl ("next_weapon", true ) toggleControl ("previous_weapon", true ) end) addEventHandler("onClientRender",root, function () toggleControl ("next_weapon", false ) toggleControl ("previous_weapon", false ) end) Link to comment
Yunix Posted April 3, 2014 Author Share Posted April 3, 2014 Oh well, i already fixed it lol, and it's much simpler then that. 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