Author Topic: Scripting issues  (Read 1977 times)

0 Members and 1 Guest are viewing this topic.

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
I have been testing the scripting capabilities with Axem and encountered few issues.. And perhaps somethings that would make scripts easier to use or enable new features to be created wioth scripts.

So first few more graphical examples:

Floating particle square
Expanding particle spiral
Expanding particle spiral, with tracer settings

And then to problems...

i) Some thing odd happens if i use the particle spiral thing combined with 'tracer' option. (See ts.createParticle in scripting.html). The screenies above demonstrate this. With tracer setting most of the weapon impact effects and damage spews are centered at 0,0,0 (world coordinates) instead of the hit location (so they appear in empty space far from the ship that was hit, compare the second and the third pic). Setting tracer option to -1 fixes the issue.

ii) I can not kill ships with scripts.. Or they dont die even if they should. If i use a script to set ship hitpoints to zero it doesnt die. Instead ship gets its ingame screen hitpoints set to 0% and also all subsystems are destroyed . In player ship the hitpoints drop to 1% and all subsys are destroyed... Making them/player sitting ducks (cant move, shoot, use sensors etc.) BUT leaving them still alive before some one cares to give them a coup de grĂ¢ce  (BTW same thing happens to me in multi every once in a while).

And finally some requests

i) Some sort of function that gets the mission name would be very nice.. Something like mn.getName() would make it much easier to trigger certain scripts to have any effect only in certain missions. Currently the same thing can be achieved but it AFAIK needs so sort of 'triggering' ships to appear in the mission (like invisble/stealth ships somewhere far away)

ii) Direct 'get weapon' functions... Pretty much the same as what the weapons have.. Currently mn.getNumShips() and mn.getShipByIndex(i) exist but it would be usefull (IMO) to also have) mn.getNumWeapons() and mn.getWeaponByIndex(i).
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
I can't commit right now, for a couple reasons (I don't have the time to clean up my codebase, test this, and bugfix four more bugs), so here is the source code for the requested mission functions. Source code goes in lua.cpp.

Under "lua_lib l_Mission("Mission", "mn", "Mission library");"

Code: [Select]
LUA_FUNC(getMissionName, l_Mission, NULL, "string", "Gets mission name")
{
if(!(Game_mode & GM_IN_MISSION))
return LUA_RETURN_NIL;

return lua_set_args(L, "s", Game_current_mission_filename);
}

And under the "LUA_FUNC(getShipByIndex" function

Code: [Select]
LUA_FUNC(getNumWeapons, l_Mission, NULL, "Number of weapon objects in mission",
"Gets number of weapon objects in mission. Note that this is only accurate for one frame.")
{
return lua_set_args(L, "i", Num_weapons);
}

LUA_FUNC(getWeaponByIndex, l_Mission, "Index", "Weapon handle, or false if invalid index",
"Gets weapon by its order in the mission. "
"Note that as weapons are added, they may take the index of destroyed ships. "
"An index is only good for one frame.")
{
int idx;
if(!lua_get_args(L, "i", &idx))
return LUA_RETURN_NIL;

//Remember, Lua indices start at 0.
int count=1;

for(int i = 0; i < MAX_WEAPONS; i++)
{
if (Weapons[i].weapon_info_index < 0 || Weapons[i].objnum < 0 || Objects[Weapons[i].objnum].type != OBJ_WEAPON)
continue;

if(count == idx) {
return lua_set_args(L, "o", l_Weapon.Set(object_h(&Objects[Weapons[i].objnum])));
}

count++;
}

return LUA_RETURN_FALSE;
}

I have test-compiled these but not tested them.
-C

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
:doubt: I seem to be unusually good in finding buggy or non functional scripting functions...

I tested mn.getShipByIndex[ i ]:getNumSubsystems() for all ships that appeared in the mission ( indexes from 1 to getNumShips() ) and it returned 0 for all of them, mission had 8 fighters and two cruisers (so they had plenty of both subsystems and submodels). Similar occurrance with mn.getShipByIndex(1)[1]:getName() as it returns always nil value.. I can access something with mn.getShipByIndex(1)["sensors"].Position but all vector components are either 0 or pretty close to it.. sometimes around 10-30..

Then a noobish question... any idea how to always get only player ships' handle? Using mn.getShipByIndex(1) isnt really good solution as i have player ship quite often having index value of 2 or 3. Though its easy to open a mission and check the index value from there.
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
I might keep adding the questions here..

Bit odd, but i noticed that i can not use multiplication (*) with vectors.. it gives me a lua error of using arithmetic on a userdata. So i have to route all multiplications via divisions with their inverted values... That is

ma.newVector(0,5,0) * 5 gives error
ma.newVector(0,5,0) / ( 1 / 5 ) gives the vector with every component multiplied by 5

And are there any documentation of the Collide Ship and Collide Weapon options (like are there other extra options in addition to the 'Self')? I found a single link but it didnt lead anywhere or then i dont have access rights to that portion of HLP.
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
is there a way to render a particular default hud gauge (like the radar or sensors) to a texture?
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Code: [Select]
tex = gr.createTexture(1024, 1024, "dynamic")
gr.setTarget(tex)
--Render gauge--
gr.setTarget()
-C

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
I might keep adding the questions here..

Bit odd, but i noticed that i can not use multiplication (*) with vectors.. it gives me a lua error of using arithmetic on a userdata. So i have to route all multiplications via divisions with their inverted values... That is

ma.newVector(0,5,0) * 5 gives error
ma.newVector(0,5,0) / ( 1 / 5 ) gives the vector with every component multiplied by 5

Try swapping the order (5 * ma.newVector())

And are there any documentation of the Collide Ship and Collide Weapon options (like are there other extra options in addition to the 'Self')? I found a single link but it didnt lead anywhere or then i dont have access rights to that portion of HLP.

Right before "$Impact Explosion:", I've added two new fields

...

$Collide Ship:
Globals: "Self", weapon with class that the hook is defined in. "Ship", ship that the weapon collided with.
Override: Turns off all damage effects from weapon, as well as weapon being destroyed.

Executed whenever a weapon has hit a ship's hull.

$Collide Weapon:
Globals: "Self", weapon with class that the hook is defined in. "Weapon", other weapon.
Override: Turns off weapon killing types with bombs. If two weapons, weapon "A" (arbitrary) is preferred

This might be better as a global hook, but basically it's executed whenever two weapons collide. If you want to kill weapons like the code does here, set LifeLeft to 0.01 and DestroyedByWeapon to true.

...

Two words..."Freespace pong"
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Code: [Select]
tex = gr.createTexture(1024, 1024, "dynamic")
gr.setTarget(tex)
--Render gauge--
gr.setTarget()

i know that part, but how to i get the gauge data. what i want to do is take the 3d radar gauge (and others as well) off the hud, and put it onto the panel.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

  

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Ahh.

You can get the data in the raw form from the scripting system, but none of the retail gauges are actually defined using it. I think that'd be a good project...but anyway, the HUD code is messy. You can do what you're saying (I think) but it'd take the addition of a nother table, section of a table, or something similar. I don't know if you could use hud_gauges.tbl, since I designed it before I really realized that RTT would be possible.
-C