Wednesday, 13 January 2010

Valkyrie Radio

As noted in the opening post, I made something called the Valkyrie radio system. Since this is a perfect example of the cool and/or odd stuff I come up with on a whim in Gmod, I suppose it's a fitting first addition to this blog.

I was considering the upcoming redesign on a lot of my drones and one of their important elements is that they can communicate needs and requirements by text strings, but before they just used the chat and would flood it quite rapidly, making it unusable to players. My thought then was to create a kind of separate chat that the different drones could use different parts of, to talk to different drones and all the drones of their kind as well. A Hephaestus drone could issue a request to the Hermes drone chat after finding out from another Hephaestus on it's chat that it's missing a component for something.

So naturally this would mean having either an internal chat or a series of global variables. Since I'd only be able to see how this was operating on a player level I immediately began working on it as something I could see in my chat and in hints, so it quickly developed into the Valkyrie radio that has a bunch of functions players can use.

I figured having it be entirely chat-based would be dull and boring, so I made a nice hologram-based selection board for players to manually choose their frequency (The frequency determining which global variable string their radio listens to). The frequency is a number, corresponding to a global variable entry, and the radio prints to the user's chat what string is stored in that entry whenever it finds that it has changed. Users can enter a new message into the variable and it pops up in the chat of other players, but not the general chat.

This is a handy use of print(S) because it only prints to the owner's chat, you need to use concmd("say "+S) to have it print to the general chat, so I'm essentially using a limitation as a basis for expansion.



Anyways, on to the actual code:

@name Valkyrie Radio
@outputs Freq
@persist [Key LMe Mes]:string O:entity Hist:array
@persist H D R Cha Alp

if(first()){
Freq=1 #Default freqency
Cha=20 #Channels
Key="vr" #Radio keyphrase

gSetGroup("valkyrie_radio")
gShare(1)
O=owner()
if(gGetEnt(O:steamID())){
hint("==Valkyrie Radio==",4)
hint("=You already have a radio active",3)
hint("=Use 'dest"+gGetEnt(O:steamID()):id()+"' to destroy it",3)
selfDestruct()
}
else{
gSetEnt(O:steamID(),entity())

Freq=min(1,Freq)
Freq=min(Freq,Cha)
Cha=min(Cha,35)
Key="["+Key+"]"

hint("==Valkyrie Radio Enabled==",6)
hint("=Radio Frequency "+Freq+"=",5)
hint("=You have "+Cha+" channels available",5)
hint("=Your radio keyphrase is "+Key,5)
hint("=See your current frequency with 'freq?'",5)
hint("=Use 'freq++' and 'freq--' to manually change frequency",5)
hint("=Use 'freq ch' to select a frequency from all channels",5)
hint("=Use 'print N' to print N number of messages from the history",5)
hint("=Use 'dest"+entity():id()+"' to make your radio self-destruct",5)
hint("=Simply preface your message with your keyphrase to broadcast",5)

R=(360*ceil(Cha/10))/Cha
D=3+max(1,floor(Cha/10))
entity():setColor(vec(255,215,0))
entity():setMaterial("models/combine_advisor/body9")

holoCreate(1)
holoScaleUnits(1,vec(5,5,5))
holoModel(1,"hqicosphere2")
Cha++
H=2

Alp=0
}
}
if(first()|H<=Cha){ interval(1000) while(H<=Cha){ P=holoEntity(1):forward()*(D+H/2) P=P:rotate(ang(R*H,90,0)) P+=holoEntity(1):pos() holoCreate(H,P) holoScaleUnits(H,vec(3,3,3)) holoModel(H,"hqicosphere2") holoAlpha(H,120) holoParent(H,1) H++ } } else{ runOnTick(1) runOnChat(1) } if(tickClk()|chatClk()){ Mes=gGetStr(Freq) #Chat reporting if(Mes!=LMe & Mes){ print(Key+" "+Mes) Hist:pushString(Mes) if(Hist:count()>10){Hist:remove(1)}
LMe=Mes
}

Chat=O:lastSaid()
C=Chat:lower():find(Key)
hideChat(C)
if(chatClk(O) & C){
Lo=Chat:lower()
#Changing frequency
if(Lo:find("freq ch")){
holoPos(1,O:shootPos()+O:eye()*25)
holoAng(1,O:eye():toAngle())
Alp=1
}
#Manual frequence increasing
elseif(Lo:find("freq++")){
Freq+=(Freq>=Cha ? 0 : 1)
Hist=array()
hint("=Radio Frequency "+Freq+"=",3)
}
#Manual frequency decreasing
elseif(Lo:find("freq--")){
Freq-=(Freq<=1 ? 0 : 1) Hist=array() hint("=Radio Frequency "+Freq+"=",3) } #Frequency reporting elseif(Lo:find("freq?")){ hint("=Radio Frequency "+Freq+"=",3) } #History printing elseif(Lo:find("print ")){ N=min(Hist:count(),Lo:explode(" ")[2,string]:toNumber()) Hi=1 while(Hi<=N){ String=Hist[Hi,string] print(Key+" "+String) Hi++ } } #Self-destruct elseif(Lo:find("dest"+entity():id())){ gSetNum(O:steamID(),0) selfDestruct() } #Chat sending else{ Na=O:name() String=Chat:right(Chat:length()-Key:length()) Time="-{"+time("hour")+":"+time("min")+":"+time("sec")+"}" gSetStr(Freq,Na+" -"+String+Time) } } #Holographic frequency interface if(Alp & O:shootPos():distance(holoEntity(1):pos())<=30){ SP=O:shootPos() M=0 while(M<=Cha){ Ent=holoEntity(M) Pos=Ent:pos() Dis=SP:distance(Pos) PP=SP+O:eye()*Dis if(PP:distance(Pos)<=2){ holoColor(M,vec(1,0.8,0)*255) holoAlpha(M,(M>1 ? 200 : 255))
if(O:keyUse() & Alp){
if(M>1 & M!=Freq){
Freq=M
Hist=array()
hint("=Radio Frequency "+Freq+"=",3)
}
elseif(M==1|M==Freq){
hint("=Frequency change cancelled=",3)
}
Alp=0
}
}
else{
In=(255/Cha)*M
Col=(M==Freq ? vec(0,255,0) : vec(1,0.8,0)*In)
Col=(M==1 ? vec(1,1,1)*255 : Col)
holoColor(M,Col)
holoAlpha(M,(M>1 ? 120 : 255))
}
M++
}
}
elseif(Alp){
Alp=0
hint("=Frequency change cancelled=",3)
}

A=0
while(A<=Cha & !Alp){
holoAlpha(A,0)
A++
}
}

No comments:

Post a Comment