Jump to content

Problem with disabling explosives


Price.

Recommended Posts

well I'm trying to disable explosives in both SF and LS and make them allowed in LV, so I made it when you try to switch to slot that has throwables it switches back to fist, I made that using COL shape but then I'm able to switch back to grenades, I made a separate functions but then I can't enable it in LV, I used toggle control but sometimes I can't shoot with shotguns nor in LV too

HELP?

SERVER SIDE :

ExplosiveID = { 
    [16] = true, 
    [17] = true, 
    [18] = true, 
    [39] = true, 
    [40] = true, 
} 
  
local hillAreaLS = createColRectangle (  -905.5929, -2933.0986, 4000, 3500 ) 
local hillAreaSF =  createColRectangle( -2994.09448,-1378.01746,2000,4900) 
local hillAreaLV =  createColRectangle   (-905.5929,602.33,4000,2500) 
  
function hill_EnterLS ( thePlayer, matchingDimension ) 
        
        local slot = getPedWeaponSlot ( thePlayer ) 
        if (getElementType(thePlayer) == "player") and ( slot == -- s8) --> then 
                outputChatBox( "You have entered Los Santos", thePlayer, 255, 255, 0 ) 
                 setPedWeaponSlot ( thePlayer, 0 ) 
      
        end 
end 
addEventHandler ( "onColShapeHit", hillAreaLS, hill_EnterLS ) 
  
function hill_EnterSF ( thePlayer, matchingDimension ) 
        
        local slot = getPedWeaponSlot ( thePlayer ) 
        if (getElementType(thePlayer) == "player") and ( slot == -- s8) --> then 
                outputChatBox( "You have entered San Fierro", thePlayer, 255, 255, 0 ) 
                 setPedWeaponSlot ( thePlayer, 0 ) 
        end 
end 
addEventHandler ( "onColShapeHit", hillAreaSF, hill_EnterSF ) 
  
  
function hill_EnterLV ( thePlayer, matchingDimension) 
  
local slot = getPedWeaponSlot ( thePlayer ) 
  
if (getElementType(thePlayer) == "player") and ( slot == -- s8) --> then 
  
toggleControl ( source, "fire", true ) 
outputChatBox("You have entered Las Venturas", thePlayer, 255, 255, 0) 
end 
end 
addEventHandler ( "onColShapeHit", hillAreaLV, hill_EnterLV ) 
  
  
addEventHandler ( 'onPlayerWeaponSwitch', getRootElement ( ), 
    function ( previousWeaponID, currentWeaponID) 
    local slot = getPedWeaponSlot ( source ) 
    local x, y, z = getElementPosition(source) 
    local zone = getZoneName ( x, y, z ) 
    if ( ExplosiveID[currentWeaponID] )  then 
    setPedWeaponSlot ( source, 0 ) 
  toggleControl ( source, "fire", false ) 
  else 
  toggleControl ( source, "fire", true ) 
 end 
end 
) 

There are no errors nor debugs

Link to comment

Something is wrong with the code you posted:

 slot == -- s8) -->

Probably just a paste error and not your issue.

Have you tried getZoneName with true at the end already? Something like this on switching weapons and/or onHitColshape:

bannedIds = {16,17,18,39,40} 
  
local city = getElementZoneName(thePlayer, true) 
if city == "Las Venturas" then 
    local slot = getPedWeaponSlot(thePlayer) 
    for _,id in ipairs(bannedIds) do 
        if slot == id then 
            setPedWeaponSlot(thePlayer, 0) 
        end 
    end 
end 
outputChatBox("Welcome to "..city, thePlayer) 

Edited by Guest
Link to comment

Changing true in the getZoneName won't help, I tried that already I just forgot to paste it

I tried your code @Tails but uhm, the outputchatbox works and all and if I'm holding a grenade it switches to fist but I still can switch back to grenades regularly

PS: I Switched to source variable instead of thePlayer bec it gives errors

Link to comment

Are you still using the colshapes? If you are then you can add this:

local current = getPedWeapon(thePlayer) 
for _,id in ipairs(bannedIds) do 
    if current == id then 
        setPedWeaponSlot(thePlayer, 0 ) 
    end 
end 

Do that on colshape hit. This forces the player to switch to fists if they had already equipped the explosives before they entered the colshape/zone. So since they'll enter and their not holding the exploves and the switch weapon event is in place then they shouldn't be able to switch back them.

Edited by Guest
Link to comment

Now I can't fire with any gun at all, but when I enter LV i can

ExplosiveID = { 
    [16] = true, 
    [17] = true, 
    [18] = true, 
    [39] = true, 
    [40] = true, 
} 
  
