Garry's Mod

Garry's Mod

105 个评价
VR Core
3
   
奖励
收藏
已收藏
取消收藏
素材类型: 插件
插件类型: 服务器内容
插件标签: 建筑, 写实
文件大小
发表于
18.144 KB
2020 年 7 月 26 日 下午 9:12
1 项改动说明 ( 查看 )

订阅以下载
VR Core

描述
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 条留言
fox gunner 2023 年 6 月 1 日 下午 4:46 
can you use this mod for posing for rage doll model?:d4_science:
Secret Ingredient (Chives) 2023 年 4 月 28 日 下午 7:08 
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 2023 年 1 月 20 日 下午 2:59 
is this client side?
MAXIDE 2022 年 12 月 27 日 下午 3:28 
steam vr?
Vurv 2022 年 10 月 12 日 下午 1:33 
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  [作者] 2022 年 9 月 15 日 下午 7:08 
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 2022 年 9 月 6 日 上午 12:24 
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 2022 年 3 月 8 日 上午 10:47 
how the do the script
s1ugcat 2021 年 12 月 31 日 下午 10:56 
hey if you could add a function that returns the players' HMD position and angle that would be rad
Nakkitsunami 2021 年 5 月 12 日 上午 1:39 
@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