Jump to content

onVehicleEnter and onWeaponSwitch interfering


Axel

Recommended Posts

So i made 2 little scripts:

function onEnter ( theVehicle, seat, jacked ) 
    local veh =  getVehicleName ( theVehicle ) 
    exports.global:sendLocalMeAction(source, "intra in vehiculul "..veh..".") 
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), onEnter ) 
-- When someone enters the vehicle, a local me action is sent.. 
  

and

  
function weaponSwitch ( previousWeaponID, currentWeaponID ) 
     if currentWeaponID == 3 then 
          exports.global:sendLocalMeAction(source, "scoate un baston de politist.") 
     elseif currentWeaponID == 4 then 
          exports.global:sendLocalMeAction(source, "scoate un cutit.") 
     elseif currentWeaponID == 2 then 
          exports.global:sendLocalMeAction(source, "scoate o crosa de golf.") 
     elseif currentWeaponID == 5 then 
          exports.global:sendLocalMeAction(source, "scoate o bata de baseball.")     
     elseif currentWeaponID == 6 then 
          exports.global:sendLocalMeAction(source, "scoate o lopata.")       
     elseif currentWeaponID == 7 then 
          exports.global:sendLocalMeAction(source, "scoate o bata de biliard.")  
     elseif currentWeaponID == 8 then 
          exports.global:sendLocalMeAction(source, "scoate o sabie.")    
     elseif currentWeaponID == 9 then 
          exports.global:sendLocalMeAction(source, "scoate o drujba.")   
     elseif currentWeaponID == 22 then 
          exports.global:sendLocalMeAction(source, "scoate un pistol.")      
     elseif currentWeaponID == 23 then 
          exports.global:sendLocalMeAction(source, "scoate un pistol cu amortizor.")     
     elseif currentWeaponID == 24 then 
          exports.global:sendLocalMeAction(source, "scoate un pistol.")  
     elseif currentWeaponID == 25 then 
          exports.global:sendLocalMeAction(source, "scoate un shotgun.")     
     elseif currentWeaponID == 26 then 
          exports.global:sendLocalMeAction(source, "scoate un shotgun improvizat.")  
     elseif currentWeaponID == 27 then 
          exports.global:sendLocalMeAction(source, "scoate un shotgun de elita.")    
     elseif currentWeaponID == 28 then 
          exports.global:sendLocalMeAction(source, "scoate un Uzi.") 
     elseif currentWeaponID == 29 then 
          exports.global:sendLocalMeAction(source, "scoate un MP5.") 
     elseif currentWeaponID == 30 then 
          exports.global:sendLocalMeAction(source, "scoate un Ak-47.")       
     elseif currentWeaponID == 31 then 
          exports.global:sendLocalMeAction(source, "scoate un M4.")        
     elseif currentWeaponID == 32 then 
          exports.global:sendLocalMeAction(source, "scoate un Tech-9.")  
     elseif currentWeaponID == 34 then 
          exports.global:sendLocalMeAction(source, "scoate un Sniper.")                
     end 
end 
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponSwitch ) 
-- When someone changes his weapon, a local me action is sent 

The problem is that when someone enters a vehicle a local action saying that he takes out a Uzi is sent.

Does somebody knows how can i cancel the showing of that message?

Link to comment

There is no error in the scripts, it's just the thing that in MTA/GTA shows u some weapons with you can shot from the vehicle when u enter it. In my case Uzi .

So what i need help in is that when they enter the car, the message to not appear.

Link to comment

You can try checking if the player is on a vehicle.

