Jump to content

Fallout New Vegas GECK & Scripting Help 101


Recommended Posts

Posted

 

So the RGB value should be 00172228

Why are there 8 numbers?  And why would it have leading zeroes?  And, couldn't that possibly be a problem?  IIRC, kid had a number issue in a C++ script that we couldn't figure out until I remembered that a leading zero made it think it was in octal.

 

Leading zeroes are for readability. There are 8 digits because it's a 32bit number. In hex, a 32bit value is 4 octets that are one byte each, and one byte is represented by two digits in hex.

 

There's no octal in geck scripts, or anything but base10 decimal for that matter. ;)

Posted

Update. eh, I'm going to read Pridelsayer's post.

 

OK. How do you get that value that you get?

 

Prideslayer's method.

let cc := (15 * 256 * 256) | (240 * 256) | 255

R ==40

G==34

B==23

 

 

(R * B+1 * B+1) + G * B+1 + B

 

 

(23040) + (816) + 23 == 23879

 

how do you get 00172228 ?

 

First, I messed up the order of RGB in my original post, where I calculated BGR instead. See  my edit.

prideslayer formula is R + (G * 256) + (B * 256 * 256) = R + 256 * ( B + ( G * 256) ) .

 

Each color ends up occupying one byte in a four byte number.

 

Sorry we are getting quite technical.

Posted

In the initial example, Blue was 255.  255 + 1 = 256.  If Blue had been 254, it would be (stuff * Blue + 2).  Very unreliable way to calculate, I would think.

 

 

 

56e97e8e68ca2414f127eb6db0b8f96e3fbb9434

 

 

 

EDIT:  Of course, since you are setting the color, you know what you'd want the value of Blue to be.  It seems like the GECK kind of way of doing things, though.  ;)

Posted

prideslayer formula is R + (G * 256) + (B * 256 * 256) = R + 256 * ( B + ( G * 256) ) .

No no, my formula is:

 

(R * 256 * 256) + (G * 256) + B

 

R * 256 * 256 == R << 16

G * 256 == G << 8

B = B

Posted
Leading zeroes are for readability. There are 8 digits because it's a 32bit number. In hex, a 32bit value is 4 octets that are one byte each, and one byte is represented by two digits in hex.

 

There's no octal in geck scripts, or anything but base10 decimal for that matter. ;)

 

But isn't NVSE written in C++, and thus having...something...*cringe* < insert appropriate blushy face of shame >

Guest tomm434
Posted

yes, I got the Idea.

 

I take RGB (89;34;89)

 

 

Then I assume that they are Decimal and transfrom them into HEXa

 

592259

 

then I add "00" prefix so it looks awesome

 

00592259

 

 

Jaam, I understand your method now too.

 

 

Thanks, Pride, thanks Jaam!!

 

Posted

looks like everybody posting at the same time. :)

Yes, looks like.

 

IMHO there's only one right, "readable" way to do this.

 

A 32bit color takes this format in hex:

 

0xAARRGGBB

 

AA is the alpha channel value

RR is the read channel value

GG is the green channel value

BB is the blue channel value

 

Each one is one byte. Two hex digits from 0x00 - 0xFF.

 

When you have a single one of those values as a byte in that range, you need to get them into the proper position in the 32bit value. You do that by shifting each one to the left by enough bits to get it into the right spot, and then ORing or ADDing them all together.

 

Shifting left by 8 bits is the same as multiplying by 256, and turns the value 0xNN into 0xNN00. Shifting left by 16 bits is the same as multiplying by 16384 (aka 256 * 256, aka shifting left by 8 twice) and turns 0xNN into 0xNN0000.

 

This is not directed to you jaam, I know you know how to handle hex/binary values; just explaining in pedantic detail for everyone else, especially tomm since he seems to need a primer on hex. ;)

Posted

I finally saw all the posts. :)

 

The way NVSE is coded, the R byte is the least significant byte. Which color do we get with

 

SetHairColor 255

 

It should be red.

 

 

EDIt: multi posting again

Posted

 

Leading zeroes are for readability. There are 8 digits because it's a 32bit number. In hex, a 32bit value is 4 octets that are one byte each, and one byte is represented by two digits in hex.

 