local hillAreaLS = createColRectangle (  -905.5929, -2933.0986, 4000, 3500 ) 
local hillAreaSF =  createColRectangle( -2994.09448,-1378.01746,2000,4900) 
local hillAreaLV =  createColRectangle   (-905.5929,602.33,4000,2500) 
  
function hill_EnterLS ( thePlayer, matchingDimension ) 
        
        outputChatBox( "You have entered Los Santos", thePlayer, 255, 255, 0 ) 
        local slot = getPedWeaponSlot ( thePlayer ) 
        if (getElementType(thePlayer) == "player") and ( slot == -- s8) --> then 
                 toggleControl(thePlayer, "fire", false) 
                 else 
                  toggleControl(thePlayer, "fire", true) 
                -- setPedWeaponSlot ( thePlayer, 0 ) 
      
        end 
end 
addEventHandler ( "onColShapeHit", hillAreaLS, hill_EnterLS ) 
  
function hill_EnterSF ( thePlayer, matchingDimension ) 
       outputChatBox( "You have entered San Fierro", thePlayer, 255, 255, 0 ) 
        local slot = getPedWeaponSlot ( thePlayer ) 
        if (getElementType(thePlayer) == "player") and ( slot == -- s8) --> then 
                 setPedWeaponSlot ( thePlayer, 0 ) 
        end 
end 
addEventHandler ( "onColShapeHit", hillAreaSF, hill_EnterSF ) 
  
  
function hill_EnterLV ( thePlayer, matchingDimension) 
  
local slot = getPedWeaponSlot ( thePlayer ) 
  
if (getElementType(thePlayer) == "player") and ( slot == 8 ) then 
toggleControl ( thePlayer, "fire", true ) 
outputChatBox("You have entered Las Venturas", thePlayer, 255, 255, 0) 
end 
end 
addEventHandler ( "onColShapeHit", hillAreaLV, hill_EnterLV ) 
  
 bannedIds = {16,17,18,39,40} 
  
  
addEventHandler ( 'onPlayerWeaponSwitch', getRootElement ( ), 
  function ( previousWeaponID, currentWeaponID) 
 for i, thePlayer in ipairs(getElementsByType("player")) do 
local city = getElementZoneName(thePlayer, true) 
if city == "Las Venturas" then 
    local slot = getPedWeaponSlot(thePlayer) 
    for _,id in ipairs(bannedIds) do 
        if slot == id then 
            toggleControl(source, "fire", false) 
             else 
             toggleControl(source, "fire", true) 
        end 
    end 
    end 
end 
end ) 
  

@Tails, Uhm Its not a problem to make it force switch to fists, I will still be able to switch to grenades then, Its about preventing switching to grenades / Disable firing them

Link to comment

Yeah I understand.

local bannedIds = { 
    [16] = true, 
    [17] = true, 
    [18] = true, 
    [39] = true, 
    [40] = true, 
} 
  
local hillAreaLS = createColRectangle (  -905.5929, -2933.0986, 4000, 3500 ) 
local hillAreaSF =  createColRectangle( -2994.09448,-1378.01746,2000,4900) 
local hillAreaLV =  createColRectangle   (-905.5929,602.33,4000,2500) 
  
function forcePlayerWeapon(prevId, curId) 
    if isElementWithinColShape(source, hillAreaLV) then 
        if bannedIds[curId] then 
            outputChatBox("blocked explosives") 
            setPedWeaponSlot(source, 0) 
        end 
    end 
end 
addEventHandler("onPlayerWeaponSwitch", root, forcePlayerWeapon) 

This seems to work for me fine when I'm in within the LV colshape. The getElementZoneName wasn't returning LV everywhere within your colshape.

For the welcoming you can use something like:

function welcomePlayer(hitElem, matchingDim) 
    if getElementType(hitElem) == "player" and matchingDim then 
        if source == hillAreaLS then 
            outputChatBox("Welcome to Los Santos", hitElem) 
        elseif source == hillAreaSF then 
            outputChatBox("Welcome to San Fierro", hitElem) 
        elseif source == hillAreaLV then 
            outputChatBox("Welcome to Las Venturas", hitElem) 
             
            local curId = getPlayerWeapon(hitElem) 
            if bannedIds[curId] then 
                setPedWeaponSlot(hitElem, 0)  -- Switch player weapon if they have an explosive equipped 
            end 
        end 
    end 
end 
addEventHandler("onColShapeHit", resourceRoot, welcomePlayer) 
  

Btw,

for i, thePlayer in ipairs(getElementsByType("player")) do 

is unnecessary in your code and really really bad for your servers performance to do it on weapon switch. You can use 'source' which is the player for this function.

Also, if you really want to block the player from firing their weapon then you probably want to do it client-side using:

https://wiki.multitheftauto.com/wiki/On ... WeaponFire

EDIT: Modified table back to how you had it, it is better because you don't have to loop through it. My mistake.

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