.:`=-~rANdOm~`-=:.

Tech Lounge => Programming => Topic started by: Krasher on April 10, 2010, 07:29:04 PM

Title: Learning Simple E2 with Kräsher!
Post by: Krasher on April 10, 2010, 07:29:04 PM
(http://www.lib.umich.edu/graphics/vrc/logo_textured_full_e2.jpg)



Prop/Player Raver

Lets begin by learning a SIMPLE color changing E2 that makes you change colors!

Open a NEW E2 and type this on the first line.
Code: [Select]
interval(10)This makes the E2 repeat itself every 10 milliseconds or so. (I am not sure what time increment it is.)

On line 2, type this out.
Code: [Select]
owner():setColor(random(255),random(255),random(255))The function 'owner' means that whatever the code after it says, it happens to the player who spawned it. The random(255) means it is randomlly picking a color from the RGB scale for each R, G, and B. RGB = Red, Green, Blue.

Simple Varition
If you want the PROP this is attached to to rave light up. Use this code..
Code: [Select]
@name Prop raver
Prop=entity():isWeldedTo()

interval(10)
 Prop:setColor(random(255),random(255),random(255))
Prop=entity():isWeldedTo() is a function that states that the prop that the E2 is attached to should have the code run on it, When the string 'Prop' is stated, followed by a code.

Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on April 10, 2010, 07:56:41 PM
User Materials
Lets follow up with an E2 that can change your material!

Full Code:
Code: [Select]
@name Tutorial E2 2
# This E2 changes your material #
owner():setMaterial("phoenix_storms/chrome")

Explanation:
Code: [Select]
owner():setMaterial("phoenix_storms/chrome")
owner is the player who spawned the E2, in other words. It's you.
setMaterial is the function that you know, states that you are setting the entity's (owner) material.
("phoenix_storms/chrome") is the part that goes after setMaterial. This is the part where you can type in any material you want!
Title: Re: Learning Simple E2 with Kräsher!
Post by: ƒąĢĢǿŧ™ on April 10, 2010, 07:57:55 PM
THX ! U R KEWL
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on April 10, 2010, 08:17:07 PM
Player Trails
Now lets do player trails! This will put a trail on you! Just like a prop trail! :D

Full Code:
Code: [Select]
@name Tutorial E2 3
# This E2 puts a trail on your player. #
 owner():setTrails(3,50,5,"trails/smoke",vec(255,0,0),200)
Explanation:
owner is the player who spawned the E2, in other words. It's you.
setTrails is the function that states that you are setting the entity's (owner) trail.
"trails/smoke" is the part that goes after setTrails. This is the part where you can type in any trail you want!
vec(255,0,0) is the vector color.  the 3 numbers after vec are the color in R, G, and B.
setTrails(3,50,5) the 3 numbers after setTrails are Start Size, End Size, and Length, in that order.
Title: Re: Learning Simple E2 with Kräsher!
Post by: Tomcat on April 10, 2010, 08:54:23 PM
lol
for forgot 2 main numb things


multiplying matrices by decimals


i could do that in ma sleep



jk
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on April 10, 2010, 09:22:08 PM
Simple Hologram
This is a LITTLE bit more advanced, :P.

Full Code:
Code: [Select]
@name Tutorial E2 5
@persist Timer
# This E2 makes a cube holo that spins :D #
interval(0.5)
Me = owner()
Chip = entity()
T = Timer
Timer = Timer+1*1
if(first()) {holoCreate(1)}

holoModel(1,"cube")
holoAng(1,ang(T,T,T))
holoPos(1,Chip:pos()+vec(0,0,45))
holoColor(1,vec(255,200,0))
holoScale(1,vec(1,1,1))
Variation of Color:
Change:
Code: [Select]
holoColor(1,vec(255,200,0))To:
Code: [Select]
holoColor(1,vec(random(255),random(255),random(255)))This sets the holo to rave light.

Explanation:
Timer is a variable, that means it is a number that can mean anything depending on the string it is set in.
Timer = Timer+1*1 adds 1 to the variable every interval.
holoCreate states that we are creating a hologram.
holoModel(1,"cube") states that this hologram will be in the shape of a cube :D.
holoAng(1,ang(T,T,T)) sets the angle of the hologram (You can put any numbers in place of T,T,T.)
holoPos(1,Chip:pos()+vec(0,0,45)) states the position of the holo. (in X,Y,Z, format.)
holoColor(1,vec(255,200,0)) states the color of our holo. (in RGB format.)
holoScale(1,vec(1,1,1)) states the scale of the holo. (in length, width, depth, format.)

Title: Re: Learning Simple E2 with Kräsher!
Post by: Frank on April 10, 2010, 09:42:59 PM
Quote
@name Tutorial E2 2
# This E2 changes your material #
owner():setMaterial("phoenix_storms/chrome")

With the above one, you only change your skin ONCE.

BUT, by making some simple modifications, you can get it to switch between different materials by just typing a tiny chat command, see:

Quote
@name Tutorial E2 2
# This E2 changes your material #
interval(20)
if(owner():lastSaid()=="!chrome"){owner():setMaterial("phoenix_storms/chrome")}
if(owner():lastSaid()=="!blkchrome"){owner():setMaterial("phoenix_storms/black_chrome")}

We make an 'if' statement, where "if   'x=z'    'z=c' ".

That means, for example, that if 'x' equals to 'z', 'z' will equal to 'c'.


How to make it easier?
Quote
If I had U$S2000, I'd buy an awesome computer.

Now, let's make it E2!
Quote
If (I had U$S==2000) {Can buy an awesome computer}
Quote
if(Money==2000){AwesomePC==Affordable}

I hope you understand it.

You can also make statements shorter, I'll show you:
Quote
@name Tutorial E2 2
# This E2 changes your material #
interval(20)
if(owner():lastSaid()=="!chrome"){owner():setMaterial("phoenix_storms/chrome")}
if(owner():lastSaid()=="!blkchrome"){owner():setMaterial("phoenix_storms/black_chrome")}

Can be reduced to:

Quote
@name Tutorial E2 2
# This E2 changes your material #
interval(20)
LS = owner():lastSaid()
if(LS=="!chrome"){owner():setMaterial("phoenix_storms/chrome")}
if(LS=="!blkchrome"){owner():setMaterial("phoenix_storms/black_chrome")}



I hope it was useful.
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on April 10, 2010, 10:20:13 PM
I will go over commands later Frank...
Title: Re: Learning Simple E2 with Kräsher!
Post by: me4488 on April 10, 2010, 10:23:28 PM
nice stuffz here  ::)
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on April 10, 2010, 10:52:09 PM
nice stuffz here  ::)
Thank you.
Title: Re: Learning Simple E2 with Kräsher!
Post by: » Magic « on April 11, 2010, 05:35:00 AM
this is wtf fail, for peeps who dont know go here, but me, stick to E2 itself :)
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on April 11, 2010, 08:22:16 AM
this is wtf fail, for peeps who dont know go here, but me, stick to E2 itself :)
Nah, its a win. Making use of the Programming Section.
Title: Re: Learning Simple E2 with Kräsher!
Post by: » Magic « on April 11, 2010, 10:11:20 AM
Nah, its a win. Making use of the Programming Section.
i am and have been lol, im currently making soemthing for random since like, 2 dayss ago, gunna go strait in here
Title: Re: Learning Simple E2 with Kräsher!
Post by: philthethrill on April 11, 2010, 12:57:49 PM
hey does anyone know how to make a e2 mine when a button is pressed it blows up
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on April 11, 2010, 01:35:37 PM
hey does anyone know how to make a e2 mine when a button is pressed it blows up

