Jump to content

Help with script :$


novo

Recommended Posts

Maybe this:

  
function invisible ( key, keyState ) 
local vehicles = getElementsByType ( "vehicle" ) 
local state = "Hiding" 
  if ( keyState == "down" ) then 
    setElementAlpha ( vehicles, 255 ) 
  end 
  outputChatBox ( "[iNFO]: Currently ".. state .." cars." ) 
end 
  
  
addEventHandler("onPlayerJoin", 
function(player) 
bindKey ( player, "F1", "up", invisible ) 
end 
) 
  

Help plz ^^

Link to comment

Lol that's terribly wrong..

And setElementAlpha will make the car invisible but you can still see the shadow, headlights and the ped controlling it..

  
bindKey('f1', 'down', function() 
   for _, player in ipairs(getElementsByType('player')) do  
       if player ~= localPlayer then 
             setElementDimension(getPedOccupiedVehicle(player), 1) 
             setElementDimension(player, 1)  
       end 
   end 
end 
  

Note: This script is client-side.

Note2: The script does not handle people who join AFTER the button was pressed. So you will either have to press it again when somebody joins the server or re-script it somehow.

Note3: The script assumes you want vehicles that are controlled by players to be invisible, not parked vehicles.

Link to comment

I made this:

  
  
addEventHandler("onPlayerJoin", 
bindKey('F1', 'down', 
function() 
   for _, player in ipairs(getElementsByType('player')) do 
       if player ~= localPlayer then 
             setElementDimension(getPedOccupiedVehicle(player), 1) 
             setElementDimension(player, 1) 
             outputChatBox("[iNFO]: Currently Hidding Vehicles.", player ) 
       end 
   end 
end 
)) 
  
bindKey('F1', 'up', 
function() 
   for _, player in ipairs(getElementsByType('player')) do 
        if ( getElementDimension ( source ) == 1 and seat == 0 ) then 
             setElementDimension(getPedOccupiedVehicle(player), 0) 
             setElementDimension(player, 0) 
             outputChatBox("[iNFO]: Currently Showing Vehicles.", player ) 
end 
end 
end 
) 
  
--[[ 
addEventHandler("onPlayerSpawn", 
function( thePlayer, key ) 
    if ( getElementDimension ( source ) == 1 and seat == 0 ) then 
             setElementDimension(getPedOccupiedVehicle(player), 1) 
             setElementDimension(player, 1) 
    end 
end 
) 
]]-- 
  

But when i press F1, it hide cars and show 4 texts. ON - OFF then again.

Plz help <3

PD: Sorry 4 double post.

Link to comment
local shown = true  
  
bindKey('F1', 'down', 
function() 
   for _, player in ipairs(getElementsByType('player')) do 
        if (player ~= localPlayer) then 
            if (show) then 
                setElementDimension(getPedOccupiedVehicle(player), 1) 
                setElementDimension(player, 1) 
                outputChatBox("[iNFO]: Currently Hidding Vehicles.", player ) 
            else 
                setElementDimension(getPedOccupiedVehicle(player), 0) 
                setElementDimension(player, 0) 
                outputChatBox("[iNFO]: Currently Showing Vehicles.", player ) 
            end 
        end 
    end 
    shown = not shown 
end) 

Link to comment
local hiding = false 
  
addEventHandler("onClientResourceStart", resourceRoot,  
  function() 
    bindKey('F1', 'down', hideVehicles) 
    bindKey('F1', 'up', hideVehicles) 
  end 
) 
  
function hideVehicles(key, state) 
  if (hiding and state == 'down') or (not hiding and state == 'up') then  
    return false  
  end 
  hiding = not hiding 
  for _, player in ipairs(getElementsByType('player')) do 
    if player ~= localPlayer then 
      setElementDimension(getPedOccupiedVehicle(player), hiding and 1 or 0) 
      setElementDimension(player, hiding and 1 or 0) 
    end 
  end 
  outputChatBox(hiding and "[iNFO]: Currently Hiding Vehicles." or "[iNFO]: Currently Showing Vehicles.") 
end 

PS: meh , already posted. well mine is a little different :S

Link to comment

Thanks Solidsnake14.

Thanks Aibo.

Thanks TAPL for correct my dudes of this.

@Aibo: I'll use Solidsnake14 code, because it's easyer to understand for me. Anyways, thank you for give me another method to script it.

Bye.

EDIT: @Solidsnake14: It's not working :S

EDIT:

  
local hiding = true 
  
addEventHandler("onClientResourceStart", resourceRoot, 
  function() 
    bindKey('F1', 'both', hideVehicles) 
  end 
) 
  
function hideVehicles(key, state) 
  if (hiding and state == 'down') or (not hiding and state == 'up') then 
    return false 
  end 
  hiding = not hiding 
  for _, player in ipairs(getElementsByType('player')) do 
    if player ~= localPlayer then 
      setElementDimension(getPedOccupiedVehicle(player), hiding and 1 or not hiding and 0) 
      setElementDimension(player, hiding and 1 or not hiding and 0) 
    end 
  end 
  outputChatBox(hiding and "[iNFO]: Currently Hiding Vehicles." or "[iNFO]: Currently Showing Vehicles.") 
end 
  

It has a bug, when i press F1 it's not showing, but i need to keep it "pushed". If i stop "push" to key, the cars already are showing.

Plz help.

Link to comment

well that't what i meant by "mine is different". it's not a bug, it's supposed to work that way.

since you've used both 'up' and 'down' keybinds yourself, i assumed that is how you wanted it to work.

well anyway, if you want switching:

local hiding = false 
  
function hideVehicles(key, state) 
  hiding = not hiding 
  for _, player in ipairs(getElementsByType('player')) do 
    if player ~= localPlayer then 
      setElementDimension(getPedOccupiedVehicle(player), hiding and 1 or 0) 
      setElementDimension(player, hiding and 1 or 0) 
    end 
  end 
  outputChatBox(hiding and "[iNFO]: Currently Hiding Vehicles." or "[iNFO]: Currently Showing Vehicles.") 
end 
bindKey('F1', 'down', hideVehicles) 
  

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