Creating a mission - game end immidiately

5 replies [Last post]
Kikert
User offline. Last seen 13 years 2 weeks ago. Offline
Joined: 2010-07-21
Posts: 3

Hi,
I'm in process of creating a mission. I have a problem - my game end immidiately. Can anybody explain me why it happens?

My LUA code:
loadfile(GetDataPath() .. "Scripts/Locale.lua")()

function onGameInit()

Seed = 1
GameFlags = gfDisableWind + gfInfAttack
TurnTime = 600 * 1000
Map = "HedgeFortress"
Theme = "Nature"
Ready = 100 * 1000
Goals = "Take down all the targets|Achieve this using only RC Plane"

AddTeam("Destroyers", 14483456, "Simple", "Island", "Default")
local player = AddHog("Pilot", 0, 100, "war_desertGrenadier1")
SetGearPosition(player, 1500, 1000)

end

function onAmmoStoreInit()

SetAmmo(amShotgun, 9, 0, 0, 0)

end

function onGameStart()

ShowMission("caption", "subcaption", "text", 4, 0)

end

function onGameTick()
end

function onGearAdd(gear)
end

function onGearDelete(gear)
end

Henek
Henek's picture
User offline. Last seen 6 years 27 weeks ago. Offline
Joined: 2010-04-06
Posts: 55

Hi,
as you are only adding one team, thus one clan, the victory condition (being only clan left) is automatically fulfilled at the start of the game and the game ends.
To be able to use only one clan and suppressing the victory condition you can add the gfOneClanMode flag to GameFlags, else add another team.

One of those hedgewars developers. I am specially knowledgeable in lua scripting, and the father of gameplay scripts.

Kikert
User offline. Last seen 13 years 2 weeks ago. Offline
Joined: 2010-07-21
Posts: 3

I have one more problem. I uses the cluster bomb and it is impossible to change this weapon timer. What do I have to do to let user choose the delay? There are no flags for this, I see. I haven't found anything in documentation, too.

Henek
Henek's picture
User offline. Last seen 6 years 27 weeks ago. Offline
Joined: 2010-04-06
Posts: 55

I do not understand the issue here, a player can change the timer of cluster bomb by pressing the keys 1 through 5 before throwing it. This do not change due to a having a script. If this didn't answer your question please explain it in more detail.

One of those hedgewars developers. I am specially knowledgeable in lua scripting, and the father of gameplay scripts.

Kikert
User offline. Last seen 13 years 2 weeks ago. Offline
Joined: 2010-07-21
Posts: 3

I don't know what happens, to be honest. Just player can't set the timer.

My code:
loadfile(GetDataPath() .. "Scripts/Locale.lua")()

local player = nil
local scored = 0
local end_timer = 5000
local game_lost = false
local time_goal = 0

function spawnTarget()
gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
FindPlace(gear, true, 0, LAND_WIDTH)
x, y = GetGearPosition(gear)
SetGearPosition(gear, x, 500)
end

function onGameInit()

Seed = 1
GameFlags = gfDisableWind + gfInfAttack + gfOneClanMode
TurnTime = 120 * 1000
Map = "Trash"
Theme = "Golf"
Goals = "Take down all the targets|Achieve it using only Cluster Bomb"
CaseFreq = 0
MinesNum = 0
Explosives = 0

AddTeam("The Hogies", 2850005, "Statue", "Island", "Hog Islands")

player = AddHog("Private Novak", 0, 100, "war_desertGrenadier1")
SetGearPosition(player, 1780, 1300)

end

function onAmmoStoreInit()

SetAmmo(amClusterBomb, 9, 0, 0, 0)

end

function onGameStart()

ShowMission("Cluster Bomb Training", loc("Aiming Practice"), "You have to destroy 12 targets in 120 seconds", -amClusterBomb, 5000)
spawnTarget()

end

function onGameTick()

if TurnTimeLeft == 1 and scored < 12 then
game_lost = true
ShowMission("Cluster Bomb Training", loc("Aiming Practice"), loc("Oh no! Time's up! Just try again."), -amSkip, 0)
SetHealth(player, 0)
time_goal = 1
end

if scored == 12 or game_lost then
if end_timer == 0 then
EndGame()
else
end_timer = end_timer - 1
TurnTimeLeft = time_goal
end
end

end

function onNewTurn()
end

function onGearAdd(gear)
end

function onGearDamage(gear, damage)

if GetGearType(gear) == gtTarget then
scored = scored + 1
if scored < 12 then
spawnTarget()
else
if not game_lost then
ShowMission("Cluster Bomb Training", loc("Aiming Practice"), loc("Congratulations! You've eliminated all targets|within the allowed time frame."), 0, 0)
PlaySound(sndVictory)
time_goal = TurnTimeLeft
end
end
end
end

function onGearDelete(gear)
end

Henek
Henek's picture
User offline. Last seen 6 years 27 weeks ago. Offline
Joined: 2010-04-06
Posts: 55

Yeah, I confirmed this behavior. It is an engine problem, so your script is not the reason.

Edit: nemo has fixed the problem now, should work fine.

One of those hedgewars developers. I am specially knowledgeable in lua scripting, and the father of gameplay scripts.

User login

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