Use Dynamite
Title: Re: Learning Simple E2 with Kräsher!
Post by: Frank on April 11, 2010, 04:19:52 PM
I will go over commands later Frank...

Foo.
Title: Re: Learning Simple E2 with Kräsher!
Post by: Peetah on April 12, 2010, 05:51:26 PM
One thing to note. Always try to make your code as clean as possible. Like followingthe basic code structure that applies to all forms of coding. Anyways, my english has really improved :).
Also, Try to make your code as efficiant as possible. this can be measures when you look at the e2 itself and check the ops. (operations per second). this makes the server less laggy and not do as much work. I would have to point somthing out. How come you used interval of 0.5? like interval(20) is more then enough.
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on April 12, 2010, 07:04:01 PM
Always try to make your code as clean as possible
Example:
Code: [Select]
@name Tutorial E2 9
@outputs V:vector
interval(10)
Me=owner()
Prop=entity():isWeldedTo()

if(owner()) {Prop:applyForce(($V*10+V)*Prop:mass()) V=Me:pos()+vec(0,0,150) - Prop:pos()}

if(owner():keyAttack1()) {Prop:applyForce(($V*10+V)*Prop:mass()) V=Me:pos()+(owner():eye()*-100000) - Prop:pos()}
To:
Code: [Select]
@name Tutorial E2 9
@outputs V:vector
interval(10)
Me=owner()
Prop=entity():isWeldedTo()

