Garry's Mod

Garry's Mod

100 ratings
VR Core
3
   
Award
Favorite
Favorited
Unfavorite
Content Type: Addon
Addon Type: Server content
Addon Tags: Build, Realism
File Size
Posted
18.144 KB
26 Jul, 2020 @ 9:12pm
1 Change Note ( view )

Subscribe to download
VR Core

Description
An e2 extension that works with VRmod to allow e2 developers to integrate VR functionality into their builds

If the example script fails to compile run
wire_expression2_extension_enable vrcore
in console

Function list
vrSetPlayer(entity)
Sets the player the chip is listening to to the current player

vrStopRequesting()
Stops listening to the current player

number vrPlayerInVR()
Returns if a player is in vr

vec2 vrMovement()
Returns the movement of a player(Or steering(x,y) if they are driving)

number vrPrimaryFire()
Returns primary fire

number vrPrimaryFire2()
Returns the amount of trigger pull on index

number vrSecondaryFire()
Returns secondary fire

number vrLeftGrab()
returns 1 if the user has their left hand closed
number vrRightGrab()
returns 1 if the user has their right hand closed

vec vrRightHandPos()
returns local position of the right hand relative to player or vehicle

vec vrLeftHandPos()
returns local position of the left hand relative to player or vehicle

angle vrRightHandAng()
returns local angle of the right hand relative to (0,0,0) or vehicle

angle vrLeftHandAng()
returns local angle of the left hand relative to (0,0,0) or vehicle

array vrRightHandWorldAng()
returns an array containing the world position and world ang of the right hand

array vrLeftHandWorldAng()
returns an array containing the world position and world ang of the left hand

number vrForward()
returns the forward control in a vehicle

number vrReverse()
returns the reverse control in a vehicle

number vrTurbo()
Returns the vehicle turbo input

number vrHandbrake()
Returns the vehicle handbrake input

number vrTurret()
Returns the vehicle turret input

Example script
This was used in the first 30 seconds of the video

@name That one Valve "Puzzle" everyone hates
@inputs E:entity Door:entity
@outputs TotalAngle TotalAngle2 RotCount
@persist On AAA LastAAA Grabbed Ply:entity PosAng:array PlySound AngSmoothed
@trigger all
#really ugly example. More to come.
#wire E to a prop on the floor, and wire door to another prop. Turn the crank and the door should rise above the prop on the floor
if(first()){
holoCreate(1)
holoScaleUnits(1,vec(2.5))
holoPos(1,owner():pos())
timer("check",1000)
local Len=10


holoCreate(2,entity():toWorld(vec(0,0,10)),vec(0.2),entity():toWorld(ang()))
holoParent(2,entity())
holoCreate(3,holoEntity(2):toWorld(vec(Len/2,0,0)),vec(1),holoEntity(2):toWorld(ang()))
holoScaleUnits(3,vec(Len,1,1))

holoParent(3,holoEntity(2))

holoCreate(4,holoEntity(3):toWorld(vec(Len/2,0,0)),vec(0.2),holoEntity(3):toWorld(ang()))
holoParent(4,holoEntity(3))
holoCreate(5,holoEntity(4):toWorld(vec(0,0,Len/4)),vec(0.2),holoEntity(4):toWorld(ang(90,0,0)))
holoScaleUnits(5,vec(Len/2,1,1))
holoParent(5,holoEntity(4))
holoColor(5,vec(255,0,0))


}
interval(10)

