Jump to content

Setting a class for certain objects


AggrorJorn
 Share

Recommended Posts

Why would you want to only check for objects that can be picked up? If there is a wall between you and the object, the raycast won't see it.

 

Use collision types for this.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I want to display a hand icon on the mouse position when a player can interact with an object. As it is now, the raytrace returns a true when it hits a moddel, thus it prety much always shows a hand icon on screen (walls are also moddels and will activate the hand icon). The hand icon only needs to appear when a raytrace sees a certain moddel of a certain class.

Link to comment
Share on other sites

You could give a setting for models that you want to be picked. pickable = true for example. Then check this setting.

 

hmm, didn't think of that, nice one. For the first time I used a LUA menu style for this (getting a menu option makes it look really professional biggrin.gif)


--hand icon menu
group=grid:AddGroup( "Hand icon" )
group:AddProperty( "Show hand icon", PROPERTY_BOOL )

 

 

this code was added to the switch.lua. If I want to retrieve the state of the bool value from the FPS Controller script, do I have to use the GetKey and Setkey commans for this?

Link to comment
Share on other sites

You could use model:GetKey() or you could set an internal value when the Lua script calls SetKey().

 

function SetKey(model,key,value)

if key=="pickable" then

entity.pickable=tonumber(value)

else

end

end

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I'm not 100% sure how to use the SetKey and GetKey functions. I have the following in the switch.lua:

--hand icon menu
group=grid:AddGroup( "Hand icon" )
group:AddProperty( 'Show hand icon', PROPERTY_BOOL,'showicon')

function SetKey(model,key,value)
if key=="showicon" then
	entity.pickable=tonumber(value)
       end
return 1
end

Is 'showicon' in AddProperty the Key here?

 

 

In the FPScontroller I use a raytrace:


pick=CameraPick(camera,Vec3(GraphicsWidth()/2,GraphicsHeight()/2,2.0),0,0)
	if pick~=nil then
		repeat
			if pick.entity:GetClass()==ENTITY_MODEL then
				break
			end
			pick.entity=pick.entity.parent
		until pick.entity==nil

		-- show hand true or false
		if pick.entity~=nil then
  		 ????GetKey("showicon","true")
	  		  	handIcon = true    
		end
	else
	handIcon = false	

	end

 

At the question marks I need to retrieve if the value is true or false from 'showicon' in the switch.lua. As I understand this is done by the GetKey.

Link to comment
Share on other sites

I'm not 100% sure how to use the SetKey and GetKey functions. I have the following in the switch.lua:

--hand icon menu
group=grid:AddGroup( "Hand icon" )
group:AddProperty( 'Show hand icon', PROPERTY_BOOL,'showicon')

function SetKey(model,key,value)
if key=="showicon" then
	entity.pickable=tonumber(value)
       end
return 1
end

Is 'showicon' in AddProperty the Key here?

 

 

In the FPScontroller I use a raytrace:


pick=CameraPick(camera,Vec3(GraphicsWidth()/2,GraphicsHeight()/2,2.0),0,0)
	if pick~=nil then
		repeat
			if pick.entity:GetClass()==ENTITY_MODEL then
				break
			end
			pick.entity=pick.entity.parent
		until pick.entity==nil

		-- show hand true or false
		if pick.entity~=nil then
  		 ????GetKey("showicon","true")
	  		  	handIcon = true    
		end
	else
	handIcon = false	

	end

 

At the question marks I need to retrieve if the value is true or false from 'showicon' in the switch.lua. As I understand this is done by the GetKey.

 

 

In your set key I think you need to get the entity from the model passed into the function. I think there is some base_Entity() or whatever where you can pass in a model and get the entity (which would really be a lua table object and not an LE TEntity).

 

You would probably need to do the same thing in your picking code as well because I think pick.entity is TEntity and not the lua table object, but I could be wrong there.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...