function weaponSwitch ( previousWeaponID, currentWeaponID ) 
    if isPedInVehicle(source) then return end 
    if (currentWeaponID == 3) then 
        exports.global:sendLocalMeAction(source, "scoate un baston de politist.") 
    elseif (currentWeaponID == 4) then 
        exports.global:sendLocalMeAction(source, "scoate un cutit.") 
    elseif (currentWeaponID == 2) then 
        exports.global:sendLocalMeAction(source, "scoate o crosa de golf.") 
    elseif (currentWeaponID == 5) then 
        exports.global:sendLocalMeAction(source, "scoate o bata de baseball.")    
    elseif (currentWeaponID == 6) then 
        exports.global:sendLocalMeAction(source, "scoate o lopata.")      
    elseif (currentWeaponID == 7) then 
        exports.global:sendLocalMeAction(source, "scoate o bata de biliard.")  
    elseif (currentWeaponID == -- s8) --> then 
        exports.global:sendLocalMeAction(source, "scoate o sabie.")    
    elseif (currentWeaponID == 9) then 
        exports.global:sendLocalMeAction(source, "scoate o drujba.")  
    elseif (currentWeaponID == 22) then 
        exports.global:sendLocalMeAction(source, "scoate un pistol.")     
    elseif (currentWeaponID == 23) then 
        exports.global:sendLocalMeAction(source, "scoate un pistol cu amortizor.")    
    elseif (currentWeaponID == 24) then 
        exports.global:sendLocalMeAction(source, "scoate un pistol.")  
    elseif (currentWeaponID == 25) then 
        exports.global:sendLocalMeAction(source, "scoate un shotgun.")    
    elseif (currentWeaponID == 26) then 
        exports.global:sendLocalMeAction(source, "scoate un shotgun improvizat.")  
    elseif (currentWeaponID == 27) then 
        exports.global:sendLocalMeAction(source, "scoate un shotgun de elita.")    
    elseif (currentWeaponID == 28) then 
        exports.global:sendLocalMeAction(source, "scoate un Uzi.") 
    elseif (currentWeaponID == 29) then 
        exports.global:sendLocalMeAction(source, "scoate un MP5.") 
    elseif (currentWeaponID == 30) then 
        exports.global:sendLocalMeAction(source, "scoate un Ak-47.")      
    elseif (currentWeaponID == 31) then 
        exports.global:sendLocalMeAction(source, "scoate un M4.")       
    elseif (currentWeaponID == 32) then 
        exports.global:sendLocalMeAction(source, "scoate un Tech-9.")  
    elseif (currentWeaponID == 34) then 
        exports.global:sendLocalMeAction(source, "scoate un Sniper.")               
    end 
end 
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponSwitch ) 
-- When someone changes his weapon, a local me action is sent 

P.S: Don't listen to Evil, he keep's posting random stuff to increase his post count.

Link to comment

That worked just fine:D Thanks Solidsnake14.

Now i'm trying to show a me action when the player is targeting a player or a car.

  
function onPlayerTarget ( targetElem ) 
    target = getElementType ( targetElem ) 
    if target and getElementModel ( targetElem ) == 'player' then 
        exports.global:sendLocalMeAction(source, "tinteste spre "..target..".") 
    elseif target and getElementModel ( targetElem ) == 'vehicle' then 
        exports.global:sendLocalMeAction(source, "tinteste spre "..target..".") 
    else 
    return 
    end 
end 
addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTarget )   
-- This shows a warning : 2:Bad argument: getElementType 
  

Link to comment
function onPlayerTarget ( targetElem ) 
    if (targetElem and isElement(targetElem)) then 
        if (getElementType ( targetElem ) == 'player') then 
            exports.global:sendLocalMeAction(source, "tinteste spre ".. getPlayerName(targetElem) ..".") 
        elseif (getElementType ( targetElem ) == 'vehicle' ) then 
            exports.global:sendLocalMeAction(source, "tinteste spre ".. getVehicleName(targetElem) ..".") 
        end 
    end 
end 
addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTarget ) 

Do you mean that?

Link to comment

I don't know, maybe you can make a check to see if the target is the same as current.

Something like this could work:

local targeting = {} 
  
function onPlayerTarget ( targetElem ) 
    if (targetElem and isElement(targetElem) and targeting[source] ~= targetElem) then 
        if (getElementType ( targetElem ) == 'player') then 
            exports.global:sendLocalMeAction(source, "tinteste spre ".. getPlayerName(targetElem) ..".") 
        elseif (getElementType ( targetElem ) == 'vehicle' ) then 
            exports.global:sendLocalMeAction(source, "tinteste spre ".. getVehicleName(targetElem) ..".") 
        end 
        targeting[source] = targetElem 
    end 
end 
addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTarget ) 

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