Coding problems

PricePrice Join Date: 2003-09-27 Member: 21247Members
edited June 2013 in Modding
Hey, i want to set the default rally point to a structure.
Like if the roboticsfactory spawn an arc, the arc should have an rally point to the closest hive, i have no idea how to set it.

You know, the commander click on the RF and "set rally point" if he click somewhere.

Comments

  • JimWestJimWest Join Date: 2010-01-03 Member: 69865Members, Reinforced - Silver
    edited June 2013
    find the hive
    for index, hive in ientitylist(Shared.GetEntitiesWithClassname("Hive")) do
    
    and then simplay give an order to the factory:
    :GiveOrder(kTechId.Move, 0, hive:GetOrigin())
    

    Maybe set an offset to the origin.
  • PricePrice Join Date: 2003-09-27 Member: 21247Members
    edited June 2013
    Thank you for your help, but it don't work.
    i tried it already.

    Example Code:
    	for index, hive in ientitylist(Shared.GetEntitiesWithClassname("Hive")) do  
    	Shared.Message(string.format("Search for %s-%s", hive:GetClassName(), hive:GetId()))
    
    	local spawnPoint = self:GetOrigin() + Vector(1, 0, 0)
            local unit = CreateEntity(ARC.kMapName, spawnPoint, self:GetTeamNumber()) 
    	unit:GiveOrder(kTechId.Move, 0, hive:GetOrigin()) 
    	Shared.Message(string.format("Giving order to %s-%s", unit:GetClassName(), unit:GetId()))
            //GiveOrder(orderType, targetId, targetOrigin, orientation, clearExisting, insertFirst, giver)
    
    
    maybe i did something wrong?
    Console said, commands are created, the arc did spawn, but did not move.
  • JimWestJimWest Join Date: 2010-01-03 Member: 69865Members, Reinforced - Silver
    Your code would create an arc for each hive, but you need to put an end at the end of the for loop.
  • PricePrice Join Date: 2003-09-27 Member: 21247Members
    edited June 2013
    Edit:
    Can be closed, i got it to work.
    :-)
    I made it diffrent, i put the code in the arc and not in the roboticsfactory, which is much easier.
  • twilitebluetwiliteblue bug stalker Join Date: 2003-02-04 Member: 13116Members, NS2 Playtester, Squad Five Blue
    edited November 2015
    It has been a while since the thread was last active, but I have a similar problem right now.

    I'm trying allow Gorge to command Whips.

    In Whip_Server.lua, function Whip:UpdateOrders(deltaTime), one of the lines I added is:

    local success = self:GiveOrder(kTechId.Move, 0, nearestBall:GetOrigin(), nil, true, true)

    That is constantly returning a value of 1, and the Whip refused to move.

    Any help would be much appreciated!
  • GhoulofGSG9GhoulofGSG9 Join Date: 2013-03-31 Member: 184566Members, Super Administrators, Forum Admins, Forum Moderators, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Reinforced - Supporter, WC 2013 - Supporter, Pistachionauts
    edited November 2015
    It has been a while since the thread was last active, but I have a similar problem right now.

    I'm trying allow Gorge to command Whips.

    In Whip_Server.lua, function Whip:UpdateOrders(deltaTime), one of the lines I added is:

    local success = self:GiveOrder(kTechId.Move, 0, nearestBall:GetOrigin(), nil, true, true)

    That is constantly returning a value of 1, and the Whip refused to move.

    Any help would be much appreciated!

    You have to pass a valid targeId with GiveOrder for the OrderTargetInvalid check. Try
    local success = self:GiveOrder(kTechId.Move, self:GetId(), nearestBall:GetOrigin(), nil, true, true)
    

    Overall i find it a bit weird that an object is giving itself orders, you might better implement a method executing the move directly.
  • twilitebluetwiliteblue bug stalker Join Date: 2003-02-04 Member: 13116Members, NS2 Playtester, Squad Five Blue
    Thanks so much Ghoul! I got it working by letting the bait ball issue the move command to the Whip and passing the bait ball as the targetId.

    Code snippet for those interested:
        function WhipPheromone:OnUpdate(deltaTime)
    
            Projectile.OnUpdate(self, deltaTime)
    		
    		for _, whip in ipairs(GetEntitiesForTeamWithinRange("Whip", self:GetTeamNumber(), self:GetOrigin(), kWhipSearchRange)) do
    			if not whip:GetOwner() or (whip:GetOwner() == self:GetOwner()) then
    				if (whip:GetOrigin() - self:GetOrigin()):GetLength() > 0.1 then
    					whip:GiveOrder(kTechId.Move, self:GetId(), self:GetOrigin(), nil, true, true) 
    				end
    
    			end 
    		end
    		
        end
    
  • YojimboYojimbo England Join Date: 2009-03-19 Member: 66806Members, NS2 Playtester, NS2 Map Tester, Reinforced - Supporter, Reinforced - Silver, Reinforced - Shadow

    So the whips not longer take damage whilst NOT standing on infestation? Also will they be able to root on non infested ground?
  • twilitebluetwiliteblue bug stalker Join Date: 2003-02-04 Member: 13116Members, NS2 Playtester, Squad Five Blue
    edited November 2015
    Yojimbo wrote: »

    So the whips not longer take damage whilst NOT standing on infestation? Also will they be able to root on non infested ground?

    Whips never required infestation to survive. No they cannot root or attack off-infestation, unless somebody wants to change that. :)
Sign In or Register to comment.