Cool Pog Tricks
20 years 8 months ago #9170
by MajorTom
Replied by MajorTom on topic Cool Pog Tricks
I'm not sure what you mean? Do you want to have the ai pilot do something specific or do you want to change the damage threshold that causes him to flee? or both?
You can write an alternative script for the AIpilot with the task:
Go to a certain location
wait a certain amount of time
heal
go back and help the player
Say you put that script function as: GoWaitHealComeback in your package: mypackage
Then you can use:
iAI.SetFleeFunction( hship damaged_aiship, "mypackage.GoWaitHealComeback" );
The threshold at which the Ai pilot will actually flee
is defined as you setup the Ai Pilot in: iShip.InstallAIPilot( with paramaters as described in the pog sdk)
You can, of course, set your "mypackage.GoWaitHealComeback" as the flee_function directly in iShip.InstallAIPilot (...); when you initially set up your AiPilot if you know that you won't be using any other (situation dependent) alternative flee scripts.
Iwar2 Multiplayer Fan Site
You can write an alternative script for the AIpilot with the task:
Go to a certain location
wait a certain amount of time
heal
go back and help the player
Say you put that script function as: GoWaitHealComeback in your package: mypackage
Then you can use:
iAI.SetFleeFunction( hship damaged_aiship, "mypackage.GoWaitHealComeback" );
The threshold at which the Ai pilot will actually flee
is defined as you setup the Ai Pilot in: iShip.InstallAIPilot( with paramaters as described in the pog sdk)
You can, of course, set your "mypackage.GoWaitHealComeback" as the flee_function directly in iShip.InstallAIPilot (...); when you initially set up your AiPilot if you know that you won't be using any other (situation dependent) alternative flee scripts.
Iwar2 Multiplayer Fan Site
Please Log in or Create an account to join the conversation.
20 years 8 months ago #9171
by Qi Qi
Life is half spent before we know what it is...
Replied by Qi Qi on topic Cool Pog Tricks
Hi MajorTom, Thank you for your reply.
I tried it some ways ,but neither of them worked.
I coded a alternative AI script function ,FleeFunc, for replacing the default flee function. I put its declare into wherever iShip.InstallAIPilot() or iAI.SetFleeFunction(), like that iShip.InstallAIPilot(ship, 1.0, 0.35, 0.5,"","SSmain.FleeFunc","","") or iAI.SetFleeFunction(ship, "SSmain.FleeFunc" ), but both of them failed to work in game although the compile succeeded.
And I tried both regular function and task function for FleeFunc, but it still didn't work.
The last thing I most want to confirm is what the argument of FleeFunc should be, hship or hsim. I have to say that this part of AI script function override is not described as clear as the one about DeathScript's replacement in the Pog SDK help file.
Life is half spent before we know what it is...
I tried it some ways ,but neither of them worked.
I coded a alternative AI script function ,FleeFunc, for replacing the default flee function. I put its declare into wherever iShip.InstallAIPilot() or iAI.SetFleeFunction(), like that iShip.InstallAIPilot(ship, 1.0, 0.35, 0.5,"","SSmain.FleeFunc","","") or iAI.SetFleeFunction(ship, "SSmain.FleeFunc" ), but both of them failed to work in game although the compile succeeded.
And I tried both regular function and task function for FleeFunc, but it still didn't work.
The last thing I most want to confirm is what the argument of FleeFunc should be, hship or hsim. I have to say that this part of AI script function override is not described as clear as the one about DeathScript's replacement in the Pog SDK help file.
Life is half spent before we know what it is...
Life is half spent before we know what it is...
Please Log in or Create an account to join the conversation.
20 years 8 months ago #9172
by MajorTom
Replied by MajorTom on topic Cool Pog Tricks
I really don't know what could be wrong. Maybe this will help:
This kind of function call works like the calls used for buttons in Gui screens (when you use iGui.CreateMenueButton):
a) Although you specify it in your script, the call actually comes from an external package (iAi) so you need to have your 'FleeFunc' function in the "provides" list of your SSMain package, and you should prototype it (as a normal function, not a task). Otherwise pog will fail silently even though the script will compile.
b) Be very carefull about spelling and capitalization (the compiler/linker cannot (or does not) check for the avaliability/syntax of a function that is defined in " " .
c) try a Debug.PrintHandle to be sure you've got a valid handle to the sim you're trying to control
Iwar2 Multiplayer Fan Site
This kind of function call works like the calls used for buttons in Gui screens (when you use iGui.CreateMenueButton):
a) Although you specify it in your script, the call actually comes from an external package (iAi) so you need to have your 'FleeFunc' function in the "provides" list of your SSMain package, and you should prototype it (as a normal function, not a task). Otherwise pog will fail silently even though the script will compile.
b) Be very carefull about spelling and capitalization (the compiler/linker cannot (or does not) check for the avaliability/syntax of a function that is defined in " " .
c) try a Debug.PrintHandle to be sure you've got a valid handle to the sim you're trying to control
Iwar2 Multiplayer Fan Site
Please Log in or Create an account to join the conversation.
20 years 8 months ago #9188
by Qi Qi
Life is half spent before we know what it is...
Replied by Qi Qi on topic Cool Pog Tricks
hi dude, I still can't figure out what the wrong is. So I attach the related scripts here below to help examine.
******************
package SSmain;
...
provides
...
FleeFunc, WimpFunc,...
prototype FleeFunc( hship ship ); // is it "hship" or others ?
prototype WimpFunc( hship ship );
...
SquadCreation(int itype)
{
...
ship=iShip.Create(strship,String.Join(shipnme,String.FromInt(i)));
iShip.InstallAIPilot(ship, 1.0, 0.35, 0.5,"","","","");
iShip.SetPilotSkillLevel(ship,0.<!-- s8) --><img src="{SMILIES_PATH}/icon_cool.gif" alt="" title="Cool" /><!-- s8) -->;
iAI.SetFleeFunction( ship, "SSmain.FleeFunc" );
iAI.SetWimpyFunction( ship, "SSmain.WimpFunc" );
...
}
FleeFunc( hship ship ) // "the argument is exactly right?"
{
hship player=iShip.FindPlayerShip();
string shipname=Sim.Name(Sim.Cast(ship));
iHUD.Print ("FleeFunc");
iAI.PurgeOrders( ship );
iAI.GiveApproachOrderNoDropOff( ship, player);
iComms.Shout(ship, shipname, " The enemy is strong, I am falling back to you." );
}
WimpFunc( hship ship ) // "the argument is exactly right?"
{
hship player=iShip.FindPlayerShip();
string shipname=Sim.Name(Sim.Cast(ship));
iHUD.Print ("WimpFunc");
iAI.PurgeOrders( ship );
iAI.GiveApproachOrderNoDropOff( ship, player);
iComms.Shout(ship, shipname, " My ship hurted badly, I need to retreat temporarily." );
}
*************************************
It seemed that both "FleeFunc" and "WimpFunc" fail to work, though the compile is no problem.
In fact, I even now don't know how to judge whether them work or not. I assumed that they would be triggered before the related AiShip want to fled. But actually those Aiships associated with the alternative functions always fled without informing me or acting as the alternative functions do.
Here, I even began to doubt the availability of the code interfaces. What should I do about it?
Life is half spent before we know what it is...
******************
package SSmain;
...
provides
...
FleeFunc, WimpFunc,...
prototype FleeFunc( hship ship ); // is it "hship" or others ?
prototype WimpFunc( hship ship );
...
SquadCreation(int itype)
{
...
ship=iShip.Create(strship,String.Join(shipnme,String.FromInt(i)));
iShip.InstallAIPilot(ship, 1.0, 0.35, 0.5,"","","","");
iShip.SetPilotSkillLevel(ship,0.<!-- s8) --><img src="{SMILIES_PATH}/icon_cool.gif" alt="" title="Cool" /><!-- s8) -->;
iAI.SetFleeFunction( ship, "SSmain.FleeFunc" );
iAI.SetWimpyFunction( ship, "SSmain.WimpFunc" );
...
}
FleeFunc( hship ship ) // "the argument is exactly right?"
{
hship player=iShip.FindPlayerShip();
string shipname=Sim.Name(Sim.Cast(ship));
iHUD.Print ("FleeFunc");
iAI.PurgeOrders( ship );
iAI.GiveApproachOrderNoDropOff( ship, player);
iComms.Shout(ship, shipname, " The enemy is strong, I am falling back to you." );
}
WimpFunc( hship ship ) // "the argument is exactly right?"
{
hship player=iShip.FindPlayerShip();
string shipname=Sim.Name(Sim.Cast(ship));
iHUD.Print ("WimpFunc");
iAI.PurgeOrders( ship );
iAI.GiveApproachOrderNoDropOff( ship, player);
iComms.Shout(ship, shipname, " My ship hurted badly, I need to retreat temporarily." );
}
*************************************
It seemed that both "FleeFunc" and "WimpFunc" fail to work, though the compile is no problem.
In fact, I even now don't know how to judge whether them work or not. I assumed that they would be triggered before the related AiShip want to fled. But actually those Aiships associated with the alternative functions always fled without informing me or acting as the alternative functions do.
Here, I even began to doubt the availability of the code interfaces. What should I do about it?
Life is half spent before we know what it is...
Life is half spent before we know what it is...
Please Log in or Create an account to join the conversation.
20 years 8 months ago #9198
by MajorTom
Replied by MajorTom on topic Cool Pog Tricks
It works if you put the alternative flee function directy in iShip.InstallAIPilot.
To test it I changed your scripta a bit:
in SSorders:
If you get off about 8 km and fire a couple of rapid fire shots at the wingman ship he will turn red at 80% damage and then approach you. You get the following debug in flux log:
SCRIPT: [unknown] Ai Ship is: 48235 ("SkullSquad Wing 1", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
SCRIPT: [unknown] iWingmen.Group: Returning wingmen group containing the player and 1 wingmen.
SCRIPT: [unknown] iWingmen.AddWingman: Wingman SkullSquad Wing 2 added. Total wingmen = 2
SCRIPT: [unknown] Ai Ship is: 48346 ("SkullSquad Wing 2", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
SCRIPT: [unknown] iWingmen.Group: Returning wingmen group containing the player and 2 wingmen.
SCRIPT: [unknown] iWingmen.AddWingman: Wingman SkullSquad Wing 3 added. Total wingmen = 3
SCRIPT: [unknown] Ai Ship is: 48456 ("SkullSquad Wing 3", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
SCRIPT: [unknown] iWingmen.Group: Returning wingmen group containing the player and 3 wingmen.
SCRIPT: [unknown] iWingmen.AddWingman: Wingman SkullSquad Wing 4 added. Total wingmen = 4
SCRIPT: [unknown] Ai Ship is: 48566 ("SkullSquad Wing 4", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
SCRIPT: [unknown] iWingmen.Group: Returning wingmen group containing the player and 4 wingmen.
SCRIPT: [unknown] iWingmen.AddWingman: Wingman SkullSquad Wing 5 added. Total wingmen = 5
SCRIPT: [unknown] Ai Ship is: 48676 ("SkullSquad Wing 5", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
SCRIPT: [unknown] iWingmen.Group: Returning wingmen group containing the player and 5 wingmen.
SCRIPT: [unknown] iWingmen.AddWingman: Wingman SkullSquad Wing 6 added. Total wingmen = 6
SCRIPT: [unknown] Ai Ship is: 48786 ("SkullSquad Wing 6", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
***snip***
SCRIPT: [unknown] **executing HowFlee Function**
SCRIPT: [unknown] : Ai Ship is:48456 ("SkullSquad Wing 3", "icShip")
SCRIPT: [unknown] has orders type 3
***Snap***
Apparently iAI.SetFleeFunction won't work if the iShip.InstallAIPilot is set to default when the pilot is first installed. (I tried commenting out the first iShip.InstallAIPilot in SSmain while commenting in the other two lines that are now commented out above.)
That didn't work.
(I didn't try to set a anternative script and then change it to another alternative via iAI.SetFleeFunction but, my guess is that it would work. I'll leave that up to you to try out.)
Iwar2 Multiplayer Fan Site
To test it I changed your scripta a bit:
in SSorders:
Code:
provides
Issue1, Issue2, Issue3, Issue4, Issue5, Issue6, LBSelFun,
FormPanel, IssueF, HowFlee;
prototype HowFlee (hship ship);
***Snip***
HowFlee (hship ship)
{
eOrderType type;
hship me = iShip.FindPlayerShip();
iAI.GiveApproachOrder( ship, me );
type = iAI.CurrentOrderType( ship );
debug
{
Debug.PrintString( "**executing HowFlee Function** " );
Debug.PrintString( "\n" );
Debug.PrintString( ": Ai Ship is:" );
Debug.PrintHandle( ship );
Debug.PrintString( "\n" );
Debug.PrintString( " has orders type " );
Debug.PrintInt( type );
Debug.PrintString( "\n" );
}
}
***Snap****
[b]And in SSmain:[/b]
***Snip***
strship = INIFile.String(ssini,"SSquadron",siniitm,"ini:/sims/ships/navy/fighter_mk2");
INIFile.Destroy(ssini);
for (i=1;i<7;++i) {
ship=iShip.Create(strship,String.Join(shipnme,String.FromInt(i)));
iShip.InstallAIPilot(ship, 1.0, 0.35, 0.6,"","","SSorders.HowFlee","");
//iShip.InstallAIPilot(ship, 1.0, 0.35, 0.6,"","","","");
iShip.SetPilotSkillLevel(ship,0.8);
//iAI.SetFleeFunction(ship, "SSorders.HowFlee");
if (itype==0)
{
iWingmen.AddWingman(ship);
}
else
{ Object.AddIntProperty( ship,"team_id", itype );
Object.SetStringProperty ( ship, "death_script", "SSmain.FinalFate" );
iSim.SetFaction(ship, myfac);
iSim.SetSensorVisibility( iSim.Cast( ship ), true );
Sim.SetCullable( Sim.Cast( ship ), false );
teamlist = Global.List(glist);
List.AddTail( teamlist, ship);
Global.SetList( glist, teamlist );
}
Sim.PlaceNear(ship, player, 0.2km);
debug
{
Debug.PrintString( "Ai Ship is: " );
Debug.PrintHandle( ship );
Debug.PrintString( "\n" );
Debug.PrintString( " has an order?: " );
Debug.PrintInt(iAI.HasOrder( ship ));
Debug.PrintString( ": of orders type : " );
Debug.PrintInt( type );
Debug.PrintString( "\n" );
}
}
}
****Snap******
SCRIPT: [unknown] Ai Ship is: 48235 ("SkullSquad Wing 1", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
SCRIPT: [unknown] iWingmen.Group: Returning wingmen group containing the player and 1 wingmen.
SCRIPT: [unknown] iWingmen.AddWingman: Wingman SkullSquad Wing 2 added. Total wingmen = 2
SCRIPT: [unknown] Ai Ship is: 48346 ("SkullSquad Wing 2", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
SCRIPT: [unknown] iWingmen.Group: Returning wingmen group containing the player and 2 wingmen.
SCRIPT: [unknown] iWingmen.AddWingman: Wingman SkullSquad Wing 3 added. Total wingmen = 3
SCRIPT: [unknown] Ai Ship is: 48456 ("SkullSquad Wing 3", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
SCRIPT: [unknown] iWingmen.Group: Returning wingmen group containing the player and 3 wingmen.
SCRIPT: [unknown] iWingmen.AddWingman: Wingman SkullSquad Wing 4 added. Total wingmen = 4
SCRIPT: [unknown] Ai Ship is: 48566 ("SkullSquad Wing 4", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
SCRIPT: [unknown] iWingmen.Group: Returning wingmen group containing the player and 4 wingmen.
SCRIPT: [unknown] iWingmen.AddWingman: Wingman SkullSquad Wing 5 added. Total wingmen = 5
SCRIPT: [unknown] Ai Ship is: 48676 ("SkullSquad Wing 5", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
SCRIPT: [unknown] iWingmen.Group: Returning wingmen group containing the player and 5 wingmen.
SCRIPT: [unknown] iWingmen.AddWingman: Wingman SkullSquad Wing 6 added. Total wingmen = 6
SCRIPT: [unknown] Ai Ship is: 48786 ("SkullSquad Wing 6", "icShip")
SCRIPT: [unknown] has an order?: 0: of orders type : 0
***snip***
SCRIPT: [unknown] **executing HowFlee Function**
SCRIPT: [unknown] : Ai Ship is:48456 ("SkullSquad Wing 3", "icShip")
SCRIPT: [unknown] has orders type 3
***Snap***
Apparently iAI.SetFleeFunction won't work if the iShip.InstallAIPilot is set to default when the pilot is first installed. (I tried commenting out the first iShip.InstallAIPilot in SSmain while commenting in the other two lines that are now commented out above.)
That didn't work.
(I didn't try to set a anternative script and then change it to another alternative via iAI.SetFleeFunction but, my guess is that it would work. I'll leave that up to you to try out.)
Iwar2 Multiplayer Fan Site
Please Log in or Create an account to join the conversation.
20 years 8 months ago #9207
by Qi Qi
Life is half spent before we know what it is...
Replied by Qi Qi on topic Cool Pog Tricks
Hi MajorTom, you are right. The iAI.SetFleeFunction itself has fault, for it would fail to work after the default one is set in iAI.InstallAI().
However there are some other things behind the scene, which I want to reveal.
Apparantly, the depiction in SDK helper about this part is not identical , quite confused actually, to the one in specific header file. Theoretically and practically, the latter is correct. That is key to the declaring order of the related arguments.
At the beginning, the first attempt to alter flee function failed not because it just didn't work itself but because the threat values over those AI ships are not big enough to surpass the threshold and trigger the flee function.
In fact, I find that the effect of reloading the self preserving function by a alternative is more manifest and remarkable, for a AI ship would take action immediately if he had a specific % hitpoints lost without checking the threat value.
I personally regard the alternation of flee and self preserving functions as importance, for my fighters would not flee far away from me without a word when they were in troubles. And let alone the alternative DeathScript which must be used to update the Global lists.
And now I have a plan to replace the original fight function.
Life is half spent before we know what it is...
However there are some other things behind the scene, which I want to reveal.
Apparantly, the depiction in SDK helper about this part is not identical , quite confused actually, to the one in specific header file. Theoretically and practically, the latter is correct. That is key to the declaring order of the related arguments.
At the beginning, the first attempt to alter flee function failed not because it just didn't work itself but because the threat values over those AI ships are not big enough to surpass the threshold and trigger the flee function.
In fact, I find that the effect of reloading the self preserving function by a alternative is more manifest and remarkable, for a AI ship would take action immediately if he had a specific % hitpoints lost without checking the threat value.
I personally regard the alternation of flee and self preserving functions as importance, for my fighters would not flee far away from me without a word when they were in troubles. And let alone the alternative DeathScript which must be used to update the Global lists.
And now I have a plan to replace the original fight function.
Life is half spent before we know what it is...
Life is half spent before we know what it is...
Please Log in or Create an account to join the conversation.