if(owner()) {
    Prop:applyForce(($V*10+V)*Prop:mass())
    V=Me:pos()+vec(0,0,150) - Prop:pos()
}

if(owner():keyAttack1()) {
    Prop:applyForce(($V*10+V)*Prop:mass())
    V=Me:pos()+(owner():eye()*-100000) - Prop:pos()
}
Title: Re: Learning Simple E2 with Kräsher!
Post by: Frank on April 13, 2010, 10:44:34 AM
Cool E2, bro.
Title: Re: Learning Simple E2 with Kräsher!
Post by: Peetah on April 15, 2010, 06:10:10 PM
Example:
Code: [Select]
@name Tutorial E2 9
@outputs V:vector
interval(10)
Me=owner()
Prop=entity():isWeldedTo()

if(owner()) {Prop:applyForce(($V*10+V)*Prop:mass()) V=Me:pos()+vec(0,0,150) - Prop:pos()}

if(owner():keyAttack1()) {Prop:applyForce(($V*10+V)*Prop:mass()) V=Me:pos()+(owner():eye()*-100000) - Prop:pos()}
To:
Code: [Select]
@name Tutorial E2 9
@outputs V:vector
interval(10)
Me=owner()
Prop=entity():isWeldedTo()

if(owner()) {
    Prop:applyForce(($V*10+V)*Prop:mass())
    V=Me:pos()+vec(0,0,150) - Prop:pos()
}

if(owner():keyAttack1()) {
    Prop:applyForce(($V*10+V)*Prop:mass())
    V=Me:pos()+(owner():eye()*-100000) - Prop:pos()
}

Very good Krasher. Just like how a real profetional coder would do it. I do respect you Krasher. Very wise for your age. Just dont get carried away with this power.
Title: Re: Learning Simple E2 with Kräsher!
Post by: DoeniDon on May 14, 2010, 07:01:49 AM
Bawmp
Will you ever continue this Krasher?
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on May 14, 2010, 12:56:26 PM
Bawmp
Will you ever continue this Krasher?
I lost all my E2 when I got that virus. I will continue when I move on toooo... What do you want to learn?
Title: Re: Learning Simple E2 with Kräsher!
Post by: DoeniDon on May 14, 2010, 01:04:51 PM
I lost all my E2 when I got that virus. I will continue when I move on toooo... What do you want to learn?
That one Lua Virus there or a different one?
And I dunno, knowing how to make these walking Ragdolls OR how to make these floating balls following your command (bad description, inorite) would be awesome.
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on May 14, 2010, 01:08:07 PM
That one Lua Virus there or a different one?
And I dunno, knowing how to make these walking Ragdolls OR how to make these floating balls following your command (bad description, inorite) would be awesome.
Floating balls?
Title: Re: Learning Simple E2 with Kräsher!
Post by: DoeniDon on May 14, 2010, 01:10:02 PM
Floating balls?
Yes. They make Zombie Sounds, and when you for example type !attack, they attack a close player. Really don't know how to describe it lol.
But the walking Ragdoll would be far more interesting. I would love you forever if you would do that one <3
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on May 14, 2010, 01:11:44 PM
Yes. They make Zombie Sounds, and when you for example type !attack, they attack a close player. Really don't know how to describe it lol.
But the walking Ragdoll would be far more interesting. I would love you forever if you would do that one <3
k, loading gmod to show everyone Bone Entities on ragdolls.
Title: Re: Learning Simple E2 with Kräsher!
Post by: Peetah on May 14, 2010, 02:32:29 PM
What your talking about is BALLS OF STEEL. I hate that dam e2. Its a good e2, but abused so much its not even funny.
Title: Re: Learning Simple E2 with Kräsher!
Post by: » Magic « on May 14, 2010, 04:09:48 PM
I ban people for using that e2
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on May 14, 2010, 04:42:24 PM
What your talking about is BALLS OF STEEL. I hate that dam e2. Its a good e2, but abused so much its not even funny.
Bone entites are not BoS.
Title: Re: Learning Simple E2 with Kräsher!
Post by: Sanders on May 14, 2010, 05:54:59 PM
Bone entites are not BoS.

