Page 2 of 5 FirstFirst 12345 LastLast
Results 51 to 100 of 212

[How To] Some Basic Scar for Mappers

  1. #51
    comeradealexi
    Guest
    I got Corsix's mod studio - i opened the SGA file which i packaged from Worldbuilder but i dont know where to go from there - do you have a link to a tutorial which shows me how to pack it in Corsix?

    soz to ask so many q's u been a great help!

  2. #52
    No problems, I'll add a link to this post

    Edit: I may as well just type it.

    (1) To start, make a new folder on desktop with your maps name(BIGFUN) inside of that make another new folder and name Scenarios, now make another new folder inside that and name it MP, then put all your map/scar related files inside this. So it should look like BIGFUN/Scenarios/MP/ and all files.

    (2) Open Modstudio, you need to load any sga file from C: programfiles/THQ/CompanyofHeroes/DLC1 and open any of the sga's in there, this is only to be able to use ModStudio as a packer, dont mod or save these files, it doesnt matter what sga is used, it could be in another folder(but must be inside main COH folder) its just the way Studio works to be able to open Studio if you dont have a mod made, if youve made a mod, then you could load the module of that and it will work the same.

    (3) Now Studio is open, click on Mod on top left toolbar for dropdown menu, now click on sga packer, Input_directory is now asking you where the file is to pack, browse to your desktop and highlight your map folder, in the 'browse to folder box' that comes up with your map name, recopy the name and click ok.

    (4) Now in the second part SGA_Create its asking where you want this saved, highlight(browse) your desktop or documents, because you may not be able to resave to desktop with both being same name, now paste in the name you copied in the SGA to create file name and click save.

    (5) Now click create on the SGA Packer box, it all should be done now and on your desktop or documents, or wherever you chose to save it
    Last edited by sirpsychoj; 25th May 09 at 5:41 PM.

  3. #53
    comeradealexi
    Guest
    Okay i done all you said but somehow it still crashed :S

    what was the code you used when you were testing it because here is what i am using
    Code:
    import("ScarUtil.scar")
    
    function OnGameSetup ()
    
    player1 = World_GetPlayerAt(1)
    player2 = World_GetPlayerAt(2)
    player3 = World_GetPlayerAt(3)
    player4 = World_GetPlayerAt(4)
    player5 = World_GetPlayerAt(5)
    player6 = World_GetPlayerAt(6)
    player7 = World_GetPlayerAt(7)
    player8 = World_GetPlayerAt(8)
    
    end
    Rule_AddOneShot(test1, 1)
    
    
    
    function OnInit()
    end
    
    function test1 ()
    
    	for i = 1, World_GetPlayerCount() do  
    	player = World_GetPlayerAt(i)
    
    Modify_PlayerResourceRate(player, RT_Manpower, 6)
    Modify_PlayerResourceRate(player, RT_Fuel, 4)
    Player_SetPopCapOverride(player, 250)
    end
    end

  4. #54
    Nah thats the wrong one, here it is


    Code:
    import("ScarUtil.scar")
    import("WCUtil.scar")
    
    -- Called immediately on startup, this just sets out some parameters for the mission
    
    
    function OnGameSetup()
    
    -- used to indicate we want annihilate to be checked
       g_CheckAnnihilate = true
    
    -- set up the players
    
    player1 = World_GetPlayerAt(1)
    player2 = World_GetPlayerAt(2)
    player3 = World_GetPlayerAt(3)
    player4 = World_GetPlayerAt(4)
    player5 = World_GetPlayerAt(5)
    player6 = World_GetPlayerAt(6)
    player7 = World_GetPlayerAt(7)
    player8 = World_GetPlayerAt(8)
    
    
    Rule_AddOneShot(test1, 1)
    
    end
    
    
    function OnInit()
    
    	for i = 1, World_GetPlayerCount() do  
    	player = World_GetPlayerAt(i)
    
           Modify_PlayerResourceRate(player, RT_Manpower, 6)
           Modify_PlayerResourceRate(player, RT_Fuel, 4)
           Player_SetPopCapOverride(player, 250)
        end
    end	
    
    Scar_AddInit(OnInit)
    
    
    function test1()
    
    
    end
    The part I added for you doesnt need a rule, it runs from game start, but I left your rule there for future things you want to add and the Scar_AddInit function to then activate your rules. This all works now, tested. Btw, the resources ingame are excessive
    Last edited by sirpsychoj; 26th May 09 at 5:37 AM.

  5. #55
    comeradealexi
    Guest
    Wow thanks so much dude - works perfectly now. Thanks a lot for all your help.


    btw if i want to increase munitions cap i added
    Code:
    "Modify_PlayerResourceRate(player, RT_Munitions, 6)"
    but that doesnt work ?

  6. #56
    No problems, glad to help. The reason RT_Munition, 6 isnt working is because you've added a "s" to the end of it, drop the s and it will work, if you have any future questions or problems, dont hesitate to ask.

  7. #57
    comeradealexi
    Guest
    lol when typing it i was thinking hmmm munitions??

    it doesnt say fuels or manpowers but they dont make sense!

    lol


    thanks for all ur help man!

  8. #58
    Member SsOullesS's Avatar
    Join Date
    Nov 2008
    Location
    Eastern Front
    Hi, I just started learning SCAR, but at the very beginning I hit the wall. I can`t implement any SCAR to my maps (not even the basic one) every time I start playing (right after loading) the game freezes and the last thing in console is:
    GAME- Starting mission...
    after I double click pause it starts again but no SCAR is executed !?

    Did someone had any similar problem and is this perhaps connected to sgb/sga map files (I tried everything I could remember)?
    I always worked with .sga till now (for OF), but haven`t done this in a while.
    Here is the screenshot of the problem, upper picture is before pause and the second after. Thx

    http://i562.photobucket.com/albums/s...g?t=1245259449
    It can be done !!!

  9. #59
    It sounds like its your code that youve setup thats causing conflict, any chance of showing it to better help your problem.

  10. #60
    Now!! The big problem!! Take a look at code plz!!

    import("ScarUtil.scar")

    function OnGameSetup()

    --Setting Player Position

    player1 = World_GetPlayerAt(1)
    player2 = World_GetPlayerAt(2)

    --Setting Player Name

    local player1name = Util_CreateLocString("8th Army Battalion")
    local player2name = Util_CreateLocString("SS Kommando Gruppe")

    Setup_SetPlayerName(player1, player1name)
    Setup_SetPlayerName(player2, player2name)

    --Setting Player Army

    Setup_SetPlayerRace(World_GetPlayerAt(1), 1)
    Setup_SetPlayerRace(World_GetPlayerAt(2), 2)

    --Modify Resource Rate

    Rule_AddOneShot(resource, 5)

    Rule_AddInterval(reinforcement, 5)

    end

    function OnInit()

    --Setting Player Resource

    Player_SetResource(player1, RT_Manpower, 1000)
    Player_SetResource(player1, RT_Munition, 500)
    Player_SetResource(player1, RT_Fuel, 150)
    Player_SetResource(player1, RT_Action, 0)

    Player_SetResource(player2, RT_Manpower, 1000)
    Player_SetResource(player2, RT_Munition, 500)
    Player_SetResource(player2, RT_Fuel, 150)
    Player_SetResource(player2, RT_Action, 0)

    end

    Scar_AddInit(OnInit)

    function resource()

    Modify_PlayerResourceRate(player1, RT_Manpower, 2)
    Modify_PlayerResourceRate(player1, RT_Fuel, 1.5)

    Modify_PlayerResourceRate(player2, RT_Manpower, 2)
    Modify_PlayerResourceRate(player2, RT_Fuel, 1.5)

    end

    function reinforcement()

    sg_support1 = SGroup_CreateIfNotFound("sg_support1")
    Util_CreateSquads(player2, sg_support1, SBP.AXIS.VOLKSGRENADIER, rf_1, nil, 3)
    Util_CreateSquads(player2, sg_support1, SBP.AXIS.GRENADIER, rf_1, nil, 1)
    Util_CreateSquads(player2, sg_support1, SBP.AXIS.PANTHER, rf_1, nil, 1)

    end
    Help!! No reinforcement!!

    Edit: One morething!! It say Cannot start OnGameSetup!!

  11. #61
    Member SsOullesS's Avatar
    Join Date
    Nov 2008
    Location
    Eastern Front
    Sure, here is the code. It`s quite simple:

    import ("ScarUtil.scar")

    function OnGameSetup ()

    player1 = World_GetPlayerAt (1)
    player2 = World_GetPlayerAt (2)

    local player1name = Util_CreateLocString ("150th Rifle Division")
    local player2name = Util_CreateLocString ("27th Panzer Division")

    Setup_SetPlayerName (player1, player1name)
    Setup_SetPlayerName (player2, player2name)

    Setup_SetPlayerRace (World_GetPlayerAt(1), 0)
    Setup_SetPlayerRace (World_GetPlayerAt(2), 3)


    end
    It`s similar with toiletguy`s problem. Everything is fine - until the game starts, then it freezes and after you double click pause or menu it starts normally but something overrides the SCAR code and it doesn`t execute. I even try`ed the simplest code I could remember
    import ("ScarUtil.scar")

    function OnGameSetup()

    player1 = World_GetPlayerAt(1)
    player2 = World_GetPlayerAt(2)


    local player1name = Util_CreateLocString("150th Rifle Division")
    local player2name = Util_CreateLocString("27th Panzer Division")


    Setup_SetPlayerName(player1, player1name)
    Setup_SetPlayerName(player2, player2name)


    end
    same thing.

  12. #62

  13. #63
    Member lilmat1's Avatar
    Join Date
    Jun 2007
    Location
    Brisbane Australia
    I'll See if I can help...

    This is how I do my code, it's mainly for modified units...

    Code:
        
    	import("ScarUtil.scar")
       
    function OnGameSetup()
       
            -- this is called as the game sets up, not when it is initalised.
       
            -- you cannot call functions from here since the game has not started yet.
       
            g_CheckAnnihilate = true
       
    	
       
            -- Setup_Player already returns a player ID so you don't need the
       
            -- World_GetPlayerAt bit.
       
            player1 = Setup_Player(1, 18010003,"Allies",1)
            player2 = Setup_Player(2, 18010003,"Allies",1)
            player3 = Setup_Player(3, 18010002,"Axis",2)
            player4 = Setup_Player(4, 18010002,"Axis",2)
      
           
    end
      
           
      
    function OnInit()
      
            -- this is called when the game initalises, so you can call functions from it.
      
           
      
           	Rule_AddOneShot(init1, 0)
            	Rule_AddOneShot(flyover, 15)
            	Rule_AddInterval(flyover1, 325)
    		Rule_AddOneShot(demo1, 15)
                Rule_AddOneShot(artillery1, 2)
            	
          end
      
          Scar_AddInit(OnInit)
      
           
      
    function init1()
      
            --UI_BindingSetEnabled("company_commander", false )
      
            --UI_ForceCommanderTreeChoice(player1, UPG.COMMANDER_TREE.ALLIES.INFANTRY)
    		
    		Player_SetUpgradeAvailability(player1, UPG.COMMANDER_TREE.ALLIES.INFANTRY, ITEM_UNLOCKED)
    		Player_SetUpgradeAvailability(player1, UPG.COMMANDER_TREE.ALLIES.AIRBORNE, ITEM_LOCKED)
    		Player_SetUpgradeAvailability(player1, UPG.COMMANDER_TREE.ALLIES.ARMOR, ITEM_LOCKED)
    		Player_SetUpgradeAvailability(player2, UPG.COMMANDER_TREE.ALLIES.INFANTRY, ITEM_UNLOCKED)
    		Player_SetUpgradeAvailability(player2, UPG.COMMANDER_TREE.ALLIES.AIRBORNE, ITEM_LOCKED)
    		Player_SetUpgradeAvailability(player2, UPG.COMMANDER_TREE.ALLIES.ARMOR, ITEM_LOCKED)
    		Player_SetUpgradeAvailability(player3, UPG.COMMANDER_TREE.AXIS.DEFENSE, ITEM_UNLOCKED)
    		Player_SetUpgradeAvailability(player3, UPG.COMMANDER_TREE.AXIS.PROPAGANDA, ITEM_LOCKED)
    		Player_SetUpgradeAvailability(player3, UPG.COMMANDER_TREE.AXIS.BLITZKRIEG, ITEM_LOCKED)
    		Player_SetUpgradeAvailability(player4, UPG.COMMANDER_TREE.AXIS.DEFENSE, ITEM_UNLOCKED)
    		Player_SetUpgradeAvailability(player4, UPG.COMMANDER_TREE.AXIS.PROPAGANDA, ITEM_LOCKED)
    		Player_SetUpgradeAvailability(player4, UPG.COMMANDER_TREE.AXIS.BLITZKRIEG, ITEM_LOCKED)
    		
    		Cmd_InstantUpgrade(player1, UPG.GRENADE, ITEM_UNLOCKED)
    		Cmd_InstantUpgrade(player1, UPG.DEMOLITION, ITEM_UNLOCKED)
    		Cmd_InstantUpgrade(player1, UPG.STICKY_BOMB, ITEM_UNLOCKED)
    		Cmd_InstantUpgrade(player1, UPG.BAR, ITEM_UNLOCKED)
    		Cmd_InstantUpgrade(player2, UPG.GRENADE, ITEM_UNLOCKED)
    		Cmd_InstantUpgrade(player2, UPG.DEMOLITION, ITEM_UNLOCKED)
    		Cmd_InstantUpgrade(player2, UPG.STICKY_BOMB, ITEM_UNLOCKED)
    		Cmd_InstantUpgrade(player2, UPG.BAR, ITEM_UNLOCKED)
    		
              --FOW_RevealMarker(mkr_beach, -1)
           -----FOW_RevealArea( markerpos, markerprox, duration )-----
    		
    		
            Util_PlayMusic("SOUND/Music/enterthesqarecombat", 0, 0)
      
           
            --g_alarm_soundpath = "SpecialFX/alarm_02"
      
           
      
            Player_SetPopCapOverride(player1, 110)
            Player_SetPopCapOverride(player2, 110)
            Player_SetPopCapOverride(player3, 130)
            Player_SetPopCapOverride(player4, 130)
      
           
      
            Modify_PlayerResourceRate(player1, RT_Manpower, 2.5)
            Modify_PlayerResourceRate(player2, RT_Manpower, 2.5)
            Modify_PlayerResourceRate(player1, RT_Munition, 1.7)
            Modify_PlayerResourceRate(player2, RT_Munition, 1.7)
      
                 
      
            EGroup_SetInvulnerable(building1, true)
            EGroup_SetInvulnerable(building2, true)
    		EGroup_SetInvulnerable(building3, true)
            EGroup_SetInvulnerable(building4, true)
    		EGroup_SetInvulnerable(building5, true)
            EGroup_SetInvulnerable(building6, true)
            EGroup_SetInvulnerable(bunker1, true)
            EGroup_SetInvulnerable(bunker2, true)
    		EGroup_SetInvulnerable(bunker3, true)
            EGroup_SetInvulnerable(bunker4, true)
            EGroup_SetInvulnerable(bunkerbig1, true)
            EGroup_SetInvulnerable(bunkerbig2, true)
            EGroup_SetInvulnerable(bunkerbig3, true)
            EGroup_SetInvulnerable(bunkerbig4, true)
    		EGroup_SetInvulnerable(bunkerbig5, true)
            EGroup_SetInvulnerable(bunkerbig6, true)
    		
    		---Cmd_InstantEntityUpgrade(building3, UPG.CONVERT_AMBIENT_BUILDING, 1)
    		---Cmd_InstantEntityUpgrade(building4, UPG.CONVERT_AMBIENT_BUILDING, 1)
      
                  barracksboat_BP = BP_GetEntityBlueprint("ebps/environment/art_ambient/objects/vehicles/military/barracks_boat.lua")
                  barracksboat = EGroup_CreateIfNotFound("barracksboat")
                  EGroup_Clear(barracksboat)
                  local entity = Entity_CreateENV(barracksboat_BP, Util_GetPosition(mkr_boat1), Util_GetPosition(facing1))
                  Entity_SetPlayerOwner(entity, player1)
                  EGroup_Single(barracksboat, entity)
    			 
    			  weaponsboat_BP = BP_GetEntityBlueprint("ebps/environment/art_ambient/objects/vehicles/military/support_weapons_boat.lua")
                  weaponsboat = EGroup_CreateIfNotFound("weaponsboat")
                  EGroup_Clear(weaponsboat)
                  local entity = Entity_CreateENV(weaponsboat_BP, Util_GetPosition(mkr_boat2), Util_GetPosition(facing2))
                  Entity_SetPlayerOwner(entity, player1)
                  EGroup_Single(weaponsboat, entity)
    			  
                 
    
    
    			 ----player 2 boats----
    			 
    
    
    			 
    			  barracksboat_BP = BP_GetEntityBlueprint("ebps/environment/art_ambient/objects/vehicles/military/barracks_boat.lua")
                  barracksboat = EGroup_CreateIfNotFound("barracksboat")
                  EGroup_Clear(barracksboat)
                  local entity = Entity_CreateENV(barracksboat_BP, Util_GetPosition(mkr_boat3), Util_GetPosition(facing3))
                  Entity_SetPlayerOwner(entity, player2)
                  EGroup_Single(barracksboat, entity)
      
                 
    			  weaponsboat_BP = BP_GetEntityBlueprint("ebps/environment/art_ambient/objects/vehicles/military/support_weapons_boat.lua")
                  weaponsboat = EGroup_CreateIfNotFound("weaponsboat")
                  EGroup_Clear(weaponsboat)
                  local entity = Entity_CreateENV(weaponsboat_BP, Util_GetPosition(mkr_boat4), Util_GetPosition(facing4))
                  Entity_SetPlayerOwner(entity, player2)
                  EGroup_Single(weaponsboat, entity)
    			  
    			  
    
    
    					-----axis bunkers-----
    				
    
    
    				
    			  --bunker_BP = BP_GetEntityBlueprint("ebps/environment/art_ambient/objects/defenses/concrete/bunkerm01_02.lua")
                  --bunker = EGroup_CreateIfNotFound("bunker")
                  --EGroup_Clear(bunker)
                  --local entity = Entity_CreateENV(bunker_BP, Util_GetPosition(mkr_bunker1), Util_GetPosition(mkr_bunkerface1))
                  --Entity_SetPlayerOwner(entity, player1)
                  --EGroup_Single(bunker, entity)
    				
    				
    
    
    					-----allies 1-----
     
    
    
    
                  sg_allies2 = BP_GetSquadBlueprint("sbps/races/allies/soldiers/engineer_infantrya.lua")
                  allies_02 = SGroup_CreateIfNotFound("allies_02")
                  Util_CreateSquadsAtMarker(player1, allies_02, sg_allies2, alliesspawn1, 1)
     
           
     
                  sg_allies3 = BP_GetSquadBlueprint("sbps/races/allies/soldiers/battle_sim_ranger_team_bazooka.lua")
                  allies_03 = SGroup_CreateIfNotFound("allies_03")
                  Util_CreateSquadsAtMarker(player1, allies_03, sg_allies3, alliesspawn1, 1)
     
           
     
              
                   
     
     
    							---- allies 2 ----
     
    
    
                 
     
                  sg_allies2 = BP_GetSquadBlueprint("sbps/races/allies/soldiers/engineer_infantrya.lua")
                  allies_02 = SGroup_CreateIfNotFound("allies_02")
                  Util_CreateSquadsAtMarker(player2, allies_02, sg_allies2, alliesspawn10, 1)
     
           
     
                  sg_allies3 = BP_GetSquadBlueprint("sbps/races/allies/soldiers/battle_sim_ranger_team_bazooka.lua")
                  allies_03 = SGroup_CreateIfNotFound("allies_03")
                  Util_CreateSquadsAtMarker(player2, allies_03, sg_allies3, alliesspawn10, 1)
     
                              
     
                  
                  
                  ------axis troops player3-----
    
    
    
                  
    		  sg_bunkermg1 = BP_GetSquadBlueprint("sbps/races/axis/soldiers/heavy_machine_gun_autotarget.lua")
    		  bunkermg_01 = SGroup_CreateIfNotFound("bunkermg_01")
                  Util_CreateSquadsAtMarker(player3, bunkermg_01, sg_bunkermg1, mkr_garrison1, 1)
                  Cmd_InstantGarrison(bunkermg_01, bunkerbig1)
    		  Cmd_Attack(bunkermg_01, mkr_mg2,true, -1)
     
    						  
    		  sg_axis2 = BP_GetSquadBlueprint("sbps/races/axis/soldiers/sniper.lua")
                  axis_02 = SGroup_CreateIfNotFound("axis_02")
                  Util_CreateSquadsAtMarker(player3, axis_02, sg_axis2, mkr_garrison1, 1)
                  Cmd_InstantGarrison(axis_02, bunkerbig5)
    			  
    			  
    		 			  
                  ------axis troops player4----
    
    
     
                  sg_axis2 = BP_GetSquadBlueprint("sbps/races/axis/soldiers/sniper.lua")
                  axis_02 = SGroup_CreateIfNotFound("axis_02")
                  Util_CreateSquadsAtMarker(player4, axis_02, sg_axis2, mkr_garrison4, 1)
    		  Cmd_InstantGarrison(axis_02, bunkerbig4)
                  ---Cmd_Garrison(axis_02, bunker3)
     
     
    
    		  sg_axis10 = BP_GetSquadBlueprint("sbps/races/axis/soldiers/officer_squada.lua")
                  axis_10 = SGroup_CreateIfNotFound("axis_10")
                  Util_CreateSquadsAtMarker(player4, axis_10, sg_axis10, mkr_garrison6, 1)
    end
     
     
    						---fly overs---
     
           
     
    function flyover()
     
     
    			  Cmd_Ability(player1, ABILITY.SP.CAEN_RECON_RUN, mkr_plane1, Marker_GetDirection(mkr_plane1), true)
    			  Cmd_Ability(player1, ABILITY.SP.CAEN_RECON_RUN, mkr_plane2, Marker_GetDirection(mkr_plane2), true)
    			  Cmd_Ability(player1, ABILITY.SP.CAEN_RECON_RUN, mkr_plane3, Marker_GetDirection(mkr_plane3), true)
     
    end
     
           
     
    function flyover1()
     
    			  Cmd_Ability(player1, ABILITY.SP.CAEN_RECON_RUN, mkr_plane1, Marker_GetDirection(mkr_plane1), true)
    			  Cmd_Ability(player1, ABILITY.SP.CAEN_RECON_RUN, mkr_plane2, Marker_GetDirection(mkr_plane2), true)
    			  Cmd_Ability(player1, ABILITY.SP.CAEN_RECON_RUN, mkr_plane3, Marker_GetDirection(mkr_plane3), true)
    
    end 
     
     
    					
    					-----starting artillery-----
     
     
     function demo1()
     
    			  Cmd_Ability(player1, ABILITY.SP.SINGLE_CREEPING_MORTAR, Marker_GetPosition(mkr_demo1), nil, true)
    			  
    			  
    end
    
    
    
    function artillery1()
           
    
                  Cmd_Ability(player1, ABILITY.SP.SINGLE_HOWITZER, Marker_GetPosition(introarty1), nil, true)
     
     
    end
     
     
                  ---artillery through out game---
     
    function mortar1()
           
     
                  Cmd_Ability(player1, ABILITY.SP.SINGLE_MORTAR, Marker_GetPosition(arty1), nil, true)
    
    
    end

    As with you code, it seems ok to me. But since you are trying to spawn 3 different types of units, try this...


    Code:
    function reinforcement()
    
    sg_support1 = SGroup_CreateIfNotFound("sg_support1")
    Util_CreateSquads(player2, sg_support1, 
    SBP.AXIS.VOLKSGRENADIER, rf_1, nil, 3)
    
    sg_support2 = SGroup_CreateIfNotFound("sg_support2")
    Util_CreateSquads(player2, sg_support2, SBP.AXIS.GRENADIER, rf_1, nil, 1)
    
    sg_support3 = SGroup_CreateIfNotFound("sg_support3")
    Util_CreateSquads(player2, sg_support3, SBP.AXIS.PANTHER, rf_1, nil, 1)
    
    end

  14. #64
    I know what is problem now. I remove Setup Player name and everything go fine.

    How do u i know unit name like "SBP.AXIS.PANTHER"?

  15. #65
    Member SsOullesS's Avatar
    Join Date
    Nov 2008
    Location
    Eastern Front
    Yeah, same thing. For some reason that command won`t work.
    Everything else work`s excellent.
    Anyway, our petition for separate section for SCAR remained unanswered by Admin, so how about making a Sticky Thread in Map`s Bunker for SCAR maps?
    Just like "Map List", but exclusively for SCAR (map`s).
    It would be better to have them all on one place, instead of chasing them around forums.

  16. #66
    HI Guys im having a problem w/ my map scar...

    if i choose annihilate and start the game, it starts up showing the victory points and icons etc...however, when ppl capture the points, the VP tickers dont go down...its as if the victory points are there but dont matter

    additionally, it never seems to get past OnGameSetup()...

    heres the code:
    Code:
    import("ScarUtil.scar")
    
    function OnGameSetup()
    -- 	-- define player variables used by various functions
    	-- g_CheckAnnihilate = true
       
    
    	
    	player1 = Setup_Player(1, "Americans","Allies",1)
            player2 = Setup_Player(2, "Americans","Allies",1)
            player3 = Setup_Player(3, "Axis","Axis",2)
            player4 = Setup_Player(4, "Axis","Axis",2)
    
    
    	
    end
    
    function OnInit()
    	
    	Rule_AddInterval(bombingRuns, 30)
    -- 	--for starter units use markers 29-33
    
    end
          Scar_AddInit(OnInit)
    
    function bombingRuns()
    	--use markers 5-28
    	plyr=World_GetPlayerCount()
      	if World_GetRand(0, 1) == 0 then 	  
    		bomber = World_GetPlayerAt(World_GetRand(1, plyr))  
    		mark=Marker_FromName("mkr_"..World_GetRand(5,28), "cyan_marker")	
    		target = Util_GetPosition(mark)
    			target.x = target.x + World_GetRand(-50, 50)
    			target.z = target.z + World_GetRand(-50, 50)
    		direction = Marker_GetDirection(mark)
    			direction.x = direction.x + World_GetRand(-90, 90)
    			direction.z = direction.z + World_GetRand(-90, 90)
    		btype = World_GetRand(0,3)
    		if btype == 0 then
    			Cmd_Ability(bomber, BP_GetAbilityBlueprint("abilities/ally_air_strike_ability_rockets.lua"), target, direction, true)
    		elseif btype == 1 then
    			Cmd_Ability(bomber, BP_GetAbilityBlueprint("abilities/off_map_artillery_ability.lua"), target, direction, true)
    		elseif btype == 2 then
    			Cmd_Ability(bomber, BP_GetAbilityBlueprint("abilities/overwatch_barrage.lua"), target, direction, true)
    		elseif btype == 3 then
    			Cmd_Ability(bomber, BP_GetAbilityBlueprint(ABILITY.COMMANDER_TREE.ALLIES.STRAFE_MG), target, direction, true)
    		end
    end
    	
    end
    
    function reinforceRohan()
    	--use marker 4
    	
    end
    
    
    function reinforceCorsairs()
    	--use marker 3
    	
    end
    The Specialized Production Mod is released!
    Also, Check out My new Mod

  17. #67
    Member SsOullesS's Avatar
    Join Date
    Nov 2008
    Location
    Eastern Front
    I made a new thread in Map`s bunker, list for SCAR map`s only, so be free to post your work.
    Here`s the link.

  18. #68
    sadflux
    Guest
    Hi, I'm new

    The tutorial is realy nice good work!

    But I have the same problem, too. I can`t implement any SCAR to my maps (not even the basic one) every time I start playing (right after loading) the game freezes.

    after I double click pause it starts again but no SCAR is executed !?

    Have anybody the solution of this problem?

    thx
    Last edited by sadflux; 20th Aug 09 at 10:55 AM.

  19. #69
    Mobius
    Guest
    It doesn't seem to work, I tried to spawn stuff and it doesn't seem like its trying to read it period.


    Now I must of did something cuz its freezing at the beginning of the game. But when I hit Pause it kicks back in but still nothing happens

    here is what I have.

    SCAR SO FAR

    Last edited by Mobius; 5th Sep 09 at 4:25 PM.

  20. #70
    Member SuperWarDude's Avatar
    Join Date
    Aug 2009
    Location
    Under your couch...

    help plz

    help! the download for the SCAR command library is gone! i really need it. can anyone bring it back?

    9-28-09 - It has been a long 14 days and still no answer. man i need those commands. The file is missing dude.
    Last edited by SuperWarDude; 28th Sep 09 at 5:49 PM. Reason: Classified

  21. #71
    Same here,

    I got some idea's that I like to try to run through SCAR, but I need to see that Relic libary page. The link just brings you to a missing file page.

    Please if there is a new link post it.

  22. #72
    I'm assuming this is what you are after, all the function lists? http://www.europeinruins.com/ScarDoc/scar_doc.htm

  23. #73
    yes

    thank you!

    This appears to be it.

  24. #74

    Some more advanced SCAR

    Hi guys,

    Been a long time since I've done anything with this thread, but have had a few requests recently for more commands, so here's some extras, each with a short explanation. Please be sure you're comfortable with the more basic scar before attempting to use them!




    Making a building or other Entity appear on the map:

    Code:
    eg_p2logist = EGroup_CreateIfNotFound("eg_p2logist")
    Util_CreateEntities(player1, eg_p2logist, BP_GetEntityBlueprint("ebps/races/axis_panzer_elite/buildings/logistik_kompanie"), s_basespawn, 1, secretbase)
    This will make a panzer elite building appear on the map (at marker "s_basespawn", facing marker "secretbase"). You can change the building type by looking up the appropriate blueprint from the LUACONSTS file or the online guide)

    Util_CreateEntities(PLAYER, EGROUP, BLUEPRINT("BLUEPRINT-PATH"), LOCATIONMARKER, NUMBER, FACINGMARKER)




    Making an entity invulnerable:

    Code:
    EGroup_SetInvulnerable(eg_bridgemiddle, true)
    The "eg_bridgemiddle" is the name of the entity group (egroup), and the "true" bit means it is invulnerable. You can set this to false again later on.




    Setting up AI type and turning off the Command Points UI:

    Code:
    UI_BindingSetEnabled("company_commander", false) --Turns off Commander UI
    
    AI_Enable(player1, false) --Turns off AI on this player
    Fairly straightforward commands - by default the commander tree and AI are enabled so you don't need to use these commands if you want them on.




    Checking if a player has units within a certain radius of a marker:

    Code:
    if Prox_ArePlayersNearMarker(player3, secretbase, false, 30) then
    This is our first look at an "if" command. You must always end "if" commands within a function, for example:

    Code:
    function IsPlayer3Near()
    
    if Prox_ArePlayersNearMarker(player3, secretbase, false, 30) then
    
    --DO STUFF
    
    Rule_RemoveMe() --Once this rule is triggered once, it will be removed, otherwise it will continue to repeat.
    
    end --this ends the "if" part of the function, commands in this section will only run if the "if" conditions are true
    
    --Anything here will run regardless of if the "if" conditions are true or not
    
    end --this ends the function
    In this example, we can set code for if any units belonging to player3 get within a radius of 30 of the marker "secretbase". Usually you need to set check commands like this on an interval in order for them to work correctly (otherwise it will check once, and then give up).

    The "Rule_RemoveMe()" part is not essential, but you'd usually include it. Don't set the check interval (use an Add Interval Rule command) for this too frequently, as these commands are processor intensive - usually every 10 seconds or so is sufficient.




    Set units controlled by AI to patrol an area:


    Code:
    sg_bbdefpar2 = SGroup_CreateIfNotFound("sg_bbdefpar2")
    Util_CreateSquads(player1, sg_bbdefpar2, SBP.ALLIES.PARATROOPER, s_fsentry19, nil, 1)
    
    Cmd_SquadPatrolMarker(sg_bbdefpar2, s_fsentry19)
    
    SGroup_IncreaseVeterancyRank(sg_bbdefpar2, 2, true)
    Cmd_InstantUpgrade(sg_bbdefpar2, UPG.ALLIES.PARATROOPER_AT, 2)
    There's quite a lot of code here...hopefully you can see that the first part creates the sgroup and spawns a squad of paratroopers at our marker. The last part increases their veterancy, and arms them with recoiless rifles.

    The middle part is the key bit here - it sets the squad to patrol near the marker "s_fsentry19". You MUST have set a radius in WB around this marker for the command to work, and this is the radius they will patrol in. You'll also need to use the "AI_Enable" command from above to make the AI obey the rule.




    Make troops use their special abilities:

    Code:
    Cmd_Ability(sg_temp, BP_GetAbilityBlueprint("abilities/camouflage_toggled.lua"), nil, nil, true)
    This bit of code will make a unit with the camo ability use it (for example, a sniper) - they must have the ability already. You can lookup more abilities from the LUACONSTS file/online.

    Be sure that when this code runs that the squad exists, and hasn't been killed. Make sure part of your code removes this command from running if the unit doesn't exist or has been destroyed. See the section on using a unit artillery command for an example.




    How to inflict a critical hit on a vehicle using code:

    Code:
    Cmd_CriticalHit(player5, sg_blackbaron, BP_GetCriticalBlueprint("critical/vehicle_destroy_engine.lua"), BP_GetDamageBlueprint("damage/damage_green.lua"))
    All of the caveats from the last bit of code apply to this - the unit must exist and not have been killed. In this example, our "sg_blackbaron" unit will take critical engine damage. Lookup more criticals from luaconsts.




    How to construct a slit trench and have a unit garrison it:


    Code:
    eg_trench1 = EGroup_CreateIfNotFound("eg_trench1")
    Util_CreateEntities(nil, eg_trench1, BP_GetEntityBlueprint("ebps/races/allies_commonwealth/buildings/slit_trench.lua"), trenchhq1, 1, trenchhq1f)
    
    sg_ownpara1 = SGroup_CreateIfNotFound("sg_ownpara1")
    Util_CreateSquads(player3, sg_ownpara1, SBP.CW.COMMANDOS, s_trenchspawn, nil, 1)
    Cmd_Garrison(sg_ownpara1, eg_trench1, true, false)
    Part 1 of this code matches up well with the create entity code from above - and all comments apply. This creates a trench and faces it towards another marker.

    Part 2 creates a squad, and issues them the garrison command to make their way to it, and climb in. This will be cancelled if another unit occupies it first.

    You can also use the command "Cmd_InstantGarrison" with the same variables to make them instantly occupy it without moving or animating (be careful that the player doesn't see it!).

    You can also use both of these garrison commands on a group of buildings - for example if you used worldbuilder to make an entity group consisting of a group of houses, the squads issued the garrison command will randomly select a particular house and occupy it. Be careful not to overload the houses or the troops won't be able to enter them!




    Use random chance to get different functions to run:


    Code:
    function specmanager()
    
    local randpickp = World_GetRand(1, 8)
    
    --randpickp = 6--TESTING
    
    		if randpickp == 1 then 
    		Rule_AddOneShot(spawnspecsnipers, 10)
    
    		elseif randpickp == 2 then 
    		Rule_AddOneShot(calliopeattack, 10)
    
    		elseif randpickp == 3 then 
    		Rule_AddOneShot(commandoattack, 10)
    
    		elseif randpickp == 4 then 
    		Rule_AddOneShot(spawntanks, 10)
    
    		elseif randpickp == 5 then 
    		Rule_AddOneShot(specsecretbaseland, 10)
    
    		elseif randpickp == 6 then 
    		Rule_AddOneShot(specsecretbaseair, 10)
    
    		elseif randpickp > 6 then 
    		Rule_AddOneShot(specarty, 10)
    
    		end
    
    end
    Quite a lot of code here

    The first part it the most important - "local randpickp = World_GetRand(1, 8)" assigns a local variable (it can only be used within this function, and will create a different number each time the function is run) to the name "randpickp", and gives it a value between 1 and 8.

    World_GetRand(min value, max value).

    The "if" command then matches the number to a possible set of outcomes (notice we use "elseif" after the first "if") - we use "==" to match to a specific number, or the < (less than) > (greater than) operators.

    The commands within the "if" lines could be whatever you wanted. You can see I've commented out (--) the testing variable - which would override the random number and set it to a particular number. This is useful for testing that all parts of the code work - the more randomisation, the more can potentially go wrong!




    Randomly generated unit types from a list:

    Code:
    function spawntanks()
    
    types_tank1 = {SBP.CW.CHURCHILL_CROC, SBP.ALLIES.PERSHING, SBP.ALLIES.PERSHING}
    types_tank2 = {SBP.CW.FIREFLY, SBP.ALLIES.CROCODILE}
    
    	sg_spectanks = SGroup_CreateIfNotFound("sg_spectanks")
    	sg_spectanks1 = SGroup_CreateIfNotFound("sg_spectanks1")
    
    	Util_CreateSquads(player3, sg_spectanks, types_tank1, s_north2, nil, 1)
    	Util_CreateSquads(player3, sg_spectanks1, types_tank2, s_north2, nil, 3)
    
    end
    This is a slightly different way of spawning units - instead of supplying a definite unit, we give the AI a list to randomly choose from, like so:

    types_tank1 = {SBP.CW.CHURCHILL_CROC, SBP.ALLIES.PERSHING, SBP.ALLIES.PERSHING}

    "types_tank1" is simply a variable name we can use later on (notice it replaces the normal SBP. part of the createsquad command) - you can call this whatever you like.

    The parts within { } are simply a list, separated by commas. This list can be as long or short as you like. Be aware that you can list units multiple times to make them a more likely choice for the AI. In the example above, there's a 66% chance of getting a pershing, a 33% chance of getting a Churchill Croc. Be careful not to mix your unit types too much in these tables, as there can be a big difference between spawning some riflemen, or spawning a pershing...




    Creating randomised artillery fire:
    Code:
    -- Get random position near position
    function Util_GetRandomOffset(pos, mindist, maxdist)	
    	local newpos = pos
    	newpos.x = newpos.x + World_GetRand(mindist, maxdist)
    	newpos.z = newpos.z + World_GetRand(mindist, maxdist)
    	return newpos
    end
    This is code written by Mannerheim for his D-Day mod - and it's very useful! You just need to have it somewhere within your scar file, and other functions will use it later on.

    Code:
    local depot_targetc = Util_GetPosition(Marker_FromName("tarty"..World_GetRand(1, 6), "red_marker"))
    
    Cmd_Ability(player1, ABILITY.COMMANDER_TREE.ALLIES.HOWITZER_SHOOT, Util_GetRandomOffset(Util_GetPosition(depot_targetc), -30, 30), nil, true)
    This code has two parts, the first creates a local locations near a random set of markers ("tarty1" to "tarty6" - you'll need the full set 1, 2, 3, 4, 5, 6 to make this work).

    The second part uses the randomoffset function (above) and the commander tree Howizter ability to fire within a random 30 radius of one of these markers. It doesn't cost the player any resources, and they don't even need to have the ability unlocked!




    Getting an existing artillery unit to fire at a location:

    Code:
    function Howfiref1() -- 
    
    --Must have sg group and unit added on WB
    
    if SGroup_GetAvgHealth(sg_priestn1) > 0.01 then
    
    local Howtar1 = Util_GetPosition(Marker_FromName("arty"..World_GetRand(1, 19), "red_marker"))
    
    Cmd_Ability(sg_priestn1, ABILITY.CW.PRIEST_BARRAGE, Util_GetRandomOffset(Util_GetPosition(Howtar1), -30, 30), true)
    
    elseif SGroup_GetAvgHealth(sg_priestn1) == 0 then
    Rule_RemoveMe()
     
    end
    end
    Unless this has been fixed in a recent update, you must already have the unit on the map and an sgroup assigned to it in WB for this code to work.

    Going through the code, first of all, it checks that the unit hasn't been destroyed (it's health is greater than 0.01) - if it has, the function will cancel and be removed.

    In this particular example, we're using a priest to randomly fire at a large number of possible locations - to make this work with other units, you just need to change the ability called in (lookup in luaconsts). Bear in mind that the unit will need to recharge as normal (and not be controlled by an enabled AI) before it can fire again.

    Code:
    Modify_AbilityMaxCastRange(player1, ABILITY.CW.PRIEST_BARRAGE, 10)
    You might also find this useful, as it boosts the range of the ability and stops it from failing if the target is too far away: this increases the range of the priest ability for player1 by 10x.




    A more efficient way of spawning lots of troops at different locations:

    Code:
    function spawnsnipers()
    
    	for i = 1, 4 do 
    
    		local randsnipe = World_GetRand(1, 7)
    		local sg_temp = SGroup_CreateIfNotFound("sg_bbhell" .. randsnipe)
    		local morein = Util_GetPosition(Marker_FromName("s_ambush" .. randsnipe, "basic_marker"))
    		local mopos = Util_GetPosition(Marker_FromName("m_ambush" .. randsnipe, "grey_marker"))
    
    		Util_CreateSquads(player4, sg_temp, SBP.ALLIES.SNIPER, morein, nil, 1)
    		Command_SquadPos(player4, sg_temp, SCMD_AttackMove, Util_GetPosition(mopos), 15)
    
                    end
    
    end
    We're getting into some more advanced stuff now - using the "for" command. This command is useful as it will quickly work through the code multiple times in a simple "loop". Loops are a way of minimising the amount of code you need to write, but are a little harder to understand. They also need their own "end" within the function, like "if" commands.

    The "for" command uses the local variable "i" - so we initially set this as "1", and then tell the loop to repeat ("i" increases by 1 each time the loop repeats) until it reaches the number "4" - the loop will run 4 times before stopping.

    Using the randomisation techniques shown earlier, we randomly choose from 7 possible locations for the sniper to spawn, and 7 possible locations for him to move to. The loop will do this 4 times, randomly spawning and moving 4 snipers from and to different destinations! Due to the random element, this will tend to spawn and position units differently each time the map is run - and it's also possible that more than 1 of the snipers could spawn from and move to the same location.




    Summary

    I hope you've found this helpful, and I'll try to answer any questions about these commands, or any other particular things you'd like Scar code to be able to do.
    Last edited by Sando; 6th Apr 11 at 10:56 AM. Reason: Readability

  25. #75

  26. #76

    How to Setup Objectives

    Thanks Bergy

    Ok here is one more frequently requested area of code - setting in game objectives for the player using the inbuilt functions. These will appear in the same way as for the campaign maps in COH - the player will see a reminder on the left hand side of the screen, and text will flash up telling the player what they need to do to complete the objective. The only limitation here is that in multiplayer games, the objectives will appear for all players - regardless of which team they are on. This means that they work best for single player and co-operative (vs AI) games, although with careful wording you can use them for versus multiplayer as well.

    Objective functions are relatively complex, and I'd recommend you use them on a test map initially in order to get the hang of how they work. Would also recommend you're comfortable with basic scar coding before attempting this - or frustration could ensue!

    We'll split up the different objectives functions into more managable chunks, here's the first one:

    Make sure you include this code as a block somewhere in the file, as a separate function (it's one that Mannerheim wrote that's very handy for constructing strings)

    Code:
    --Setup Local Locs
    function Util_CreateLocString(text)
    local tmpstr = LOC(text)
    tmpstr[1] = text
    return tmpstr
    end
    Code:
    function StartSetupOb()
    
    ObjectiveInit_Setup()
    Objective_Start(OBJECTIVE_Setup, true)	
    
    end
    This first function is relatively simple - it starts our objective and loads the next chunk of objective code. You need to ensure that the names of your objective and objective function match up with the next section - although can call them whatever you like. The part you change to alter the name is the parts after the _. So in this case, our objective is called "Setup". If you wanted to change this it would look like this:

    ObjectiveInit_YOURNAME()
    Objective_Start(OBJECTIVE_YOURNAME, true)

    This is the only section of code you need to launch directly in order start up the rest of the objective code. A simple "Rule_AddOneShot(StartSetupOb, 10)" would do the trick.



    Code:
    function ObjectiveInit_Setup()
    
    local Setup_TITLE = Util_CreateLocString("Prepare Your Defences")                                                 -- This will be the title of your objective that appears on the left hand side of the screen for players - keep it short!
    local Setup_STARTMSG = Util_CreateLocString("Allied forces are preparing to attack, dig in!")         -- This is the message that will appear in the middle of the screen when the objective first starts.  Be more descriptive, but try to keep it concise.
    
    	OBJECTIVE_Setup =              -- Change the name after the _ to match your objective.
    	{
    		SetupUI = function()     -- Set up the UI for the function, leave this as it is.  Due to the name of this function the "Setup" part of it could be confusing, but this is actual code.
    		end,
    
    		OnStart = function()
    			Objective_StartTimer(OBJECTIVE_Setup, COUNT_DOWN, 4 * 60)     -- For this particular example, we're using a timer to count down how long the objective can last for, this is in seconds, in this example 4 x 60 = 240, or 4 minutes.  Again, change the name after the _
    			-- Start checker
    			Util_PlayMusic("SOUND/Music/coh_four_minute_suspense", 6, 0)	  -- I've added an extra bit of code here to kick in the game's music system with a particular track - you don't need to do this!
    			Rule_AddInterval(ObjectiveCheck_Setup, 10)			                  -- We're using this bit of code to setup an interval rule to check if it the objective has been completed, it will run the code in the next section below
    		end,
    		
    		OnComplete = function()
    		end,
    		
    		IsComplete = function()			
    			return false			
    		end,
    		
    		OnFail = function()
    		end,
    		
                                                                                                       -- These 3 bits of code need to be here, include them, and don't change them yet!  Basically they register the objective hasn't been complete, and allow you to specify commands if the objective is completed or failed...however we're doing this from the checker function so don't need to do so.
    
    		Title = Setup_TITLE,
    		Description = Setup_TITLE,
    		DisplayTitleStart = Setup_STARTMSG,
    		Icon = IT_P_Defend,
    		Type = OT_Primary,
    
                                                                                                      -- These bits of code are again necessary, although you can alter them more.  As you can hopefully see, the first 3 parts refer to the strings we setup at the start of the function
                                                                                                      -- The top 3 lines should be left alone, aside from changing the Setup_ parts to match. 
                                                                                                      -- The final 2 lines can be altered and describe which kinds of icons to use for the objective when it is displayed to the player.  Here we've used a "defend" icon, and a "primary" mission objective.  You can alter these as detailed below.
    	}
    	
    	Objective_Register(OBJECTIVE_Setup)                            -- Registers the objective with the game engine, leave this as it is, aside from changing the "Setup" part at the end to the name of your objective.
    end
    Ok, there's a lot to look at there - I've included some comments for individual bits. I'd recommend you maybe copy this code as is, and try it out before changing anything. The most important thing to look out for is to alter the parts where the code reads SOMETHING_Setup - you need to change the part after the _ to match your objective name.

    In this particular example, we're setting up a simple time rule (4 minutes) - the timer will be displayed next to the objective title on the player's screen so they can see how long they have to complete the objective. Ok, now on the final part:



    Code:
    -- Setup objective timer
    function ObjectiveCheck_Setup()
    	-- Check if done
    	if Objective_GetTimerSeconds(OBJECTIVE_Setup) < 1 then
    		Objective_Complete(OBJECTIVE_Setup)
    		StartConvoyObWait()
    		Rule_RemoveMe()		
    	end
    end
    A nice neat little check function to finish up with. You can see from the previous part that we launched an interval rule for this function, to keep checking whether the objective is complete or not yet. This uses one of the "if" rules I explained in the previous post - basically what this does is checks to see whether the timer we setup in the previous function has counted down to below 1 yet (<1). Once it has, the "Objective_Complete(OBJECTIVE_Setup)" will be set as complete, and will shown as such in the UI. Again, all you need to change here is the part after the _ to the name of your objective.

    Next, I have some code running "StartConvoyObWait()" that will load the function for the next objective - putting a function name with a () behind it is the same as using a "Rule_AddOneShot(FUNCTIONAME, SECONDSTOWAIT), except the function will be run immediately.

    Finally, we have "Rule_RemoveMe()" - this will stop this function from repeating anymore (it's currently on a 10 second interval). We don't need it to, and leaving it running could cause us problems. There's an "end" to finish the "if" part of the function, and another "end" to finish the function itself.

    Ok....so there's a complete objective function - there's quite a lot of code involved, but hopefully you can see what we're doing with it. This is quite a simple objective, as there's only 2 possible outcomes from it - either the timer will tick down successfully, or the player(s) will be defeated before this happens. I'd suggest you have a go with this yourself, and see if you can get it to work.



    A more complex objective:


    In this example, we're going to setup some code with more potential outcomes. There's no real limit on how many potential outcomes you can setup - for example if a player partially completes the objective you could program a slightly different outcome. You could even randomise the outcome so that the map plays out differently each time!


    Code:
    function StartConvoyOb()
    
    ObjectiveInit_Convoy()
    Objective_Start(OBJECTIVE_Convoy, true)
    
    end
    Ok, the same as last time - hopefully this will help you see which parts of the code we need to change for a new objective name. Please be aware, due to some lazy coding on my part, the name of the objective doesn't completely match up with it's content - don't worry about this, as the code names never show up ingame and the players will never know any different! However, you shouldn't really follow my example here, and should name your objectives properly! On to the main body of the objective:



    Code:
    function ObjectiveInit_Convoy()
    
    local Convoy_TITLE = Util_CreateLocString("Protect the General")
    local Convoy_STARTMSG = Util_CreateLocString("The Obergruppenfuhrer must stay alive until reinforcements arrive...")
    local Convoy_HINT = Util_CreateLocString("Protect the General")      --This time we're also going to setup one of the green arrows that hovers above an objective marker or unit - this is the text that will appear there.  Again, keep it short!
    
    
            OBJECTIVE_Convoy =
            {
                    SetupUI = function()
                    OBJECTIVE_Convoy.PingID = UI_CreateMinimapBlip(sg_command, -1, BT_ObjectivePrimary)            -- This time we're adding some extra information to the objective UI.  This part will great a green circle around the unit "sg_command" on the mini-map.  You can use different ping markers here such as "BT_ObjectiveSecondary" for a yellow marker.
    
                    OBJECTIVE_Convoy.HintID = HintPoint_Add(sg_command, true, Convoy_HINT)            -- This sets up the green arrow text from above, attaching it to the unit "sg_command", and it will follow him around the map.
    
                    end,
    
                    OnStart = function()
                            Objective_StartTimer(OBJECTIVE_Convoy, COUNT_DOWN, 26 * 60)          -- Again, we're setting up a timer, in this case for 26 minutes, a long time!
                            Rule_AddInterval(ObjectiveCheck_Convoy, 3)                                            -- We're setting up a checker for the objective again, see below
    
                            attackmanager1()                                               
    			convoymanager()                                                                                        -- This time, we're starting several other functions at the same time - these refer to other parts of our scar file, and don't need to be included  
                              
                            Util_PlayMusic("SOUND/Music/omg/motivation/the_blitz_v2", 6, 0)            -- Again, playing some music, unnecessary
                            --Camera_MoveToPosition(attacktownright, true)                                      -- This code is commented out as it proved annoying, but it might be a useful thing to know - it moves all players cameras to the scar marker "attacktownright"
                    end,
    
                    OnComplete = function()
                    end,
    
                    IsComplete = function()
                            return false
                    end,
    
                    OnFail = function()
                    end,
    
                    Title = Convoy_TITLE,
                    Description = Convoy_TITLE,
                    DisplayTitleStart = Convoy_STARTMSG,
                    Icon = IT_P_Defend,
                    Type = OT_Primary,
            }
    
            Objective_Register(OBJECTIVE_Convoy)                      -- The rest of this code is the same as above, bar we've changed the objective names to match
    end

    Ok quite a lot here, but you can see that most of it is the same. I've left in some bits of extra code so that you can see that you can run other functions off this objective code, as you would any other function. The main difference here is that we've setup some hint and minimap icons to make it easier for the players to see where the objective unit is, and easy to pick out from other units.



    Finally, on to the checker code, this is a little more complex this time:


    Code:
    function ObjectiveCheck_Convoy()
            -- Check if done
    
            if Objective_GetTimerSeconds(OBJECTIVE_Convoy) < 1 then
    
                    Objective_Complete(OBJECTIVE_Convoy)
                    UI_DeleteMinimapBlip(OBJECTIVE_Convoy.PingID)
                    HintPoint_Remove(OBJECTIVE_Convoy.HintID)
    
                    StartTownSquareObWait()
    
                    Rule_RemoveMe()
    
                                                                       -- The above code is one potential outcome from our objective, i.e. that the timer counts down without the other outcome coming into force.  Notice that we complete the objective, and also need to remove the UI blip (minimap) and the Hint (green arrow) above the unit - as otherwise they will stay until the end of the game!
    
            elseif SGroup_GetAvgHealth(sg_command) == 0 then          -- This code checks if the unit "sg_command" is dead - i.e. it has 0 health.  If you include more than 1 unit in this sgroup, they must all be dead for this to register.
    
                    UI_DeleteMinimapBlip(OBJECTIVE_Convoy.PingID)
                    Objective_Fail(OBJECTIVE_Convoy)
                    HintPoint_Remove(OBJECTIVE_Convoy.HintID)
    
                    allieswin1()
                    
                    Rule_RemoveMe()
    
                                                                                                         -- Again, we need to remove the minimap blip and the hint, or they will hover over the unit's last location.  Notice that this time we used the code "Objective_Fail" - the players did not complete this objective successfully.  This will not automatically make them lose the map, or have any other effect than telling them that they failed their objective.  It's up to you to code the outcome of this.
    
            end
    end
    Again I've tried to add lots of comments to the relevant bits of this code. You can hopefully see that because of the "if" / "elseif" split, the code will follow one of two potential paths - either the unit will still be alive when the timer reaches 0, or it won't. Depending on the outcome of these tests, we instruct the code to load a different set of functions for what happens next. There's no reason why you couldn't have more potential outcomes here by adding more "elseif" statements - for example we could have an elseif that doesn't end the objective or remove the rule, but instead sends a message if the "sg_command" unit's health goes below 20% ("<0.2" - sgroup functions are always decimal - 1.0 = 100%, 0.2 = 20%) to warn the players!

    Ok, that's probably enough for now on objectives - give these a try and see how you get on! I'll try and answer any questions.

    Finally, here's a few alternative settings or check criteria you may find useful:


    Ping types:

    BT_ObjectiveSecondary (yellow)
    BT_ObjectivePrimary (green)
    BT_ObjectiveMedal (Purple/Brown)

    Objective Icon Types:

    IT_P_Capture
    IT_P_Defend
    IT_P_Attack (** not sure on this one!)

    Objective check criteria:

    Code:
    if EGroup_IsCapturedByPlayer(eg_townsquare, player1, ANY) then
    If you setup an egroup on one of your territory markers (e.g. a fuel point) on Worldbuilder, you can use this code to check if a player has captured it.

    EGroup_IsCapturedByPlayer(EGROUP, PLAYER, ANY/ALL) -- the any/all bit is used when there are several entities in the egroup (for example, 3 different territory markers). Any would mean the test is true if any 1 of the 3 points is captured, All would mean that all 3 of them would have to be captured.


    Code:
    if Player_OwnsEGroup(player1, eg_townsquare) then
    A slightly different take on the same code - the change here is not about whether the point is captured or not, but if a particular player owns this point at the time. So this code is more useful for when a player needs to hold a territory point rather than capture it.


    Code:
    if Prox_AreSquadsNearMarker(sg_convoy, spawnallies, ANY, 10) then
    This function checks if a particular sgroup is near a particular scar marker on the map. This can be useful for escort missions where you need to get a particular unit to a particular place. Unlike the prox_IsPlayerNearMarker detailed in the previous post, this function is much more efficient (it only needs to check on a single sgroup, rather than every unit a player owns) and can be used more frequently.

    Prox_AreSquadsNearMarker(SGROUP, MARKER, ANY/ALL, RADIUS_AROUND_MARKER)



    Code:
    if planecount == 3 then
    This is some more custom code - in the example above, I've setup a global variable (like a local one, but can be used in any function in the scar file) called "planecount". This variable can be increased or decreased by various functions throughout the file. Here we check if the custom variable equals the number we want, in which case the objective will be complete. In this example, players had to hold an airfield, and while they did, planes would be coded to appear from the hangers, go down the run way and then take off and despawn. When they despawned, they would be counted, and the objective completed once 3 had taken off.
    Last edited by Sando; 23rd May 11 at 10:18 AM.

  27. #77
    OMG...missed something really obvious from that first post! Sorry guys...

    You need this bit of custom code from Mannerheim to make the named players work: (just include it below as a separate function)

    --Setup Local Locs
    function Util_CreateLocString(text)
    local tmpstr = LOC(text)
    tmpstr[1] = text
    return tmpstr
    end

  28. #78
    Member Searcher64's Avatar
    Join Date
    May 2010
    Location
    United States
    Do you think the file with list of scacr commands you uploaded on filefront on part 2 could be reuploaded? The wiki for scar codes on relic wiki is dead and I don't know where else to get them

  29. #79
    Member Jagdpanther's Avatar
    Join Date
    Dec 2008
    Location
    Berlin
    @Searcher: I do host a copy of the scardoc on my own server. Feel free to use it.

  30. #80
    Member stalkerblaze's Avatar
    Join Date
    Dec 2008
    Location
    Wrocław, Poland
    Is there a way to use special effects with SCAR, like those used with Action Markers?

  31. #81
    You can call effects in a similar way to action markers:

    Code:
    Util_MarkerFX( String markername, String eventfile )
    
    --Play an events file at a given markers location
    You can also do some other funky stuff with the camera, atmosphere settings etc:, can only be used for preset Relic Atmospheres

    Code:
    Game_LoadAtmosphere( String filename, Real transitionTime )
      	
    --Transitions to another atmosphere. Overwrites current transitions.
    Code:
    Game_FadeToBlack(true, 0) --Make game fade to black (over how many seconds)
    Game_FadeToBlack(false, 3)--Opposite
    
    Game_Letterbox(true, 5)--Letterbox mode on (over seconds)
    Game_Letterbox(false, 5)--Letterbox mode off(over seconds)
    
    Camera_FollowSGroup(sg_tiger1) --locks camera on sgroup movements until told not to
    
    Camera_SetOrbit(-100.5)
    Camera_SetZoomDist(35.99)
    Camera_SetDeclination(0.15) -- Set camera to angle
    
    Camera_AutoRotate(Util_GetPosition(Marker_FromName("planespawn", "basic_marker")), 55, 35, 1) --Set camera to auto-rotate around a marker (Camera_AutoRotate( Position target, Real distance, Real declination, Real speed ))
    
    SGroup_SetAnimatorState(SGroup_GetSpawnedSquadAt(sg_trucks, 1), "headlights", "Off") -- Set states of lights, for example on a truck, can be used to set any unit (there's an entity version too) with animator states
    There's various other stuff too, but I haven't played with this stuff much...

    Hope this helps!

  32. #82
    Member Searcher64's Avatar
    Join Date
    May 2010
    Location
    United States
    Thank you for the scar doc, it will work just fine

    Btw, I just tested my first scar file. Everything went well except for one thing, the names.

    Code:
    local player4name = Util_CreateLocString("The Axis Army four")
    local player5name = Util_CreateLocString("The Axis Army five")
    local player6name = Util_CreateLocString("The Axis Army six")
    
    Setup_SetPlayerName(player4, player4name)
    Setup_SetPlayerName(player5, player5name)
    Setup_SetPlayerName(player6, player6name)
    When I go in game, the game freezes, I look at the console and it says it has trouble executing line 13, with error on Util_CreateLocString, am I doing something wrong?
    Last edited by Searcher64; 23rd May 11 at 4:19 PM.

  33. #83
    Yeah my bad on that one - see the post above, you need to include this code somewhere in your file outside of any other functions (I've used it for so long, forgot it was a custom function!)

    --Setup Local Locs
    function Util_CreateLocString(text)
    local tmpstr = LOC(text)
    tmpstr[1] = text
    return tmpstr
    end

  34. #84
    Member stalkerblaze's Avatar
    Join Date
    Dec 2008
    Location
    Wrocław, Poland
    I have been trying this function
    Code:
    Util_MarkerFX("wall_s11","data\art\fx\fx_special\smoke_mortar_01.bfx")
    Trying several ways to write the effect file string, but I always get this


    What am I doing wrong?

    If it turns out that this function doesn't work (I have checked several campaign missions looking for an example), is there another way to just spawn a smoke with function (I will even settle with the basic smoke from mortars)?

  35. #85
    You can spawn an excellent smoke barrage with "SmokeEntrance_Do(spawn10)" - spawn10 being the markername, seems to work with basic and coloured markers.

    I think the problem you're encountering with the MarkerFX could be if you're not using a basic marker - the code it's running is:

    World_FXEvent( eventfile, Marker_GetPosition( Marker_FromName( markername, "basic_marker" ) ) )

    It's possible as well that you're not quite phrasing the special effect properly - I'm not sure which part of the path you need, whether the path is correct to it, or whether you need a helper function to fetch it for you. Either that, or it's an outdated function that's been replaced by one of the more recent patches.
    Last edited by Sando; 25th May 11 at 11:57 AM.

  36. #86
    Member stalkerblaze's Avatar
    Join Date
    Dec 2008
    Location
    Wrocław, Poland
    I tried even running directly that function, but the result was the same.
    I settled for now with making a NIS scene which consists of effects and then running it through SCAR, based on this thread http://forums.relicnews.com/showthre...OH-for-viewing while removing the letterbox and adding this line:
    Code:
    nis_usegamecamera(true)
    so the player can still freely look around.

  37. #87
    Member Searcher64's Avatar
    Join Date
    May 2010
    Location
    United States
    Thanks. It worked, but I have one small inquiry on Util_CreateSquads

    How would you get a squad to spawn, facing a certain direction? I know it may be obvious, but I really have no clue how these mappers figure out these things like Integer blueprintID, Position spawn_facing, Position dest_facing, Position destination etc. etc. Is there a trick to figuring out what to put in these lines? Cause the ScarDoc certainly doesn't tell that...

  38. #88
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    If you want to define the facing direction of a squad, user markers, and rotate them. If you spawn squad to a marker with parameters like this, it will face the rotated arrow. You don't need to make anything special to apply this, since it is default. The squad will face the direction of the arrow in the marker by default.

    Code:
    Util_CreateSquads(player1, sg_squad, SBP.ALLIES.RIFLEMEN, mkr_spawnpos)
    Use keys R and M to swap between move and rotate mode.

    In case you'd like to use an existing marker to define the direction, use these parameters:

    Code:
    Util_CreateSquads(player1, sg_squad, SBP.ALLIES.RIFLEMEN, mkr_spawnpos, nil, nil, nil, nil, nil, nil, mkr_direction)
    Reload Attrib files ingame with SCAR

    Do you need help with SCAR?


  39. #89
    Member Searcher64's Avatar
    Join Date
    May 2010
    Location
    United States
    Ohh thanks...I knew you should be able to rotate markers but didn't know how.

  40. #90
    Member ernesto-m's Avatar
    Join Date
    Jul 2011
    Location
    Karlsruhe / Germany
    Hi folks,

    many thanks for so much excellent SCAR-Tutorial stuff.

    massive mappergrettings
    -ernst-

  41. #91
    Member ernesto-m's Avatar
    Join Date
    Jul 2011
    Location
    Karlsruhe / Germany
    Hi folks,

    i am looking for some special functions :

    1. Is there an possibility to check if a Player ( player1 - n) has any Units/Squads in an area?

    2. How can i find out, which Player ( player 2-n) is an enemy?


    thanks a lot for your feedback

    best mappergreetings
    -ernst-

  42. #92
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    1. To check if player has any squads near by marker:
    Code:
    Player_GetAllSquadsNearMarker(player, sgroup, position, [range])
    Result type: Void.
    
    Gather together all of a player's squads that are in proximity to a marker, a position, or within a territory sector into an SGroup. The SGroup is cleared beforehand.  
    You can override a marker's normal proximity by specifying a range. 
    
    -----------------------------------------------------------------------------
    - For example check if the collected SGroup is empty with command
    Code:
    SGroup_IsEmpty(sgroup)
    2. To check if players are allied, returns false if players are not allied:
    Code:
    Player_IsAllied(playerId1, playerId2)
    Result type: Boolean.
    
    Returns true if the players are allied and false if they are not.

  43. #93
    Member ernesto-m's Avatar
    Join Date
    Jul 2011
    Location
    Karlsruhe / Germany
    hi Jannev,

    many thanks for your fast reply.

    another question to my 1. problem, if the code is:

    Player_GetAllSquadsNearMarker(player, sgroup, position, [range])
    Result type: Void.

    and the reslut of it is VOID, how can a process this? where can i get to correct sgroup, when, for exaple, player2 has units in the range of a marker?

    the background is, i want to fire with artillery in the range of a marker position if an enemy player enter this area.

    worldwide mappergreetings
    -ernst-

  44. #94
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    You'll need to create a new SGroup:
    for example:
    Code:
    sg_artytarget = SGroup_CreateIfNotFound("sg_artytarget")
    I would recommend reading post #27 on this thread, since it handles the basics of SGroups. If you haven't already, please read all messages from the beginning of this thread.

  45. #95
    Member ernesto-m's Avatar
    Join Date
    Jul 2011
    Location
    Karlsruhe / Germany
    ..ok, i will do.

    happy weekend mappergreetings
    -ernst-

  46. #96
    Member ernesto-m's Avatar
    Join Date
    Jul 2011
    Location
    Karlsruhe / Germany
    Hi folks,

    i have read all of Sandos post´s und built in some of his functions in a test map.

    integrated functions are:
    - start and init function
    - modify start ressources
    - troup spawn
    - troup patrol

    after some trouble, now, all the functions work correct, but the game don´t end with a victory, when all enemys are destroyed.

    What´s the mistake? Is it obligatory necessary to define a opbjective?


    one more mappergreetings
    -ernst-

  47. #97
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    You'll need to import wcutil.scar to enable annihilate victory condition because of it is disabled if map has scar file.
    Add
    import("WCUtil.scar")
    below import("Scarutil.scar")

    Note: there is a possibility that this does not work if you have placed squads to for player that normally doesnt get those, e.g. 20mm flack to wehr player.

  48. #98
    Member ernesto-m's Avatar
    Join Date
    Jul 2011
    Location
    Karlsruhe / Germany
    Hi Jannev,

    many thanks for help and your fast reply.

    yellow mappergreetings
    -ernst-

  49. #99

    Advanced Waypoints

    I promised to get round to this a while ago, so here's some stuff about more advanced spawning and waypoints. This is the most basic way of using these, we'll go into some other ones in a separate post.

    Ok, by now you've already got to grips with basic spawning, move commands and order queues - if not, go back and read up first! This technique (as usual, inspired by Mannerheim's excellent scripts) combines the use of loops and waypoint tables to produce a set of random troops from a list, picks a spawn point and route for them to follow, and does this as many times as you set it to.

    Lets have a look at some code, for this basic example, I've put all of the relevant code in a single function, so it's self-sufficient.

    Code:
    function FinalAlly()
    
    FINAL_ATTACK_ROUTES =
    	{
    		-- Final Attack Routes
    		{	
    			{wp = spawnmiddleright, cmd = "S"},
    			{wp = roadmiddlerightback, cmd = "M"},
    			{wp = roadmiddle, cmd = "M"},
    			{wp = attackchurchback, cmd = "M"},
    			{wp = attackchurch, cmd = "AM"},
    			{wp = attacktownbackleft, cmd = "M"},
    			{wp = attackbases, cmd = "M"},		
    		},
    		{	
    			{wp = spawnleft3, cmd = "S"},
    			{wp = roadmiddle, cmd = "M"},
    			{wp = attackchurchback, cmd = "M"},
    			{wp = attackchurch, cmd = "M"},
    			{wp = attacktownbackleft, cmd = "AM"},
    			{wp = attackbases, cmd = "AM"},
    		},
    		{	
    			{wp = spawnright, cmd = "S"},
    			{wp = attackchurchright, cmd = "AM"},
    			{wp = attackchurchback, cmd = "AM"},
    			{wp = attackbases, cmd = "AM"},
    			{wp = attacktownbackleft, cmd = "AM"},
    		},
    	}
    Ok this first chunk gives our function a name, and also names the set of routes as "FINAL_ATTACK_ROUTES" - we can refer to this later in the function.

    What this codes does is creates a series of potential paths for our units to follow. I'll break down a single line:

    {wp = spawnright, cmd = "S"},

    wp is simply the name of your marker in WB, and the cmd is a shorthand way of coding the command we want to use at this particular marker - more on this later. You can see that the paths are divided into sets by the use of {} brackets - each unit will use 1 of these routes, and you can have as many different ones as you like. Be aware, that you can "stack" these routes (use them more than once) to make them more likely to be used.

    Code:
    type_super = {SBP.ALLIES.PERSHING, SBP.ALLIES.PERSHING, SBP.CW.CHURCHILL_CROC, SBP.CW.CHURCHILL_CROC}
    type_heavy = {SBP.CW.FIREFLY, SBP.CW.FIREFLY, SBP.CW.CROMWELL, SBP.CW.CROMWELL, SBP.CW.CROMWELL}
    type_medium = {SBP.ALLIES.SHERMAN, SBP.ALLIES.SHERMAN, SBP.ALLIES.CROCODILE, SBP.ALLIES.M10, SBP.ALLIES.M10, SBP.ALLIES.SHERMAN}
    Next, we setup our unit tables - you'll have already seen these and know what they do.

    Ok, on to the meat of the function!

    Code:
    countallies1 = Player_GetSquadCount(player_Allies2)
    
    if countallies1 < 35 then 
    
    for i = 1, 4 do 
    
    sg_final = SGroup_CreateIfNotFound("sg_final" .. i)
    
    local routeindex = World_GetRand(1, table.getn(FINAL_ATTACK_ROUTES))
    			for j = 1, table.getn(FINAL_ATTACK_ROUTES[routeindex]) do
    				local command = FINAL_ATTACK_ROUTES[routeindex][j].cmd
    				local waypoint = FINAL_ATTACK_ROUTES[routeindex][j].wp
    
    				if command == "S" then
    				Util_CreateSquads(player_Allies2, sg_final, type_super, waypoint, nil, 1)	
    				Util_CreateSquads(player_Allies2, sg_final, type_heavy, waypoint, nil, 1)
    				Util_CreateSquads(player_Allies2, sg_final, type_medium, waypoint, nil, 1)
    				elseif command == "M" then
    				Cmd_Move(sg_final, Util_GetPosition(waypoint), true)
    				elseif command == "AM" then
    				Cmd_AttackMove(sg_final, Util_GetPosition(waypoint), true, nil, 20)
    				end
    
    
    end
    end
    end
    end
    Ok, there's a lot to take in there, so we'll try to break it down into more managable chunks! The first part is a checker to see how many squads in total the AI currently has:

    Code:
    countallies1 = Player_GetSquadCount(player_Allies2)
    
    if countallies1 < 35 then
    Simple enough, hopefully! You can use population or unit counts instead, but I find squad counts give the most accurate impression of how much force the AI currently has on the map. If it has more than 35 squads, the rest of the function won't run and produce anymore units...

    Code:
    local routeindex = World_GetRand(1, table.getn(FINAL_ATTACK_ROUTES))
    			for j = 1, table.getn(FINAL_ATTACK_ROUTES[routeindex]) do
    				local command = FINAL_ATTACK_ROUTES[routeindex][j].cmd
    				local waypoint = FINAL_ATTACK_ROUTES[routeindex][j].wp
    This part looks through the route tables we have already set up, and picks one at random.

    The rest of this I'll comment up so you can see what the relevant commands do. Essentially, it's running a loop command 4 times, and each time it picks a route from the table, picks a random tank from the super, heavy and medium unit tables and then queues up the commands for those units.

    Code:
    				if command == "S" then                      -- Our first command in the list is always an "S", so when the code sees this, it will use this as a spawn command for the units.  The S just makes it easy for us to tell.
    				Util_CreateSquads(player_Allies2, sg_final, type_super, waypoint, nil, 1)	
    				Util_CreateSquads(player_Allies2, sg_final, type_heavy, waypoint, nil, 1)
    				Util_CreateSquads(player_Allies2, sg_final, type_medium, waypoint, nil, 1)
    				elseif command == "M" then                -- Any commands with an "M" are move commands, so Cmd_Move will be queued.
    				Cmd_Move(sg_final, Util_GetPosition(waypoint), true)
    				elseif command == "AM" then              -- Any commands with an "AM" are attack-move commands, so Cmd_AttackMove will be queued.
    				Cmd_AttackMove(sg_final, Util_GetPosition(waypoint), true, nil, 20)
    				end
    
    
    end
    end  ---ends for the various ifs, loops and the function
    end
    end
    Ok, hopefully that all makes sense! Please feel free to ask any questions. Obviously these functions are quite powerful, and you can use them in a variety of different ways to get different results - in the example here, 3 units will be spawned in the same place with the same commands - so they'll naturally form a "battlegroup" when they attack. You may want more single units attack from different positions, so just keep the spawn command to 1 unit, and increase the number of loops...

    ----------

    Ok, here we go, the final part of the scar tutorial (for now at least!) - this about as far as I've got with scar code, and if you've reached this point, you're ready to start writing your own special functions and exploring existing scar missions for yourself!

    These functions are bastardised versions of Mannerheim's code from the JointOps missions - simplified in various ways so I could get to grips with them. They're a method for spawning troops from random locations, and will continue to "top up" the number of units that are spawning up to a set amount. We'll also take a little look at an Attack Manager, which allows you to heavily re-use these functions as your mission develops. Please note, on the map I made for these (Nazi Invaders 4.0, see the maps bunker for download) there are a large number of spawn and movement markers with numbers on the end - e.g. spawn10, spawn11, spawn12 , movement10 etc, and had a manpower point entity group setup called "eg_capturepoint".

    First we need to setup some background variables that allow these functions to run: (these can go pretty much anywhere within the code, I usually run them just after OnGameSetup())

    Code:
    dif_maxsquads_suinf = 8 --Volks etc Front attack only
    dif_types_suinf = {SBP.ELITE.LUFTWAFFE, SBP.AXIS.VOLKSGRENADIER, SBP.AXIS.VOLKSGRENADIER, SBP.AXIS.VOLKSGRENADIER, SBP.AXIS.VOLKSGRENADIER, SBP.AXIS.VOLKS_2PANZERF}
    These setup how many units to spawn, and what types. We'll come back to this later.

    Here's the most basic example:

    Code:
    function InfantryAttackForces_SU()
    	--Suicide frontal attack infantry
    
    	for i = 1, dif_maxsquads_suinf do
    		local sg_temp = SGroup_CreateIfNotFound("sg_suinfantry" .. i)
    		
    		if SGroup_IsEmpty(sg_temp) then
    			Util_CreateSquads(player8, sg_temp, dif_types_suinf, Marker_FromName("spawn" .. World_GetRand(1, 3) .. World_GetRand(0, 4), "basic_marker"), nil, 1)
    
    				local attackormove = World_GetRand(1, 3)
    				if attackormove < 3 then
    				Cmd_AttackMove(sg_temp, Util_GetPosition(Marker_FromName("move" .. World_GetRand(1, 3) .. "0", "cyan_marker")), true)
    				elseif attackormove == 3 then
    				Cmd_Move(sg_temp, Util_GetPosition(Marker_FromName("move" .. World_GetRand(1, 3) .. "0", "cyan_marker")), true)
    			end
    
    				if not EGroup_IsCapturedByPlayer(eg_capturepoint, player5, ALL) then
    					if attackormove == 1 then
    					Cmd_AttackMove(sg_temp, Util_GetPosition(eg_capturepoint), true)
    					elseif attackormove == 2 then
    					Cmd_Move(sg_temp, Util_GetPosition(eg_capturepoint), true, NIL_DEST, NIL_FACE, NIL_OFFSET, NIL_DIST, 10)
    					end
    				Command_SquadEntity(player8, sg_temp, SCMD_Capture, eg_capturepoint, true)			
    			end
    		end
    	end
    end
    First up, you can see that we run a loop (based on dif_maxsquads_suinf) that tells the code how many times to try and run. "if SGroup_IsEmpty(sg_temp) then" checks that the squad to be spawned to is empty - this is important as it stops the code from spawning a new unit if one of the existing ones is still alive. If a squad is empty, the code will spawn a new one from the "dif_types_suinf" list. The squad will be spawned somewhere between "spawn10" and "spawn34" (these are the available number of basic markers in this case) depending on the randomised numbers.

    "local attackormove" is a simple way of randomising whether the squad will use a Cmd_Move or Cmd_AttackMove as it's primary order.

    If the entity group "eg_capturepoint" has not already been captured, the code will queue a command to try and do this after the Move or AttackMove command has been completed.

    There we go, easy as that! Obviously to get this code working we need an interval rule "Rule_AddInterval(InfantryAttackForces_SU, 150)" - this is how often the code will check whether those squads have been wiped out, and will spawn the relevant number of replacements. For example, we start with 8 squads - if none have been wiped out, no more will spawn. If 3 have been wiped out, 3 will be respawned to replace them.

    We can then get a bit more advanced, for example we may want to increase or decrease the number of squads, to do this, simply change the variable in another function:

    Code:
    dif_maxsquads_suinf = 6 --reduce the number of squads to 6
    No troops will be removed, but the maximum number replaced in future will be limited to 6 active at any time. We could also increase this.

    We could also change the types of troops involved with another function:

    Code:
    dif_types_suinf = {SBP.ELITE.LUFTWAFFE, SBP.AXIS.GRENADIER, SBP.AXIS.GRENADIER, SBP.ELITE.ASSAULTGRENADIER, SBP.AXIS.VOLKS_2PANZERF}



    Ok, lets move on to a slightly more complex example with special troop behaviour:

    First of all, we need to set a limit on how many special weapons the squad has:

    Code:
    ax_slotweapon_no = 2
    dif_maxsquads_stinf = 2 --Stormtrooper Inf
    Player_SetResource(player7, RT_Munition, 9999) --set this in the OnInit() function, ensures there are munitions available for grenades
    Player_SetAbilityAvailability(player7, ABILITY.AXIS.GRENADE, ITEM_UNLOCKED) --allow use of grenades
    Then we write the function:

    Code:
    function InfantryAttackForces_ST()
    	--Stormtrooper infantry with weapons and grenades
    	--local ability_uses = 0
    
    local choosespawn = World_GetRand(4, 7)
    
    	for i = 1, dif_maxsquads_stinf do
    		local sg_temp = SGroup_CreateIfNotFound("sg_stinfantry" .. i)
    		
    		if SGroup_IsEmpty(sg_temp) then
    			Util_CreateSquads(player7, sg_temp, SBP.AXIS.STORMTROOPER, Marker_FromName("spawn" .. choosespawn .. World_GetRand(0, 4), "basic_marker"), nil, 1)
    			
    				local attackormove = World_GetRand(1, 2)
    				if attackormove == 1 then
    				Cmd_AttackMove(sg_temp, Util_GetPosition(Marker_FromName("move" .. choosespawn .. "0", "cyan_marker")), true)
    				elseif attackormove == 2 then
    				Cmd_Move(sg_temp, Util_GetPosition(Marker_FromName("move" .. choosespawn .. "0", "cyan_marker")), true)
    				Cmd_Ability(sg_temp, BP_GetAbilityBlueprint("abilities/camouflage_toggled.lua"), nil, nil, true)
    			end
    
    				if not EGroup_IsCapturedByPlayer(eg_capturepoint, player5, ALL) then
    					if attackormove == 1 then
    					Cmd_AttackMove(sg_temp, Util_GetPosition(eg_capturepoint), true)
    					elseif attackormove == 2 then
    					Cmd_Move(sg_temp, Util_GetPosition(eg_capturepoint), true, NIL_DEST, NIL_FACE, NIL_OFFSET, NIL_DIST, 10)
    					end
    				Command_SquadEntity(player7, sg_temp, SCMD_Capture, eg_capturepoint, true)			
    			end
    
    				local chooseweapon = World_GetRand(1, 3)
    
    				if chooseweapon == 1 then				
    				Cmd_InstantUpgrade(sg_temp, UPG.AXIS.STORM_MP44, ax_slotweapon_no)
    
    				elseif chooseweapon == 2 then				
    				Cmd_InstantUpgrade(sg_temp, UPG.AXIS.STORM_PANZERSCHRECK, ax_slotweapon_no)
    			end
    
    		else 		
    
    				local sg_temptarget = SGroup_CreateIfNotFound("sg_temptarget")
    				SGroup_Clear(sg_temptarget)
    				SGroup_GetLastAttacker(sg_temp, sg_temptarget)
    				
    				if not SGroup_IsEmpty(sg_temptarget) then
    					if World_GetRand(1, 2) == 1 then
    						Cmd_Ability(sg_temp, ABILITY.AXIS.GRENADE, sg_temptarget, nil, false)
    						-- Command queue resets with above ability use so add the primary target back to queue
    						if attackormove == 1 then
    							Cmd_AttackMove(sg_temp, Util_GetPosition(eg_capturepoint), true)
    						elseif attackormove == 2 then
    							Cmd_Move(sg_temp, Util_GetPosition(eg_capturepoint), true, NIL_DEST, NIL_FACE, NIL_OFFSET, NIL_DIST, 10)
    						end
    						Command_SquadEntity(player7, sg_temp, SCMD_Capture, eg_capturepoint, true)
    					end
    				end
    		end
    	end
    end
    This code is essentially the same, but we've added several more aspects to it - first of all, the stormtroopers will spawn as a group in a single location, and follow the same orders. Secondly, the stormtroopers will randomly be equipped with MP44s or Panzershreks (or nothing) - how many is set by the ax_slotweapon_no variable above. The troops have their camoflague ability set on. Finally, as well as spawning and replacing troops, the code will also try to use special abilities when it runs - in this example the stormtroopers will try to throw a grenade at the last unit to attack them. This final section of code, starting "local sg_temptarget = SGroup_CreateIfNotFound("sg_temptarget")" first of all finds the last attacker, it then checks that the unit is still alive (is not empty), then throws the grenade. The grenade throwing overrides the movement queue, so we then need to set it back up again, keeping the same variables as above.

    Finally, it's a good idea to have an "Attack Manager" function which keeps adjusting these variables in a single place, allowing you to easily make changes or re-use the code. There are many, many different ways of making attack managers, and this is something you should experiement with for yourself in order to make something that suits your needs. I'll post up a final example below:

    Code:
    -------------------
    ---Attack Manager--
    -------------------
    
    function attackmanager()
    
    --Add, change or remove wave types/times
    --Alter wave sizes and weapon numbers
    --Increase veterancy
    --Special attacks
    --Increase/decrease supplies to AI player5
    
    -------------------
    ----By Mission ----
    -------------------
    
    	if MissionNo == 1 and mission1 == false then
    
    		AI_Enable(player5, true)
    
    		InfantryAttackForces_SU()
    		Rule_AddInterval(InfantryAttackForces_SU, 150)
    
    		mission1 = true
    
    	elseif MissionNo == 2 and mission2 == false then
    
    		dif_maxsquads_suinf = 10
    		bonusaxis1()
    		upgraderesources()
    
    		InfantryAttackForces_AX()
    		Rule_AddInterval(InfantryAttackForces_AX, 60)
    
    		InfantryAttackForces_PE()
    		Rule_AddInterval(InfantryAttackForces_PE, 60)
    
    		Rule_AddInterval(regenerateinfantryspawn1, World_GetRand(50, 180))
    
    		mission2 = true
    
    	elseif MissionNo == 3 and mission3 == false then
    
    		Rule_ChangeInterval(InfantryAttackForces_SU, 210)
    
    		specialmanager() ----------------------Might want to randomise these more
    
    		SupportForces()
    		Rule_AddInterval(SupportForces, 150)
    
    		LightArmourForces()
    		Rule_AddInterval(LightArmourForces, 90)
    
    		Cmd_InstantUpgrade(player7, UPG.AXIS.VETERANCY.INFANTRY1, ITEM_UNLOCKED) --Grens only
    
    		mission3 = true
    
    	elseif MissionNo == 4 and mission4 == false then
    
    		dif_maxsquads_suinf = 8
    		dif_maxsquads_axinf = 3
    		dif_maxsquads_peinf = 4
    		dif_maxsquads_support = 3
    
    		InfantryAttackForces_ST()
    		Rule_AddInterval(InfantryAttackForces_ST, 300)
    
    		dif_types_lightarm = {SBP.ELITE.ARMOURCAR_221, SBP.ELITE.HALFTRACK_SNIPER, SBP.AXIS.PUMA, SBP.AXIS.HALFTRACK_FLAME} --2
    		dif_types_support = {SBP.AXIS.HEAVYMG, SBP.AXIS.SNIPER, SBP.AXIS.MORTAR, SBP.AXIS.PAK_38} --2
    
    		Cmd_InstantUpgrade(player7, UPG.AXIS.VETERANCY.VEHICLE1, ITEM_UNLOCKED)
    		Cmd_InstantUpgrade(player8, UPG.AXIS.VETERANCY.INFANTRY1, ITEM_UNLOCKED) --Front attackers
    
    		Rule_ChangeInterval(regenerateinfantryspawn1, World_GetRand(50, 180))
    
    		mission4 = true
    
            end
    end

  50. #100
    Member
    Join Date
    Jul 2011
    Location
    England
    Hi

    Im new to this scar code and this tutorial is amazing but I want to make some bridges in my map indestructible but I didnt really understand the bit about it in this thread.

    I use the instructions from a different website

    import("ScarUtil.scar")
    function OnInit()

    Invulnerable()

    end

    Scar_AddInit(OnInit)


    function Invulnerable()
    EGroup_SetInvulnerable(eg_invincible, true)
    end

    I saved this file as the same name as my map and added the objects to the list in world builder but no luck

    Could someone help me with the code and where to save the notepad file please??

Page 2 of 5 FirstFirst 12345 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •