Weapons for each team?

18 replies [Last post]
francot514
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

It is possible to do this in game, or need to be added/marked as a new feature for future updates, is need to be, to allow properly setup weapons in missions.

sheepluva
sheepluva's picture
User offline. Last seen 1 week 2 days ago. Offline
Joined: 2009-07-18
Posts: 563

I guess it's possibly by adding ammo to a hedgehog of that team?
Similar like highlander and other scripts do - just with PerHogAmmo not being turned on of course.

  sheepluva <- me  my code stats -> 
a Hedgewars Developer


   <- where I'm from  what I speak -> 

Wuzzy
Wuzzy's picture
User offline. Last seen 26 weeks 6 days ago. Offline
Joined: 2012-06-20
Posts: 1304

Wait, what? I don't understand what you want.
Per-team weapons are already the default in Hedgewars.
Just don't turn on per-hog ammo in the game scheme.

Hi, I am a Hedgewars developer. Smile

sheepluva
sheepluva's picture
User offline. Last seen 1 week 2 days ago. Offline
Joined: 2009-07-18
Posts: 563

Wuzzy allegedly wrote:

Wait, what? I don't understand what you want.
Per-team weapons are already the default in Hedgewars.
Just don't turn on per-hog ammo in the game scheme.

I think he meant that not all teams start with the same weaponset.
But e.g. that one team plays defender and one the attacker, or something.

  sheepluva <- me  my code stats -> 
a Hedgewars Developer


   <- where I'm from  what I speak -> 

francot514
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

sheepluva allegedly wrote:

I think he meant that not all teams start with the same weaponset.
But e.g. that one team plays defender and one the attacker, or something.

Yes, i want to allow config this by default in the mission script, what should i do??

Vatten
Vatten's picture
User offline. Last seen 1 year 32 weeks ago. Offline
Joined: 2009-09-02
Posts: 48

Hai

I don't really know what you want to do, but i think you want what i kinda did in continental supplies (and some of my other scripts). However as i see it, i guess you want to be more team specific.

Below im posting some code that may be to some use.

declare a global vector for each team,clan whatever:

local setFirstTurn = {}

In onNewTurn() add:

if(setFirstTurn[GetHogTeamName(CurrentHedgehog)]==nil and GetHogTeamName(CurrentHedgehog) == "whatever team name") -- you could use GetClanColor(), GetHogClan() if you want that instead
then
-- dont remember if these lines are needed, but I put them there anyways. They are used to refresh all weapons before adding the ones you want.
AddAmmo(CurrentHedgehog,weapon1,0)
AddAmmo(CurrentHedgehog,weapon2,0)
AddAmmo(CurrentHedgehog,weapon3,0)
... all weapons except skip turn ...

AddAmmo(CurrentHedgehog,weapon1,amount)
AddAmmo(CurrentHedgehog,weapon2,amount)
AddAmmo(CurrentHedgehog,weapon3,amount)
...

setFirstTurn[GetHogTeamName(CurrentHedgehog)] = true
end

This could of course be improved, for example by using the tracker and by using an array to declare all weapons you may want to use.

Vattenania, my beloved motherland, my beloved homeland! You are always with me in my thoughts and in my heart!

francot514
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Vatten allegedly wrote:

Hai

....

This could of course be improved, for example by using the tracker and by using an array to declare all weapons you may want to use.

Wow, so impressive line of code, but there is not native function for doing that, SetAmmo should also considerer the HogTeam to which should be preset ammo values.

What is the tracker?

Vatten
Vatten's picture
User offline. Last seen 1 year 32 weeks ago. Offline
Joined: 2009-09-02
Posts: 48

The tracker is pretty much an array that store gears of some kind.
In this case it could be used to make the impression of giving out the weapons from the start to all teams.
From what i meant in the previous post, it could be used like this:

in your script add:

HedgewarsScriptLoad("/Scripts/Tracker.lua")

local setFirstTurn = {}
local iterateFirtTurn = nil

