Page 1 of 1
Can I immediately destroy unit by widget?
Posted: 29 Nov 2010, 11:35
by picmee
I have to stop or destroy unit that build from the AAI's factory. I try to create widget to do that but when I use, it send error msg
" attemt to call field 'DestrotUnit'(a nil value) "
Please suggest me the easiest way to do it?
Code: Select all
function widget:GetInfo()
return {
name = "Hello Widget",
desc = "Simple Widget Test",
author = "You",
date = "Jan 1, 2008",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = false
}
end
-- We define one local variable and one local function.
-- These cannot be accessed from outside this file but are fast to access.
-- The 'Spring' module was automatically included for us.
local hello = "Hello Spring"
local Echo = Spring.Echo
-- Now we create two call-ins.
-- The first will execute when the widget is loaded,
-- the second executes each time a unit is built.
function widget:Initialize()
Echo( hello )
Spring.SendCommands("cheat")
end
function widget:UnitCreated(unitID, unitDefID, unitTeam)
Echo( "Hello Unit " .. unitID )
Spring.DestroyUnit(unitID, false, true)
end
function widget:GameFrame( frameNumber )
if frameNumber % 100 == 0 then
Spring.SendCommands("give 1 armpw 0")
end
end
Thank you for your kindness.
Re: Can I immediately destroy unit by widget?
Posted: 29 Nov 2010, 11:45
by zwzsg
Spring.DestroyUnit is for gadget, not for widget.
Try Ctrl'D! Err, I mean Spring.GiveOrderToUnit(unitID,CMD.SELFD,{},{})
Of course that assume you are in charge of that team. Maybe you need to Spring.SendCommands({"cheat","spectator","godmode"}) to be sure.
__
Also, giving a peewee every three seconds? Are you sure? And at cursor position?
Plus you're trying to destroy every unit as soon as they are created (that include the spawn unit btw), seem a bit much.
What's the context anyway, what are you trying to do, why, etc...
I feel a gadget would be more appropriate.
Re: Can I immediately destroy unit by widget?
Posted: 29 Nov 2010, 11:52
by knorke
zwzsg wrote:Of course that assume you are in charge of that team. Maybe you need to Spring.SendCommands({"cheat","spectator","godmode"}) to be sure.
You should then also check unitTeam or it will selfdestruct units on all teams.
Also you should check what & when you selfdestruct units, ie you would not want to blow up the commander right after it is spawned...
Re: Can I immediately destroy unit by widget?
Posted: 29 Nov 2010, 12:05
by picmee
knorke wrote:zwzsg wrote:Of course that assume you are in charge of that team. Maybe you need to Spring.SendCommands({"cheat","spectator","godmode"}) to be sure.
You should then also check unitTeam or it will selfdestruct units on all teams.
Also you should check what & when you selfdestruct units, ie you would not want to blow up the commander right after it is spawned...
I want to stop AAI build unit but let it do other in AAI script continue because I give use /give order to do build instead.
Can you help me, please?
Re: Can I immediately destroy unit by widget?
Posted: 29 Nov 2010, 12:34
by hoijui
maybe editing AAI source code, and commenting out the line where it gives the command to build a unit works.
https://github.com/spring/spring/blob/0 ... r.cpp#L108
Re: Can I immediately destroy unit by widget?
Posted: 29 Nov 2010, 13:27
by zwzsg
/give creates the unit where the mouse cursor is. This isn't right for simulating the AI getting new units.
Widgets are to control the player's units, not to control other team units. So widgets are not appropriate here.
The best way would be to use a scriptable AI. AAI is configurable via some .cfg file. Maybe by editing those .cfg you can tell AAI to only build peewees. If not, use
Shard instead of AAI, and edit the taskqueues.lua.
If for some reasons you don't use a script or configure AI but instead let the AI do its things then have your code undo its thing, at least use a gadget, not a widget. You will need a mutator for a gadget (that is, a small nearly empty mod with a modinfo.lua that contains something like depend={"BA712.sd7"},). Then in that gadget, instead of using DestroyUnit callout, use the AllowCommand callin to disallow the order to build units to be issued. And Spring.CreateUnit to create units. But depending on how the AI algorithm is coded, it might be very confused about its build order not being issued, and about being given units it never built.
Re: Can I immediately destroy unit by widget?
Posted: 29 Nov 2010, 18:51
by oksnoop2
I might be misunderstanding but if you just want to prevent AAI from building units you can disallow them in springlobby.
Re: Can I immediately destroy unit by widget?
Posted: 29 Nov 2010, 19:06
by picmee
oksnoop2 wrote:I might be misunderstanding but if you just want to prevent AAI from building units you can disallow them in springlobby.
Thank you but I want do prevent AAI form building units(only mobile units) otherwise the opponent(may be AAI or human play) must can build unit.
Can you suggest me more about that?
If it's possible, I don't want to edit AAI code because it's take more time to do.
Thank you for your kindness