if(clk("check")){
findByClass("player")
findSortByDistance(entity():pos())
Ply=findResult(1)
if(vrPlayerInVR(Ply))
{
if(!On)
{
print(Ply:name()+" In vr")
}
vrSetPlayer(Ply)
On=1
}
else
{

#print(Ply)
On=0
}
timer("check",1000)
}
if(On){
PosAng=array(vec(0,0,0),ang(0,0,0))


if(vrRightGrab()){

PosAng=vrRightHandWorldPosAng()

if(PosAng[1,vector]:distance(holoEntity(5):pos())<10){
Grabbed=1
}
}
if(vrLeftGrab()){

PosAng=vrLeftHandWorldPosAng()

if(PosAng[1,vector]:distance(holoEntity(5):pos())<10){
Grabbed=1
}
}

if((!vrLeftGrab()) && !vrRightGrab()){

Grabbed=0
}
if(Grabbed){

if(TotalAngle2>1000){
if(!PlySound){
entity():soundPlay(1,soundDuration("doors/garage_stop1.wav"),"doors/garage_stop1.wav")
PlySound=1
}

}else{
PlySound=0
AAA=entity():toLocal(PosAng[1,vector]):toAngle():yaw()
if(RotCount<0){
RotCount=-1
if(AAA<350 &&AAA>45){
AAA=350
}


}
if((AAA-LastAAA)<-270){
RotCount+=1
}
if((AAA-LastAAA)>270){
RotCount-=1
}

TotalAngle2=AAA+(360*RotCount)
LastAAA=AAA
holoAng(2,entity():toWorld(ang(0,AAA,0)))
}


holoColor(5,vec(0,255,0))
}else{
holoColor(5,vec(255,0,0))
}





}else{
Grabbed=0
}
if(!Grabbed){
if(TotalAngle2>0){
TotalAngle2-=2
AAA=TotalAngle2%360
RotCount=floor(TotalAngle2/360)

}else{
if(!PlySound){
entity():soundPlay(1,soundDuration("doors/garage_stop1.wav"),"doors/garage_stop1.wav")
PlySound=1
}
TotalAngle2=0
}
holoAng(2,entity():toWorld(ang(0,AAA,0)))

}


AngSmoothed=AngSmoothed+((TotalAngle2-AngSmoothed)/5)
Door:setPos(E:toWorld(vec(0,0,94+clamp(AngSmoothed/10,0,100))))

if(AngSmoothed>1){PlySound=0}
19 Comments
fox gunner 1 Jun, 2023 @ 4:46pm 
can you use this mod for posing for rage doll model?:d4_science:
The ATM from Breaking Bad 28 Apr, 2023 @ 7:08pm 
I'm running into an issue when sitting in a chair where the hand positions given are offset in the wrong direction by 90 degrees. Is there a GitHub I can submit code changes to?
kinny 20 Jan, 2023 @ 2:59pm 
is this client side?
MAXIDE 27 Dec, 2022 @ 3:28pm 
steam vr?
Vurv 12 Oct, 2022 @ 1:33pm 
No, the issue is returning lua tables in functions that return a "vector" or "angle" e2 type. For example the vrLeftHandPos returns a "vector" e2 type, but might be returning a lua table of three numbers instead of the Vector userdata type.

If it is returning the userdata then there's nothing to change and you're fine
Iron Roadkill  [author] 15 Sep, 2022 @ 7:08pm 
Thanks for letting me know. I no longer am actively maintaining this though but, I am returning arrays instead of tables so hopefully it wont break?
Vurv 6 Sep, 2022 @ 12:24am 
This is a notice that some functionality this extension will likely be broken by wiremod/wire#2399 if you don't convert your ``e2function``s to return proper ``Vector`` and ``Angle`` userdata rather than tables of three numbers.

This is a copy pasted message, I cba to download the addon and check myself if it does contain use of these.
damnp 8 Mar, 2022 @ 10:47am 
how the do the script
s1ugcat 31 Dec, 2021 @ 10:56pm 
hey if you could add a function that returns the players' HMD position and angle that would be rad
Nakkitsunami 12 May, 2021 @ 1:39am 
@rappy, those should be forward and back etc listed above, they work for car controls, also @Iron Roadkill, could you add the hands as entities so stuff like vrRightHandEntity:toWorld(vec(0,0,0)) could be used for example