Jump to content

How hide an object from the player(client-side)?


NoName74

Recommended Posts

Posted
Code please..

Server-side:

if weapon1 == "M95 BARRETT" then 
    m95a = createObject(1900, x,y,z) 
    attachElementToBone(m95a, source, 12, 0,0,0,0,-90,0) 
    triggerClientEvent (source, "hiderweap", source, m95a) 
end 

Client-side: 
function hiderweap(ident) 
?????????????? 
end 
addEvent("hiderweap", true) 
addEventHandler("hiderweap", getRootElement(), hiderweap) 

It's all I have...

setElementVisibleTo 

This does not work with all entities - vehicles, players and objects are exempt.(с) wiki

Posted
Code please..

Server-side:

if weapon1 == "M95 BARRETT" then 
    m95a = createObject(1900, x,y,z) 
    attachElementToBone(m95a, source, 12, 0,0,0,0,-90,0) 
    triggerClientEvent (source, "hiderweap", source, m95a) 
end 

Client-side: 
function hiderweap(ident) 
?????????????? 
end 
addEvent("hiderweap", true) 
addEventHandler("hiderweap", getRootElement(), hiderweap) 

It's all I have...

setElementVisibleTo 

This does not work with all entities - vehicles, players and objects are exempt.(с) wiki

Ow, why don't you create it in client side then and set its alpha to 0?

Posted
Ow, why don't you create it in client side then and set its alpha to 0?

This object should see all the players, including the client-player, to which is attached the object.

I need to hide the object when the client-player is aiming.

That's because object prevents aim. .-. http://i.imgur.com/mlEtLK1.png

Posted
  
if weapon1 == "M95 BARRETT" then 
    m95a = createObject(1900, x,y,z) 
    attachElementToBone(m95a, source, 12, 0,0,0,0,-90,0) 
    setElementVisibleTo(m95a,root,false) 
    setElementVisibleTo(m95a,source,true) 
end 
  

Posted
  
if weapon1 == "M95 BARRETT" then 
    m95a = createObject(1900, x,y,z) 
    attachElementToBone(m95a, source, 12, 0,0,0,0,-90,0) 
    setElementVisibleTo(m95a,root,false) 
    setElementVisibleTo(m95a,source,true) 
end 
  

Function "setElementVisibleTo" not works for the elements with type "player", "vehicle" and "object". .-.

But thanks for answer. ^^,

Posted (edited)

got it how to do it.

  
  
if weapon1 == "M95 BARRETT" then 
    m95a = createObject(1900, x,y,z) 
    attachElementToBone(m95a, source, 12, 0,0,0,0,-90,0) 
    setElementData(source,"objectperm",true) 
end 
if getElementData(source,"objectperm") == true then 
setElementAlpha(m95a,255)  
else 
setElementAlpha(m95a,0) 
end 
  

Edited by Guest
Posted (edited)

got it how to do it.

  
  
if weapon1 == "M95 BARRETT" then 
    m95a = createObject(1900, x,y,z) 
    attachElementToBone(m95a, source, 12, 0,0,0,0,-90,0) 
    setElementData(source,"objectperm",true) 
end 
if getElementData(source,"objectperm") == true then 
setElementAlpha(m95a,255)  
else 
setElementAlpha(m95a,0) 
end 
  

Edited by Guest
Posted

got it how to do it.

  
  
if weapon1 == "M95 BARRETT" then 
    m95a = createObject(1900, x,y,z) 
    attachElementToBone(m95a, source, 12, 0,0,0,0,-90,0) 
    setElementData(source,"objectperm",true) 
end 
if getElementData(source,"objectperm") == true then 
setElementAlpha(m95a,255)  
else 
setElementAlpha(m95a,0) 
end 
  

Posted

got it how to do it.

  
  
if weapon1 == "M95 BARRETT" then 
    m95a = createObject(1900, x,y,z) 
    attachElementToBone(m95a, source, 12, 0,0,0,0,-90,0) 
    setElementData(source,"objectperm",true) 
end 
if getElementData(source,"objectperm") == true then 
setElementAlpha(m95a,255)  
else 
setElementAlpha(m95a,0) 
end 
  

Posted
got it how to do it.

Yea, great idea! But... I can't change Alpha of object when I aiming. I'm so stupid. ><

Don't punish yourself, you're just new and I like people who put their efforts in scripting.

This is a client side script

  
function targetingActivated ( target ) 
    if  target  and getElementType (target) == "object" then 
setElementAlpha(target, 0) -- 0 will make it invisible 
    end 
end 
addEventHandler ( "onClientPlayerTarget", getRootElement(), targetingActivated ) 

Can you please explain more what exactly are you trying to do?

Posted
Can you please explain more what exactly are you trying to do?

http://i.imgur.com/DcWG10K.png - I attach object to player. This object prevents me to aim. I want hide this object from myself when I aiming.

The other players must continue to see this object.

EDIT:

Maybe I should use it?

getAttachedElements 

Posted

I haven't seen your whole code, so I just give you an example so that you can edit it:

local m95a = createObject( 1337, 0, 0, 0) 
attachElements(m95a, localPlayer, 0, 3, 0) 
  
bindKey( "mouse2", "down", function ( ) 
    local slot = getPedWeaponSlot( localPlayer ) 
     
    if slot == 6 then 
        setElementAlpha ( m95a, 0 ) 
    end 
     
end ) 
  
bindKey( "mouse2", "up", function ( ) 
    local slot = getPedWeaponSlot( localPlayer ) 
     
    if slot == 6 then 
        setElementAlpha ( m95a, 255 ) 
    end 
     
end ) 

Posted

Damn. I just replace

triggerClientEvent (source, "hiderweap", m95a) 

with

triggerClientEvent (source, "hiderweap", source, m95a) 

and now I can change Alpha of object m95a in client-side. .-.

Thanks all for answers. You'e the best. ^^,

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