It is currently Sun Jul 12, 2020 4:03 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Changing Character Nation
PostPosted: Fri Jan 01, 2016 7:38 pm 
Offline
Soldier level 0
Soldier level 0
User avatar

Joined: Sat Dec 26, 2015 2:11 pm
Posts: 5
Location: Poland
I was pretty frustrated that there is no easy way to switch character nation. So i made this little code and though I share it with you guys. I used code from the arcamp mod as a reference. It was super helpfull. Thanks for that. :D

It allows you to change nation of characters placed in depot (or any other building you choose).

It uses query and character replacing as the way to do it and its contained within one module, so you wont need to jumble your code with it.

'dep2' is the identifier of the building, so you need to change that for your building id, and you need to change the side number from 3 to whichever side you are using too.

And here is the code:

Code:
var nation_chosen, my_all_units, my_unit, do_change;

function ChangeNation(var unit_to_change, p_nation);
var old_unit;
begin
     old_unit := unit_to_change;
     SaveCharacters(unit_to_change, 'temp');
     PrepareCharacter('temp');
     uc_nation := p_nation;
     uc_side := 3;
     unit_to_change := CreateHuman;

     RemoveUnit(old_unit);
     PlaceHumanInUnit(unit_to_change,dep2);

     SetLives(unit_to_change,GetLives(old_unit));
end;

every 0$6 trigger isselected(dep2) do
begin
       enable;
       do_change := true;
       Case Query('Change') of
          1:Begin
                 nation_chosen := nation_american;
          end;

          2:Begin
                 nation_chosen := nation_russian;
          end;

          3:Begin
                 nation_chosen := nation_arabian;
          end;

          4:Begin
                 do_change = false;
          end;
       end;
       if(do_change) then
       begin
            my_all_units = FilterAllUnits([f_side,3]);
            for my_unit in all_units do
            begin
                 if(dep2 = IsInUnit(my_unit)) then
                 begin
                      ChangeNation(my_unit, nation_chosen);
                 end;
            end;
       end;


end;


Top
 Profile  
 
 Post subject: Re: Changing Character Nation
PostPosted: Sun Jan 03, 2016 2:33 pm 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1130
Location: Denmark
Looks good. Smart idea to save the character and then load it in again. That way you don't have to worry about settings skills.
If you want to clean up properly you could delete the temporarily saved character ( DeleteCharacters('temp') ) and completely delete the old unit ( DestroyUnit(old_unit) ) (remember to save the unit's HP as it will be unavailable after the unit has been destroyed).

_________________
I have an if that has an else, but that if has another if with an else inside... My question is... If an if has an else, if there is more than one line in that if, should it have a begin and an end?


Top
 Profile  
 
 Post subject: Re: Changing Character Nation
PostPosted: Mon Jan 04, 2016 3:09 pm 
Offline
Soldier level 0
Soldier level 0
User avatar

Joined: Sat Dec 26, 2015 2:11 pm
Posts: 5
Location: Poland
I found one flab in it though. If the character had previously assigned ID then if you use the change on it you lose that ID. I need to somehow adress that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Original War is an RTS / RPG game by Altar Games
Original War Support is not part of Altar Games but is maintaining Original War for Altar Games

Privacy Policy