function onGearAdd(gearUid)
  --track the gears...
  if(GetGearType(gearUid) == gtHedgehog) 
  then
    trackGear(gearUid)
  end
end

function onGearDelete(gearUid)

  if(GetGearType(gearUid) == gtHedgehog) 
  then
    trackDeletion(gearUid)
  end
end

--add a function where you add all weapons to each team (this will be done on the first turn  (see below)
--in this function you add the code i mentioned in the previous post like this:
function addWeaponsToEachTeam(hog)

  if(setFirstTurn[GetHogTeamName(hog)]==nil and GetHogTeamName(hog) == "whatever team name") -- you could use GetClanColor(), GetHogClan() if you want that instead
  then
    -- dont remember if these lines are needed, but I put them there anyways. They are used to refresh all weapons before adding the ones you want.
    AddAmmo(hog,weapon1,0)
    AddAmmo(hog,weapon2,0)
    AddAmmo(hog,weapon3,0)
    ... all weapons except skip turn ...

    AddAmmo(hog,weapon1,amount)
    AddAmmo(hog,weapon2,amount)
    AddAmmo(hog,weapon3,amount)
    ...

    setFirstTurn[GetHogTeamName(hog)] = true
  end
  
  --add your next team here ...

end

--then iterate through each hog here:
function onNewTurn()

  if(iterateFirstTurn==nil)
  then
    runOnGears(addWeaponsToEachTeam)
    
    iterateFirtTurn = true
  end
end

Vattenania, my beloved motherland, my beloved homeland! You are always with me in my thoughts and in my heart!

francot514
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Thanks for the code snippet, but i really dont want to use all that only to achieve it by doing missions, there should be a way in the lua functions to do this easy way, something like SetAmmo(Team,Ammo,value,delay)

sheepluva
sheepluva's picture
User offline. Last seen 1 week 2 days ago. Offline
Joined: 2009-07-18
Posts: 563

francot514 allegedly wrote:

Thanks for the code snippet, but i really dont want to use all that only to achieve it by doing missions, there should be a way in the lua functions to do this easy way, something like SetAmmo(Team,Ammo,value,delay)

Here a working example script of what I meant earlier.


-- enable localization of text
HedgewarsScriptLoad("/Scripts/Locale.lua")

function onAmmoStoreInit()
    -- everyone should have this ammo
    SetAmmo(amSkip, 9, 0, 0, 0)
end

local redteamhog
local blueteamhog

function onGameInit()
    -- some random setup so that this script runs
    Seed = 0
    GameFlags = 0  -- gfPerHogAmmo is NOT enabled
    TurnTime = 10000
    CaseFreq = 0
    MinesNum = 0
    Explosives = 0
    Delay = 0
    Map = "Bath"
    Theme = "Bath"
    SuddenDeathTurns = 99999

    -- create teams and remember one hedgehog per team for later
    AddTeam(loc("Red Team"), 14483456, "Simple", "Island", "Default")
    redteamhog = AddHog(loc("Tomato 1"), 0, 100, "fr_tomato")
    AddHog(loc("Tomato 2"), 0, 100, "fr_tomato")

    AddTeam(loc("Blue Team"), 29439, "Simple", "Island", "Default")
    blueteamhog = AddHog(loc("Bluehog 1"), 0, 100, "sth_Sonic")
    AddHog(loc("Bluehog 2"), 0, 100, "sth_Sonic")
end

function onGameStart()
    -- give red team infinite grenades
    AddAmmo(redteamhog, amGrenade, 100) 
    -- give blue team infinite bazookas
    AddAmmo(blueteamhog, amBazooka, 100) 
end


  sheepluva <- me  my code stats -> 
a Hedgewars Developer


   <- where I'm from  what I speak -> 

francot514
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

That should work, but is not being really useful, because i need to predefine local for each hog, to allow have ammo for them, or maybe could i repeat same variable in each team?

sheepluva
sheepluva's picture
User offline. Last seen 1 week 2 days ago. Offline
Joined: 2009-07-18
Posts: 563

francot514 allegedly wrote:

That should work, but is not being really useful, because i need to predefine local for each hog, to allow have ammo for them, or maybe could i repeat same variable in each team?

Using a local for ONE hog per team is just the easiest way to do it if you know how which teams there will be, because the script defines them.

If you do not know all the teams in advance, you could probably detect them and add weapons as needed.

E.g. giving all AI teams specific weapons and all player teams different ones.

If that's useful to you, I'll see if I can come up with a script that does that.

  sheepluva <- me  my code stats -> 
a Hedgewars Developer


   <- where I'm from  what I speak -> 

francot514
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Quote:
E.g. giving all AI teams specific weapons and all player teams different ones.

If that's useful to you, I'll see if I can come up with a script that does that.

Yes, thats is a good example of what i want to achieve, i do not need extra script, but if you can post it will be cool for testing purposes..

sheepluva
sheepluva's picture
User offline. Last seen 1 week 2 days ago. Offline
Joined: 2009-07-18
Posts: 563

function onAmmoStoreInit()
    -- reset all ammo to 0
    SetAmmo(amSkip, 0, 0, 0, 0)
end

function onNewTurn()
    -- check if clan/team/hog has no ammo assigned yet
    if GetAmmoCount(CurrentHedgehog, amSkip) == 0 then

        -- give this clan/team/hog infinite skip and mortars
        AddAmmo(CurrentHedgehog, amSkip, 100)
        AddAmmo(CurrentHedgehog, amMortar, 100)

        -- give players 3 grenades and bots 4 bazooka shots
        if GetHogLevel(CurrentHedgehog) == 0 then
            AddAmmo(CurrentHedgehog, amGrenade, 3)
        else
            AddAmmo(CurrentHedgehog, amBazooka, 4)
        end

    end
end

Because OnNewAmmoStore is currently lacking supporting functions, I decided to just give hogs 0 amSkip and check if the current hog has no ammo yet when each turns begins.

If that's the case, then some code can be used to dynamically decide what ammo to give (here: Players get different weapons than AI).

  sheepluva <- me  my code stats -> 
a Hedgewars Developer


   <- where I'm from  what I speak -> 

francot514
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Interesting code snippet, GetHogLevel check if CurrentHedgehog is a bot? skip need to be assigned as infinite?

sheepluva
sheepluva's picture
User offline. Last seen 1 week 2 days ago. Offline
Joined: 2009-07-18
Posts: 563

Yes @ GetHogLevel. It gives the level of the bot. 0 means human player. Look it up in the LuaAPI for more details.

I don't think skip has to be set to infinite, that was just an example chosen by me. Because usually you always want players to be able to skip.

PS: That was not just a "code snippet" by the way. It's a fully functional multiplayer gamestyle/script example. I tested/played it ;p

  sheepluva <- me  my code stats -> 
a Hedgewars Developer


   <- where I'm from  what I speak -> 

francot514
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Yes, no problem, the functional game style will not be the firts script you showed, that has locale defined?, the second one is not missing something??

sheepluva
sheepluva's picture
User offline. Last seen 1 week 2 days ago. Offline
Joined: 2009-07-18
Posts: 563

francot514 allegedly wrote:

Yes, no problem, the functional game style will not be the firts script you showed, that has locale defined?, the second one is not missing something??

The second one isn't missing anything to run as multi-player script, except for a .cfg file of the same name to set default scheme/weapons (see other .cfg files in /Data/Scripts/Multiplayer/ ).

My test.cfg was:

*
*

  sheepluva <- me  my code stats -> 
a Hedgewars Developer


   <- where I'm from  what I speak -> 

francot514
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Ok, no problem, code is working good, right now i can easy implement it into the Mission Editor, using AddAmmo function.

User login

Copyright © 2004-2024 Hedgewars Project. All rights reserved. [ contact ]