He is refering to the floating balls bein Balls of Steel

For reference to everyone, bone is what it sounds like, the specific parts of a ragdoll.
Title: Re: Learning Simple E2 with Kräsher!
Post by: Peetah on May 16, 2010, 02:53:01 PM
gets pretty complicated once you get to the animating the bones part. use a timer.
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on June 30, 2010, 06:49:57 PM
Arrays
Lets do some simpler arrays, maybe one that prints every players name in the server :D.

Full Code:
Code: [Select]
@name Array Test
@persist [Array Players]:array Total

runOnChat(1)

LastS=owner():lastSaid():lower()

Total=findByClass("player")
Players=findToArray()

for(I=1,Players:count()){
    Array[I,string]=Players[I,entity]:name()

if(LastS=="/run"){
for(K=1, Array:count()){
    print(Array[K,string])
        }
    }
}
Explanation:
runOnChat(1) makes the e2 trigger-able by the chat.
LastS=owner():lastSaid():lower(), this is a variable I made that will make life easier.
findByClass("player") is the part where we find all the players.
findToArray() is the part where we put it into an array. I put mine into a variable. (Players)
for(I=1, Player:count())  this function (for) lets me set up my arrays. I (or 1) is our index, Player:count() is the number of players. So it is basically for(1 to 4) (Implying we have 4 people in the server.)
Array[I,string]  tell the e2 that our array 1 (I) will be a string. (Basically saying: Array 1 (or I) is a string)
Players[I,entity]:name()  Players will be put into an array. The array tells the e2 that we will classify "Players" as an entity. name() Will get the name of the players.
LastS=="/run" ''=='' means 'Is equal to", Basically this line means, If the players last said is /run.
for(K=1, Array:count())  using K as an index this time, then we just count the number of arrays in our previous index. (Amount of players)
print(Array[K,string])  telling the e2 to print the Array (Index) of K as a string.

If you need further help on Arrays, it is best if you steam message me, PM me, or ask me in-game. Arrays can be hard to understand at first, but they are super easy :P.

Title: Re: Learning Simple E2 with Kräsher!
Post by: SheepsAholy on July 01, 2010, 12:24:05 AM
Krasher I'd rather do this:

Code: [Select]
@name Array Test
@persist Players:array

runOnChat(1)
LS = owner():lastSaid():explode(" ")
Clk = chatClk(owner())

if(Clk & LS:string(1) == "/r")
{
findByClass("player")
Players = findToArray()
}

if(Clk & LS:string(1) == "/i")
{
print(Players[LS:string(2):toNumber(),entity]:name())
}

Players:array
will hold all the players the chip finds in the "/r" if-statement (the first if line.)
If you type /r again all the indexes of the old will be replaced with the new find values.

LS = owner():lastSaid():explode(" ")
this is similar to krashers but instead of :lower() its :explode(" ") which turns it into an array.

This array makes an index for each space you type and the value for that index is anything but a space. Example:

this is a test.

Index|Value
1: this
2: is
3: a
4: test.

Clk = chatClk(owner())
You don't have to use this, I do in all my chat cmd e2's just because I believe its good coding practice.

Similar to above, when you have used the /r cmd it will make the Players:array equal to what it finds. And when you type /i <value> it will print what it finds at that index. Example again:

Index | Name
1. Bob
2. Joe
3. Dirt

/i 1 = Bob
/i 2 = Joe
/i 3 = Dirt

Any value under 1 and any value over 3 will still run the chip and print a "space"

also if you do something like below:

/i tom

it will also run the chip but will not be of much help.

but the way the /r is coded, it will run even if you do this:

/r tom

I'm not much of the explainer online meet me ingame and I'm more of a help ;)

P.s sry about stealing you thread krasher :P
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on July 01, 2010, 12:30:33 AM
its k

Arrays are hard to explain online in text
lol xP
Title: Re: Learning Simple E2 with Kräsher!
Post by: SheepsAholy on July 01, 2010, 12:35:22 AM
its 3 a.m. in the morning I'm to sleepy to explain anything accurate online. Had to type that stuff above 3 times and even edit that once to get it decent lol.
Title: Re: Learning Simple E2 with Kräsher!
Post by: Krasher on July 01, 2010, 01:24:18 AM
dude

same here

just thought I should update a bit

I was thinking the whole time while writing, "this isn't gonna make any sense"