Announcement

Collapse
No announcement yet.

SLIC Help: Gift Unit

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SLIC Help: Gift Unit

    I received a lot of good help on this code and eventually got it to load withou slic errors but still its not working as intended (in fact not at all). Can anyone provide some help on this?


    Code:
    HandleEvent(DisbandUnit) 'GiftUnit' pre {
    
    	unit_t		tmpUnit;
    	location_t	tmpUnitLoc;
    	int_t		tmpUnitType;
    	int_t		tmpWe;
    	int_t		tmpThey;
    	unit_t		tmpNewUnit;
    	
    	tmpUnit = unit[0];
    	tmpUnitType = unit[0].type;
    	tmpUnitLoc = unit[0].location;
    	tmpWe = unit[0].owner;
    	tmpThey = CellOwner(tmpUnitLoc);
    
    	if (tmpThey > 0 && tmpThey != tmpWe) {
    		// Alternative options:
    		// if(HasAgreement(tmpWe, tmpThey, 36)) { // 36 = Military Pact
    		// if(HasAgreement(tmpWe, tmpThey, 38)) { // 38 = Alliance
    		if (!(AtWarWith(tmpWe, tmpThey))) {	
    			KillUnit(tmpUnit);
    			CreateUnit(tmpThey, tmpUnitType, tmpUnitLoc, 0, tmpNewUnit);
    		}
    	}
    }
    My next bet is to change it from disband to sleep because maybe disband is causing the problem but sleep is kind of important in enemy territory.
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

  • #2
    Checking, double checking, triple checking the code I still can't see why it shouldn't work theoretically.

    But trying to think in terms of SLIC-metaphysics, I can see -- no, not the light, but some variations:


    1. Applying the "trial and horror" method: what about replacing

    Code:
    tmpWe = unit[0].owner;
    by

    Code:
    tmpWe = player[0];
    3. Also, you could try

    Code:
    tmpUnitType = tmpUnit.type;
    tmpUnitLoc = tmpUnit.location;
    2. Theoretically killing the unit pre disbanding should not affect the creation of the new unit -- but who knows? As the unit will be disbanded anyway, why not try this:

    Code:
    [COLOR=darkred]// KillUnit(tmpUnit);[/COLOR]
    CreateUnit(tmpThey, tmpUnitType, tmpUnitLoc, [COLOR=darkred]1[/COLOR], tmpNewUnit);
    Not sure if the distance-parameter is strictly needed, but it seems correct to adjust it.

    That's all I can think of for this morning -- good night!

    P.S.: AAArgh -- another thing hits me just before pressing the submit button:

    Maybe, just maybe SLIC has some problem creating a unit for a player when it's not his turn -- despite the documented owner-parameter. I don't remember if this has ever been done so far -- granted lots of units have been killed when it was not their player's turn . If that's the problem the solution would be to store the disbanded unit in variable -- maybe better create an array for keeping "gifted units" -- and create the correspondig unit during the receiver's turn.

    However: I would recommend searching the forums or waiting for a third opinion before blowing up the code
    The modding knowledgebase: CTP2 Bureau (with CTP2 AE Modding Wiki). Modern Times Mod (work in progress): MoT-Mod for CTP2.

    Comment

    Working...
    X