Help making a special power

Help making a special power

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Help making a special power

Post by code_man »

I need advice, what im trying to do is a satelite scan power that globally reveals the map once the player presses a button.
Now i use a unit as special object for that, for the time being it does the job.
My problem however is right now that i dont know how to attach a button to trigger said power.

I looked in the synced and unsynced control section of the lua reference, but i couldnt come up with an idea on how to make one.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Help making a special power

Post by gajop »

I'd do it by creating a (chili) button (unsynced widget) that sends a message to synced Lua (synced gadget), and there I would check if I've received the correct message, and if so I'd do the 'special power' logic you already have.
Pinpoint the part you are struggling with exactly if you want help.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Help making a special power

Post by knorke »

Sorry, I read your post too fast and bit wrong.
I read scanning as scanning like in Starcraft, where it only reveals a small part of the map instead of "global."
But also not quite clear from your question what kind of "button" you want: A button in menu of unit or a button that is always there.

Maybe still somewhat helpful
www.youtube.com/watch?v=uZy6h6XLNsQ
There is two places where it says "YOUR UNIT NAME HERE", put unit names them there. First the unit that can scan (like radarcenter) then a invisible unit that will get spawned to provide the los. (this unit should probally also remove itself after a while)
Attachments
tp_scannertest.lua
(1.88 KiB) Downloaded 9 times
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Help making a special power

Post by code_man »

gajop wrote:I'd do it by creating a (chili) button (unsynced widget) that sends a message to synced Lua (synced gadget), and there I would check if I've received the correct message, and if so I'd do the 'special power' logic you already have.
Pinpoint the part you are struggling with exactly if you want help.
Il try this and see how that goes.
Tough if there is a way to simply add a button straight from the gadget this might be preferable in my case.
knorke wrote: But also not quite clear from your question what kind of "button" you want: A button in menu of unit or a button that is always there.
Yes, stupid of me, the button i need is faction global, so one button per player that is not tied to a unit.
knorke wrote: Maybe still somewhat helpful
http://www.youtube.com/watch?v=uZy6h6XLNsQ
...
Already made such a thing myself, but thanks.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Help making a special power

Post by zwzsg »

Is there a clean way to reveal the map? Because having to lay an array of units over the map isn't : it's hard to make them really invisible and non-interacting.
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Help making a special power

Post by code_man »

zwzsg wrote:Is there a clean way to reveal the map? Because having to lay an array of units over the map isn't : it's hard to make them really invisible and non-interacting.
Well im using an invisible aircraft with high altitude and enormous view range, so that pins it down to a single unit.
But i havent a lua function to reveal terrain to teams would be nice, i havent found one in the documentaion.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Help making a special power

Post by FLOZi »

Can't reveal terrain but you can make all units act as in permanent LOS. i.e. you can't change LOS status of terrain but you can of units.

btw you can use http://springrts.com/wiki/Gamedev:UnitD ... EmitHeight on a ground based unit if you want to avoid the vtol.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Help making a special power

Post by knorke »

http://springrts.com/wiki/Lua_SyncedCtrl#Unit_LOS
Spring.SetUnitLosMask or Spring.SetUnitLosState (hm, not quite sure atm what the difference is)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Help making a special power

Post by FLOZi »

State sets current state, Mask sets what engine will automatically update.

Example usage:

https://sourceforge.net/p/mwspring/code ... _radar.lua
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Help making a special power

Post by code_man »

Ok i couldnt work on my game for a while but now im back in the action.

So far i managed to make a chilly button, but thats it, i have no idea how to connect it to the a gadget.
I did look at the reference ofc but i could make much out of it. If someone could post an example it would help me much.

Another thing is i want a image button, but i only made a text button.
User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: Help making a special power

Post by Funkencool »

For the chili button you'll need to add an image as a child to the button.
Something like..

Code: Select all

local yourButton = Chili.Button:New{
  caption = '',
  x = 0,
  y = 0,
  height = 40,
  width  = 40,
  children = {
    Chili.Image:New{
      height = '100%',
      width  = '100%',
      file   = 'luaUI/images/yourimage.png',
    },
  }
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Help making a special power

Post by code_man »

Ok, good news and bad news.
Good news is adding the image worked just fine, so one less thing to do.
Bad news is i remembered that i also need a way to highlight how long it takes for the superpower to charge and if its ready. Which makes things even more complicated as this information must come from the gadget itself logically.
User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: Help making a special power

Post by Funkencool »

Reading around it sounds like SetUnitParams is what you need
http://springrts.com/wiki/Lua_SyncedCtrl#RulesParams

It allows you to tie a new param to a specific unit (unit with power) that is then readable in all lua environments. Or at least can be depending on how you set it.


Some other ways
http://springrts.com/phpbb/viewtopic.ph ... 38#p513838
http://springrts.com/phpbb/viewtopic.ph ... 57#p462457

If you give me a sec I'll try work out a basic example with a chili button
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Help making a special power

Post by knorke »

I use something like this in gadget:
mana=mana+1 --mana energy recharges or whatever
Spring.SetUnitRulesParam(unitID,"manaEnergy",mana)


In widget can read it like:
local mana = Spring.GetUnitRulesParam(unitID,"manaEnergy")

For complete example maybe look at jumpjets in zK, the gadget and how it "jumpReload" is read in unit_healtbars.lua

If you do not want it tied to a unit but rather global to the team can use:
Spring.SetTeamRulesParam
User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: Help making a special power

Post by Funkencool »

okay, so this might at least gives you some ideas

Code: Select all

local function onClick()
  label = Spring.GetUnitRuleParam(unitID, 'yourParamName') or ''
  buttonlabel:SetCaption(label)
end

buttonlabel = Chili.Label:New{
  caption = '',
  x       = 0,
  bottom  = 0,
}

image = Chili.Image:New{
  height = '100%,,
  width  = '100%',
  file   = 'luaUI/images/yourimage.png',
  children = {label},
}

button = Chili.Button:New{
  caption = '',
  x = 0,
  y = 0,
  height = 60,
  width  = 40,
  OnClick = {onClick},
  children = {image}
}
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Help making a special power

Post by code_man »

Ok nice, i got it to work thanks guys.

The only thing i need now is to actually call the function of the gadget to trigger the thing and i need the teamid of the one who clicks the button.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Help making a special power

Post by knorke »

The only thing i need now is to actually call the function of the gadget to trigger the thing and i need the teamid of the one who clicks the button.
in widget:
Spring.SendLuaRulesMsg("blabla i clicked a button")

gadget:

Code: Select all

function gadget:RecvLuaMsg(msg, playerID)
local active, spectator, teamID = Spring.GetPlayerInfo (playerID)
if not spectator and active then ... do things
...
Do not remember if there was another way to send messages other than strings?
So for the actual message you could think of some system, like "buttonclick_scanner" "buttonclick_nuke" or something.
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Help making a special power

Post by code_man »

Ok i tried that but now im getting this error.

Code: Select all

Error: LuaRules::RunCallIn: error = 2, RecvLuaMsg, [string "LuaRules/Gadgets/satelite_scan.lua"]:28: Unsafe attempt to change game state
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Help making a special power

Post by smoth »

and what is at line 28..?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Help making a special power

Post by knorke »

guess: Try to move the CreateUnit (or whatever you do there) from RecvLuaMsg into GameFrame.
Post Reply

Return to “Lua Scripts”