There's no octal in geck scripts, or anything but base10 decimal for that matter. ;)

 

But isn't NVSE written in C++, and thus having...something...*cringe* < insert appropriate blushy face of shame >

 

It is, but that doesn't matter.

 

It's literal values in the C++ sourcecode that are affected by prefixes according to the rules of the C++ language and compiler. This is geck script code, not C++ code being run through a C++ compiler.

Guest tomm434
Posted

It should be red.

 

 

It's red. I checked.

Posted

I finally saw all the posts. :)

 

The way NVSE is coded, the R byte is the least significant byte. Which color do we get with

 

SetHairColor 255

 

It should be red.

 

 

EDIt: multi posting again

Ah so it *is* in BGR?

 

Figures.. goddamn gamebryo.

Posted

In that case you want this instead:

 

(blue << 16) | (green << 8) | red

 

OR

 

(blue << 16) + (green << 8) + red

 

OR

 

(blue * 256 * 256) | (green * 256) | red

 

OR

 

(blue * 256 * 256) + (green * 256) + red

 

 

All four of those mean exactly the same thing.

Guest tomm434
Posted

In that case you want this instead:

 

(blue << 16) | (green << 8) | red

 

OR

 

(blue << 16) + (green << 8) + red

 

OR

 

(blue * 256 * 256) | (green * 256) | red

 

OR

 

(blue * 256 * 256) + (green * 256) + red

 

 

All four of those mean exactly the same thing.

 

Oh, I get last 2 examples but what does "<<" mean?

 

Posted

<< is shiftleft as I explained a post or two back.

 

Shiftleft means "take this value and move it X bits to the left".

 

A byte is 8 bits, so shifting left 8 bits means "moving" the value one byte to the left. Moving a value 8 bits left is the same as multiplying it by 256.

 

0xNN << 0 == 0x00NN

0xNN << 4 == 0x0NN0

0xNN << 8 == 0xNN00

 

There is a shiftright >> as well that does the opposite.

Guest tomm434
Posted

YES! Now I remember something like that back from school.

Posted

The shift should be preferred in general, since it's almost always faster than multiplication or division. Now the geck script language, being interpreted, might just be converting shifts to mul/div's for you at run time, but if it's actually translating them to native shifts (which would not be difficult for it), it'll be slightly faster -- and in a loop, it'll be *much* faster.

Guest luthienanarion
Posted

Ok, now whats a single "|" mean? :)

 

Binary/bitwise OR. Gamebryo scripting doesn't support bitwise operators, as far as I know.

Posted

In that case you want this instead:

 

(blue << 16) | (green << 8) | red

 

OR

 

(blue << 16) + (green << 8) + red

 

OR

 

(blue * 256 * 256) | (green * 256) | red

 

OR

 

(blue * 256 * 256) + (green * 256) + red

 

 

All four of those mean exactly the same thing.

Ok I'll just take that last one and run with it, before my brain explodes in a rainbow of colors :)
Posted

 

Ok, now whats a single "|" mean? :)

 

Binary/bitwise OR. Gamebryo scripting doesn't support bitwise operators, as far as I know.

 

It doesn't natively, but NVSE added it. I doublechecked and it's there, and I have been actively using it for some time to apply the inuse flag bitmask to variable04.

Posted

 

Yeah, it works just fine with objects, but not with character's X angle (-90 to 90 degrees). Works fine with Z axis though.

Yep, working on timer right now.

Trig functions are used to find X angle.

set iUnits to player.GetDistance ffTarget
set posZ to ffTarget.GetPos Z
set playerZ to player.GetPos Z
set offsetZ to posZ - playerZ
set gg to 0 - (offsetZ/iUnits)
set arctan to tan gg 1
player.setangle x arctan

 

Not sure what you achieve there, but if you're going to find the X-heading angle to the player on a certain ref, I would be interested in understanding more. My formula implies both sin and sqrt, yours only arctan >>> should be definetely faster

Posted

X-heading angle to the player on a certain ref

exactly. Btw, it will be great if you can share your code, I would love to see it, bc arctan is the only way I found how to implement it =\

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...