Results 1 to 46 of 46

Critical via scar?

  1. #1

    Critical via scar?

    Is it possible to have a critical which has effects which can only be done via scar? Because I want to have a critical which makes the vehicle unusable but it should explode.. Therefore I want to set it no selectable

  2. #2
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    You can set EGroup / SGroup selectable state with the following commands:
    Code:
    EGroup_SetSelectable(egroup, selectable)
    Result type: Void.
    
    Set player selectable state of entities in the egroup  
    
    -----------------------------------------------------------------------------
    
    SGroup_SetSelectable(sgroupid, selectable)
    Result type: Void.
    
    Set player selectable state of squads in the sgroup  
    
    -----------------------------------------------------------------------------

  3. #3
    i have another question about this: how to get the squadID of a single entity? I tried to use Entity_GetSquad() but it returns a table :O how to solve this?

  4. #4
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    What are you going to do with the SquadID returned from function Entity_GetSquad() ?
    For example this test code works just fine with the returned SquadID:
    Code:
    	
    	sg_rifles = SGroup_CreateIfNotFound("sg_rifles")
    	Util_CreateSquads(World_GetPlayerAt(1), sg_rifles, SBP.ALLIES.RIFLEMEN, Player_GetStartingPosition(World_GetPlayerAt(1)))
    	_entity = Squad_EntityAt(SGroup_GetSpawnedSquadAt(sg_rifles, 1), 0)
    	--NOTE! Squad indexes in SGroups starts from 1. Entity indexes in Squads starts from 0.
    	_squad = Entity_GetSquad(_entity)
    	Squad_SetHealth(_squad, 0.5)

  5. #5
    I had done this
    Code:
    	sg_destroyed = SGroup_CreateIfNotFound("sg_destroyed")
    	i = 0;
    	while(World_GetNumEntities() > i) do
    		e = World_GetEntity(i)
    		if(Entity_IsVehicle(e) and Entity_GetHealth(e) == 0 and SGroup_ContainsSquad(sg_destroyed, Entity_GetSquad(e)) == false) 
    			SGroup_Add(sg_destroyed, Entity_GetSquad(e))
    			SGroup_SetSelectable(sg_destroyed, false)
    		end
    	end
    and got this error:
    *FATAL SCAR ERROR: Invalid parameter 2 (type expected=unsigned long, received=table) in function SGroup_ContainsSquad
    Lua Hull_Destroyed.scar Ln 19 (Util_hull_destroyed)
    Lua Testmod_Surrender.scar Ln 21 (Util_SurrenderSelection_Units_Check)
    Could not execute rule: Util_SurrenderSelection_Units_Check
    FATAL Scar Error while running rules - Execution has been paused.

  6. #6
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    Function SGroup_ContainsSquad appears to cause your fatal error. You don't have to check if SGroup has the squad already while adding a new squad to it, because of the function SGgroup_Add checks it automatically.

    Code:
    -----------------------------------------------------------------------------
    SGroup_Add(group, squadron)
    Result type: Void.
    
    Adds an squadron to the end of a group if the group doesnt already have it.  
    -----------------------------------------------------------------------------

  7. #7
    yeah but I only want to go into this if-Branch if the squad is not in this SGroup.. However the problem lays in the second parameter: expected is an unsigned long but my Entity_GetSquad returns a table.. How to solve this?

  8. #8
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    What (kind of) units are you trying to collect into this "sg_destroyed" SGroup?

    have you tried creating a new squad or something to the position of the entity before "SGroup_Add(sg_destroyed, Entity_GetSquad(e))" ?
    That way you could find the position of the entity that was used to get the SquadID.

    You could also print entity's blueprint to the console before "SGroup_Add(sg_destroyed, Entity_GetSquad(e))", so you could know what entity was used to get the squadID.
    That way you could make sure your filters wont let in any entities that are unable to return squad.
    Code:
    print(BP_GetName(Entity_GetBlueprint(entity))
    function Entity_GetSquad() might also return null.

    Code:
    -----------------------------------------------------------------------------
    Entity_GetSquad(pEntity)
    Result type: SquadID.
    
    Returns the Squad for the passed Entity. (May be NULL)  
    
    -----------------------------------------------------------------------------

  9. #9
    the entity blueprint is the one I expected :
    ebps\races\axis\vehicles\stug_iv

  10. #10
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    I think you should use for loop instead of while loop, and run for loop with an interval, like 1 second.

    Code:
    	--[[ 
    	NOTE:
    	-------------------------------------------------------------------------------------------------------
    	Remember to subtract 1 from World_GetNumEntities(), because of entity ID numbers starts from 0.
    	Function SGroup_ContainsSquad(group, squadID) needs Unique GameID as second parameter instead of squadID.
    	I'm using health percentage of 0.1, as I spawned a stug to the map with 0.1 health. 
    	I replaced EntityIsVehicle() with Blueprint Comparison.
    	-------------------------------------------------------------------------------------------------------
    	]]--
    	
    	sg_destroyed = SGroup_CreateIfNotFound("sg_destroyed")
    	_VehicleFilters = 
    	{
    		BP_GetEntityBlueprint("ebps/races/axis/vehicles/stug_iv.lua"), 
    		BP_GetEntityBlueprint("ebps/races/axis/vehicles/panther.lua"),
    		BP_GetEntityBlueprint("ebps/races/axis/vehicles/panzer_iv.lua"),
    	}
    	
    	for i = 0, World_GetNumEntities() -1 do
    		_entity = World_GetEntity(i)
    		_squad = Entity_GetSquad(_entity)
    		
    		for j = 1, table.getn(_VehicleFilters) do
    			if Entity_GetBlueprint(_entity) == _VehicleFilters[j] then				
    		
    				if _squad ~= nil
    				and not SGroup_ContainsSquad(sg_destroyed, Squad_GetGameID(_squad))
    				and Entity_GetHealthPercentage(_entity) == 0.1 then
    				
    					SGroup_Add(sg_destroyed, Entity_GetSquad(_entity))
    					print("a vehicle was added to the SGroup 'sg_destroyed'")
    				end
    			end
    		end
    	end
    Last edited by Janne252; 4th Jul 12 at 4:48 AM.

  11. #11
    great work thx for help now I should be able to finish the work on my own

    However I have two last questions:
    1) How to set the Sgroups no longer to be a target for the enemy?
    2) How to get the criticalBlueprint? because I want to replace the Entity_GetHealth() with Entity_HasCritical() ?

  12. #12
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    1) How to set the Sgroups no longer to be a target for the enemy?
    You'll need an ability that sets action\upgrade_action\change_weapon_target_type.lua to type_target_weapon\tp_infantry_surrender.lua
    Then you'll have to use Cmd_Ability(sgroup, BP_GetAbilityBlueprint("your_new_ability_path")) to apply this action to the sgroup.
    To enable targeting the sgroup again, you'll need an ability, just like the one above, but this one sets action\upgrade_action\change_weapon_target_type.lua to type_target_weapon\tp_infantry.rgd
    or what ever type_target_weapon you think fits best.
    And again, apply it to the sgroup with the command Cmd_Ability(sgroup, BP_GetAbilityBlueprint("your_new_ability_path"))

    2) How to get the criticalBlueprint? because I want to replace the Entity_GetHealth() with Entity_HasCritical() ?
    For example
    Entity_HasCritical(_entity, CRIT.VEH.DAMAGE_ENGINE)

    Here's all vehicle critical hits that are listed in luaconsts:
    Code:
    CRIT.VEH.DAMAGE_ENGINE
    CRIT.VEH.MOBILITY_MAJOR
    CRIT.VEH.MAIN_WEAPON_DESTROYED
    CRIT.VEH.CONTROL_FAST
    CRIT.VEH.CONTROL_SLOW
    CRIT.VEH.AXIS_KILL_TOP_MG
    CRIT.VEH.IMMOBILIZE
    You can also use BP_GetCriticalBlueprint(pbgPath) to get those that are not listed in luaconsts.

  13. #13
    and again thx for your great help
    Unfortunately I have another question:

    How to get the direction of an entity? I want to Spawn a new entity at exact the same position and looking in the same direction using this code:
    Code:
    Squad_CreateAndSpawnToward(_squad_blueprint ,World_GetPlayerAt(1), 1, Entity_GetPosition(_entity), Entity_GetHeading(_entity))
    But I having trouble with this because the Position is not the same :/

  14. #14
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    I'm using randomized position as facing for riflemen for testing purposes.

    Code:
    	sg_rifles = SGroup_CreateIfNotFound("sg_rifles")
    	sg_engineers = SGroup_CreateIfNotFound("sg_engineers")
    	_spawnpos = Player_GetStartingPosition(World_GetPlayerAt(1))
    	_riflemen_facing = Util_GetRandomPosition(Player_GetStartingPosition(World_GetPlayerAt(2)), 6)
    	
    	Util_CreateSquads(World_GetPlayerAt(1), sg_rifles, SBP.ALLIES.RIFLEMEN, _spawnpos, nil, nil, nil, nil, nil, nil, _riflemen_facing)
    	_engineer_facing = Squad_GetOffsetPosition(SGroup_GetSpawnedSquadAt(sg_rifles, 1), 0, 5)
    	
    	--[[
    	Squad_GetOffsetPosition(squad, offset, distance)
    	offset list:
    		OFFSET_FRONT = 0
    		OFFSET_FRONT_RIGHT = 1
    		OFFSET_FRONT_LEFT = 7
    		OFFSET_BACK = 4
    		OFFSET_BACK_RIGHT = 3
    		OFFSET_BACK_LEFT = 5
    		OFFSET_RIGHT = 2
    		OFFSET_LEFT = 6
    	]]--
    	
    	Util_CreateSquads(World_GetPlayerAt(1), sg_engineers, SBP.ALLIES.ENGINEER, Squad_GetPosition(SGroup_GetSpawnedSquadAt(sg_rifles, 1)), nil, nil, nil, nil, nil, nil, _engineer_facing)
    Last edited by Janne252; 7th Jul 12 at 7:04 AM.

  15. #15
    I respawn vehicles so if they look in another direction it is really obviously that they are not the same.. Therefore I need the facing and not a random positon :/ is there any way to get the facing?

  16. #16
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    Before de-spawning the old vehicle, take its position to a variable, let's say _pos_oldvehicle. Then take offset position from the old vehicle to a variable, let's say _offset_oldvehicle, using function Squad_GetOffsetPosition(squad, 0, 5)
    2nd parameter "0" returns a position in front of the squad. This can be used as heading, which can be used to set squad facing while spawning it with function Util_CreateSquads()

    Then you can de-spawn the old vechicle, and re-spawn a new one using _pos_oldvehicle as spawn position and _offset_oldvehicle as facing.

    Code:
    	_pos_oldvehicle = Squad_GetPosition(_squad)
    	_offset_oldvehicle = Squad_GetOffsetPosition(_squad, 0, 5)
    	Squad_Destroy(_squad)
    	Util_CreateSquads(World_GetPlayerAt(1), sg_newvehicle, SBP.AXIS.STUG, _pos_oldvehicle, nil, nil, nil, nil, nil, nil, _offset_oldvehicle)

  17. #17
    oh man! this is great!!! This was exactly what I was looking for

    Edit: How to add a critical to the new spawned squad? I tried this :

    Code:
    Cmd_CriticalHit(World_GetPlayerAt(1), sg_newvehicle, BP_GetCriticalBlueprint("critical/vehicle_hull_destroyed.lua"), 1)
    but it doesn't work
    Last edited by berse2212; 7th Jul 12 at 12:27 PM.

  18. #18
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    Code:
    Cmd_CriticalHit(World_GetPlayerAt(1), sg_newvehicle, BP_GetCriticalBlueprint("critical/vehicle_hull_destroyed.lua"), CRIT.DAMAGE_GREEN)
    Last parameter is DamageBlueprint. luaconsts has these damageblueprints listed, and after testing I included estimated amount of lost HP in critical hit.
    Code:
    CRIT.DAMAGE_GREEN ~ - 10 % HP
    CRIT.DAMAGE_YELLOW - ~ - 60 % HP
    CRIT.DAMAGE_RED - ~ - 90 % HP
    Oh and remember to clear sg_newvehicle after spawning a unit with it, so you wont call critical hit to all vehicles that have been respawned, as it might look silly if other immobilized tanks in map appear to get critical hits from nothing.
    Might be also a good idea to use custom critical hits for re-spawned vehicles that wont create kicker messages.

  19. #19
    that was wrong as well but I forgot to create the SGroup "sg_newvehicle"

  20. #20
    I have another question: is there a possibility to get the path of the texture? I have some tanks in my mod with random textures and if I respawn them it may change and this is really obvious :/

  21. #21
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    I don't know how the random texture system works, but if you can call different scar function for each texture, it could be one way. I think scar functions called via RGD does not support parameters.
    Then you would have to create new RGD files for each texture, so the tank can be respawned with correct texture.

  22. #22
    the random texture system works with a random action in the .rgo file of the objective how do I call a scar function via RGD?

  23. #23
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    action\ability_action\scar_function_call.lua
    How the system would work is when scar function is called, it would find the new spawned tank and take its info to a lua table, and get texture id from the function it self.
    Then this info could be used for respawning tanks with correct textures. Only thing is what I am not sure is, is it possible to do different action for each texture?
    Last edited by Janne252; 28th Jul 12 at 12:47 PM.

  24. #24
    mh not really.. For know its a critical and this is always the same and cannot be different for each texture


    Edit:

    I have another question: I kill the old vehicle know with this action to make sure that the one who kills him receive experience points and the stats of the unit are updated

    Code:
    Cmd_CriticalHit(_attack_player, _squad, BP_GetCriticalBlueprint("critical/vehicle_make_wreck.lua"),  BP_GetDamageBlueprint("damage/damage_red"))
    However the wreck should be removed right after this action. But it is no longer the squad I saved in my variable and I cannot use the "Squad_Destroy(_squad)" command

    Edit 2:

    for now I just move the wreck outside the map which works well but the experience points are not shown..
    Last edited by berse2212; 29th Jul 12 at 4:51 AM. Reason: double post

  25. #25
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    If you want to give xp for killing the tank, use this function to first find who was the last one who attacked the tank:
    Code:
    Squad_GetLastAttacker(squad, group)
    Result type: Void.
    
    Find the last squad attacker on this squad. If found, the squad is added to the sgroup  
    
    -----------------------------------------------------------------------------

    Adding XP reward to the player


    Creating green xp kicker message ( locally )

    Last edited by Janne252; 29th Jul 12 at 9:40 AM.

  26. #26
    thx for help again

    I started a try to apply random textures in another way. However I got stuck because some strange things are happening..

    A part of my code is this:

    Huge code :D




    this part:

    Code:
    local _zeige = function (gID, idx, sID)
    		print(BP_GetName(Squad_GetBlueprint(_squad)))
    	end
    	SGroup_ForEach(sg_toFilter,  _zeige)
    print this:

    sbps\races\axis\soldiers\grenadier_squad
    sbps\races\axis\soldiers\grenadier_squad
    sbps\races\axis\soldiers\grenadier_squad
    However the only units the axis have are two grenadiers and one stug, therefore I want to ask why there are just three grenadiers listed :/
    Additionally this code:

    Code:
    if SGroup_CountSpawned(sg_toFilter) > 0 then 
    		spawnStug(sg_toFilter)
    	end
    calls the function spawnStug and the print function there

    Code:
    print("größe:" .. SGroup_CountSpawned(sg_toFilter))
    prints this:
    größe:1
    this means that in the SGroup "sg_toFilter" has to be one stug doesn't it?

    But this thought was a mistake: I got a crash

    *FATAL SCAR ERROR: Cannot find "sbps\races\axis\soldiers\grenadier_squad_1"
    Lua Hull_Destroyed.scar Ln 189 ((null))
    C =[C] Ln -1 (SGroup_ForEach)
    Lua Hull_Destroyed.scar Ln 206 (spawnStug)
    Lua Hull_Destroyed.scar Ln 172 (randomSquads)
    this is logical because I have no grenadier_squad_1 but there shouldn't be any grenadier any longer so why did this happen?

  27. #27
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland

    Part1: confusing usage of variable _squad


    Part2: Suggestions for debugging



    Part3: Fine tuning

    Last edited by Janne252; 3rd Aug 12 at 12:52 AM.

  28. #28
    Part1: I could hate me for this.. If I am to lazy to rewrite a line which I had used before I always just copy them and forgot to change (all) the variables used in this function -.- Thanks for recognizing this

    Part2: That was what I had done before but there was only one grenadier printed and I was more confused

    Part3: This is a great Idea but what returns this function?

    Code:
    number = World_GetRand(1, 4)

  29. #29
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    Part3: This is a great Idea but what returns this function?
    What do you mean by that? It returns an integer, if you meant that.
    Code:
    World_GetRand(min, max)
    Result type: Integer.
    
    Returns a random integer with range [min, max] 
    It is recomended you use this instead of luas math.random function 
    
    -----------------------------------------------------------------------------

  30. #30
    If the min value is 1 does it may return 1 or starts by 2 and if the max is 4 does it may return 4 or only 3? :-P

  31. #31
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    I believe it will return any value of 1..4 if min and max are 1 and 4.
    You can also try running
    Code:
    for i = 1, 10 do
      print(math.random(1, 4))
    end
    Here: http://www.lua.org/cgi-bin/demo

  32. #32
    I tried math.random but I was an unknown function (don't know why) so I decided to use this "World_GetRand( Integer min, Integer max )" because in the description is written this:
    It is recomended you use this instead of luas math.random function

  33. #33
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    You could try that by your self in CoH, just make a loop that uses World_GetRand(1, 4) for example 10 times, and print it each time.
    Code:
    for loop = 1, 10 do
         print(World_GetRand(1, 4))
    end

  34. #34
    Code:
    function destroyEntities()
    	eg_killed = EGroup_CreateIfNotFound("eg_killed")
    	eg_alle = EGroup_CreateIfNotFound("eg_alle")
    	sg_angreifer = SGroup_CreateIfNotFound("sg_angreifer")
    	eg_spielersquads = EGroup_CreateIfNotFound("eg_spielersquads")
    	
    	for i = 1, World_GetPlayerCount() do
    		Player_GetAll(World_GetPlayerAt(i), eg_spielersquads)
    		EGroup_AddEGroup(eg_alle, eg_spielersquads)
    	end
    	
    	local _checkEntityCritical = function (gID, idx, eID)
    		if Entity_HasCritical(eID, BP_GetCriticalBlueprint("critical/vehicle_make_wreck.lua"))
    		and not EGroup_ContainsEntity(eg_killed, eID) then
    			Entity_GetLastAttacker(eID, sg_angreifer)
    			angreifer = Util_GetPlayerOwner(sg_angreifer)
    			Cmd_CriticalHit(angreifer, eID, BP_GetCriticalBlueprint("critical/vehicle_make_wreck2.lua"),  BP_GetDamageBlueprint("damage/damage_red"))
    			print("Entity von anderen zerstört!")
    		elseif Entity_HasCritical(eID, BP_GetCriticalBlueprint("critical/vehicle_make_wreck.lua")) then
    			Entity_Kill(eID)
    			print("Entity killed!")
    		end
    	end
    	EGroup_ForEach(eg_alle, _checkEntityCritical)
    end
    just a simple question about this code: why is the code in the if branch never accomplished, even when an entity receives this critical?

  35. #35
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    Just like in post #10: Egroup_ContainsEntity / SGroup_ContainsSquad functions require unique GameID for comparison.

    Code:
    Entity_GetGameID(entity)
    Result type: Integer.
    
    Returns the entities unique id in the world  
    
    -----------------------------------------------------------------------------
    Code:
    Squad_GetGameID(squad)
    Result type: Integer.
    
    Returns an integer containing the unqiue squad ID for this squad.  
    
    -----------------------------------------------------------------------------

  36. #36
    okay changed this line but it does not change the problem because the elseif branch and the if branch are never accomplished and the Entity_HasCritical function does not work work the unique id

  37. #37
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    Changed what? This line should be
    Code:
    	local _checkEntityCritical = function (gID, idx, eID)
    		if Entity_HasCritical(eID, BP_GetCriticalBlueprint("critical/vehicle_make_wreck.lua"))
    		and not EGroup_ContainsEntity(eg_killed, eID) then
    -->
    Code:
    	local _checkEntityCritical = function (gID, idx, eID)
    		if Entity_HasCritical(eID, BP_GetCriticalBlueprint("critical/vehicle_make_wreck.lua"))
    		and not EGroup_ContainsEntity(eg_killed, Entity_GetGameID(eID)) then

  38. #38
    that was what i had done but it still does not enter the if or the elseif branch

  39. #39
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    When ever I am trying to find out why some parts of the code are not being executed, I print out everything to the console. Every variable that are compared in inf branches and so on.
    You should be able to find what variable had a value that your filters wont let to pass, and figure out what causes it to have that kind of value.

  40. #40
    okay solved the mistake but how to kill vehicles by world so no player and no squad receive points for the killed entity? I already tried this one but the last attacker get one tank kill more..

    function


  41. #41
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    You could try instantly spawning a new entity after removing the old one and kill the new entity instantly so it won't have "last attacker"?

  42. #42
    great idea that worked well thx for help :P
    Last edited by berse2212; 21st Sep 12 at 7:31 AM.

  43. #43
    have another question: how to reveal a certain area for only one player? I tried: "FOW_RevealArea( Position pos, Real radius, Real durationSecs )" but this works only for all players :/

  44. #44
    Member eliw00d's Avatar
    Join Date
    Jul 2008
    Location
    USA
    Check to see if the player is a local player.

  45. #45
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    @eliw00d are you sure calling FOW revealing functions locally in multiplayer won't cause a sync error?
    What would happen if a certain area would only be revealed for player 1 and player 1 decides to use a sniper to kill something in the revealed area while other players in same team can't see this area?
    Isn't FOW shared for the whole team?

  46. #46
    Member eliw00d's Avatar
    Join Date
    Jul 2008
    Location
    USA
    Sorry, I should have said "Try checking to..." instead. Some UI related functions are able to be used by the local player and not cause sync errors, but I suppose this would not be one of them. Disregard.

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
  •