Help me script edition

This is a moderated forum that collects tutorials, guides, and references for creating Transcendence extensions and scripts.
User avatar
Mutos
Militia Lieutenant
Militia Lieutenant
Posts: 218
Joined: Thu Aug 14, 2008 3:31 am
Location: Near Paris, France
Contact:

Hi Periculi,


So the "T:planet" wouldn't work because of the further restriction to structure-scale instead of world scale as in the planet definition...

Thanks for making the point clear !
@+

Benoît 'Mutos' ROBIN
Hoshikaze 2250 Project
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

What would be the best way of getting what armor or shield is hit in onDamage.

A function that you put in the ship? Is aHitDir where on the ship it gets hit or oriented to the screen?

What about non critical armor?
Crying is not a proper retort!
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

related to my armor question is there a way of telling what armor a station has (without putting it in static data)? I know it overrides it's hp but it does use it for resistances (and maybe other effects that I may mod)
Crying is not a proper retort!
User avatar
Fatboy
Militia Lieutenant
Militia Lieutenant
Posts: 247
Joined: Fri Feb 22, 2008 1:52 am
Location: California

How would you add a check to see if a certain ship is there or not.

I'm pretty sure it has something to do with sysFindObject but I'm not sure how to code it

maybe

Code: Select all

(sysFindObject "Ts:iocrym;E")

User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

is there a way to tell how much damage a weapon will do to a shield?

Lets say I have the amount of damage the weapon will do the damage type and the shield. (lets assume the shield is on a ship)
Crying is not a proper retort!
F50
Fleet Officer
Fleet Officer
Posts: 1004
Joined: Sat Mar 11, 2006 5:25 pm

Fatboy wrote:How would you add a check to see if a certain ship is there or not.

I'm pretty sure it has something to do with sysFindObject but I'm not sure how to code it

Something like:

Code: Select all

(block (iocrymShip listofShips thisShip)

(setq listofShips (sysFindObject "s"))
(enum listofShips thisShip
    (if (eq (shpGetClass thisShip) "&scIocrym;")
        (setq iocrymShip thisShip)
    )
)

)
Apemant
Commonwealth Pilot
Commonwealth Pilot
Posts: 94
Joined: Mon Dec 03, 2007 12:51 pm

Betelgeuse wrote:This thread is for you to ask and answer questions about small amounts of code. Please do not ask how to how to make your mod. Those kind of questions go in the extensions reference help me thread.
For example here is a question I have myself.

(setq vary (sysVectorPolarOffset center angle radius))
Is there a way to derive center and radius from vary?
Noone answered this a long time... anyway, I don't think there is a way, because I think 'vectors' are just coordinates in space, they are pairs of (x, y) offsets from the center of the system, i.e. a star. So, if you did a
(setq vary (sysVectorPolarOffset Nil angle radius))
then 'radius' would simply be the distance to the center, i.e.
(sysVectorDistance vary Nil)
would retrieve it.

But, if you do a sysVectorPolarOffset centered somewhere else instead of 'Nil', then it basically just creates a polar offset from that spot. The result is again some pair of coordinates so it doesn't 'remember' how you came up with those coordinates.

To put it simpler:
(sysVectorPolarOffset center angle radius)
is equivalent of
(sysVectorAdd center (sysVectorPolarOffset Nil angle radius))

- and it is obvious that you can't derive 'center' and 'radius' from the resulting vector, because the same 'vector' could be created by infinite number of combinations of 'center', 'angle' and 'radius'.
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

sorry Apemant you are mistaken while it might be true that I could not derive center and radius but the format for a vector in Transcendence is not (x,y) it has 4 numbers in a list.
Crying is not a proper retort!
Apemant
Commonwealth Pilot
Commonwealth Pilot
Posts: 94
Joined: Mon Dec 03, 2007 12:51 pm

Betelgeuse wrote:sorry Apemant you are mistaken while it might be true that I could not derive center and radius but the format for a vector in Transcendence is not (x,y) it has 4 numbers in a list.
Answered this on the irc channel already but perhaps others might be interested in this as well....
As we have talked on the irc, if you do this in debug screen:
(sysVectorPolarOffset Nil 0 1)
(sysVectorPolarOffset Nil 90 1)
(sysVectorPolarOffset Nil 180 1)
(sysVectorPolarOffset Nil 270 1)

you get the following series of numbers
(0 1091718210 0 0)
(-62448911 1035218696 0 1091718210)
(0 -1055765438 -62448911 1036267272)
(2053810281 -1110554995 0 -1055765438)

which indeed looked kinda odd, however, this little c thing reveals exactly what those numbers mean

Code: Select all

#include <stdio.h>

int main(void) 
{
	double num;
	int *ptr;

	ptr = (int*) &num;

	*ptr =	0;
	*(ptr+1) = 1091718210;
	printf("%.30f\n", num);

	*ptr =	-62448911;
	*(ptr+1) = 1035218696;
	printf("%.30f\n", num);

	*ptr =	2053810281;
	*(ptr+1) = -1110554995;
	printf("%.30f\n", num);

	*ptr =	0;
	*(ptr+1) = -1055765438;
	printf("%.30f\n", num);

	return 0;
}
you get -
299792.500000000000000000000000000000
0.000000000018356996276669144358
-0.000000000055070988830007429842
-299792.500000000000000000000000000000

Which means those 4 numbers are just pairs of doubles, displayed as two ints, and the 'weird' numbers are very little doubles which are probably the roundoff error in conversion from degrees to radians. So it really looks like this:

(299792.5 0)
(0 299792.5)
(-299792.5 0)
(0 -299792.5)

which are quite obviously coordinates in kilometers, 299792.5 km being 1 lightsecond naturally.

So, I believe it's safe to assume that 'vectors' are just coordinates in space, (x,y) offsets from the center of the system (i.e. a star).
Apemant
Commonwealth Pilot
Commonwealth Pilot
Posts: 94
Joined: Mon Dec 03, 2007 12:51 pm

Betelgeuse wrote:I would like to see a couple functions but can't think of a nice way to do them.

objHasItemByUNID
and
objRemoveItemByUNID

checks if they have or removes an optional count of items that match an id

I would like them to go damaged normal enhanced (I don't care the order of what enhancements are removed, also no removing installed devices)

any takers? (no hurry I don't need them for a mod but it would have made the mod I am making easier)
Hmm, for the first func, couldn't you just objEnumItems "*U" or something, and then check items for unid, like
(setq found Nil)
(objEnumItems aObj "*U" aItem (if (eq unid (itmGetUNID aItem)) (setq found 1)))

or somesuch?

As for the second func... well make 3 enums, first "*DU" (or "*U" but with itmIsDamaged), then normal, then enhanced.

(setq items (objGetItems aObj "*DU"))
(append items (filter (objGetItems aObj "*U") aItem (not (itmIsEnhanced aItem))))
(append items (filter (objGetItems aObj "*U") aItem (itmIsEnhanced aItem)))
(setq notf True)
(enumwhile items notf aItem (if (eq unid (itmGetUNID aItem)) (block Nil (setq notf Nil) (objRemoveItem aObj aItem))))


Didn't check any of this though - too lazy :D
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

with objRemoveItemByUNID I was thinking more of giving it a number otherwise it doesn't matter the order that you remove these things
your method only removes one but it would be easy enough to alter to allow for that.
Crying is not a proper retort!
F50
Fleet Officer
Fleet Officer
Posts: 1004
Joined: Sat Mar 11, 2006 5:25 pm

Apemant wrote: As for the second func... well make 3 enums...
Wouldn't it be more efficient to create an item and then destroy x+1 items from that item struct?
Apemant
Commonwealth Pilot
Commonwealth Pilot
Posts: 94
Joined: Mon Dec 03, 2007 12:51 pm

F50 wrote: Wouldn't it be more efficient to create an item and then destroy x+1 items from that item struct?
how do you mean?

I thought he wanted to remove first the damaged, the normal, then enhanced versions of the same item.

So if you have 3 mining lasers, one damaged, one normal and one enhanced, and you want to 'objremove' 2 of those, but in the above order (so that you leave the enhanced one behind)
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

now that I think about it I think "*U" needs to be "*NU" otherwise you are adding the damaged items twice
Crying is not a proper retort!
F50
Fleet Officer
Fleet Officer
Posts: 1004
Joined: Sat Mar 11, 2006 5:25 pm

Apemant wrote:how do you mean?

I thought he wanted to remove first the damaged, the normal, then enhanced versions of the same item.
Ah, couldn't find the text being quoted that said that.
So if you have 3 mining lasers, one damaged, one normal and one enhanced, and you want to 'objremove' 2 of those, but in the above order (so that you leave the enhanced one behind)
I'd have to take a closer look at the remove item function, but you can remove any object that stacks with the created object, which should allow you to do damaged items easily. The trouble is the enhanced items.
Post Reply