Player Research Granting and Restrictions

Hi,

Need some help here with an “Player_UnrestrictResearchOption” that I used to have in a script for the previous version of the game, but now it doesn’t work any more:

function Balance(playerid)
	Player_UnrestrictResearchOption(playerid, PlayerRace_GetString(playerid, "Balance_research_Unrestrict", ""))
	Player_UnrestrictBuildOption(playerid, PlayerRace_GetString(playerid, "Balance_build_Unrestrict", ""))
	Player_RestrictBuildOption(playerid, PlayerRace_GetString(playerid, "Balance_build_restrict", ""))
end

function HW2BalanceToggle()
	local i=0;
	local numplayers=Universe_PlayerCount();
	while (i<numplayers) do
		Balance(i);
		i=(i + 1);
	end
	

end
     luaplayer 144:  Player_UnrestrictResearchOption: unable to unrestrict (AttackBomberImprovedBombs) 
     parameter: 3
    stack traceback:
       1:  function `Balance' at line 2 [string ""]
       2:  function `HW2BalanceToggle' at line 11 [string ""]
       3:  function `OnInit' at line 57 [string ""] 

The strange thing is that not even granting all research works as intended, I’m not sure what is happening, but seems that I’m missing something obvious.

Whenever this is called in the stock game files (always in sp mission scripts), the following lines are in the lua file:

dofilepath("data:scripts/SCAR/SCAR_Util.lua")
dofilepath("data:scripts/scar/restrict.lua")

Did you try including them?

Yes, I did, they are included in the Deathmatch.lua, that now is split in 2 files, I actually customized it with my own, which I made it in the same manner.

[details=First section in scripts\Deathmatch.lua][code]
GUID = { 110,91,157,190,18,23,250,78,144,20,41,246,181,128,214,12 }
GameRulesName = “Homeworld Remastered (PnF Mod)” – Homeworld Remastered
Description = "$4804"
SaveGameVersion = 1.0
SinglePlayer = 0

ExtFilter = “rules_dm”

Race_Paths = “Deathmatch”

Level_Pass_Tags = "dm"
Race_Pass_Tags = “race_dm,race_random”

GameSetupOptions =
{
{
name = “resources”,
locName = “$3240”,
tooltip = “$3239”,
default = 1,
visible = 1,
choices =
{
“1/10”, “0.1”,
“1/5”, “0.2”,
“1/2”, “0.5”,
“Default”, “1.0”,
“x2”, “2.0”,
“x5”, “5.0”,
“x10”, “10.0”,
“x100”, “100.0”,
},
},
{
name = “unitcaps”,
locName = “$3214”,
tooltip = “$3234”,
default = 1,
visible = 1,
choices =
{
"$3215", “Small”,
"$3216", “Normal”,
"$3217", “Large”,
"$4801", “Huge”, --to localize
},
},
{
name = “resstart”,
locName = “$3205”,
tooltip = “$3232”,
default = 0,
visible = 1,
choices =
{
"$3206", “1000”,
"$3207", “3000”,
"$3208", “10000”,
“20000”, “20000”,
“50000”, “50000”,
“100000”, “100000”,
“500000”, “500000”,
“1000000”, “1000000”,
"$3209", “0”,
},
},
{
name = “lockteams”,
locName = “$3220”,
tooltip = “$3235”,
default = 0,
visible = 1,
choices =
{
"$3221", “yes”,
"$3222", “no”,
},
},
{
name = “startlocation”,
locName = “$3225”,
tooltip = “$3237”,
default = 0,
visible = 1,
choices =
{
"$3226", “random”,
"$3227", “fixed”,
},
},
{
name = “cpuplayers”,
locName = “$2984”,
tooltip = “$2985”,
default = 1,
visible = 1,
choices =
{
"$3161", “1”,
"$3201", “2”,
"$3160", “3”,
"$2986", “4”,
},
},
{
name = “bounties”,
locName = “$2987”,
tooltip = “$2988”,
default = 0,
visible = 1,
choices =
{
"$5455", “0”,
"$3215", “0.04”,
"$2989", “0.07”,
"$3217", “0.1”,
},
},
{
name = “research”,
locName = “$2961”,
tooltip = “$2962”,
default = 1,
visible = 1,
choices =
{
"$3184", “0”,
"$3183", “1”,
},
},
{
name = “RUsInjection”,
locName = “RUs Injection”,
tooltip = “Manages amount of resources that would be given to the players every (Injection Interval)”,
default = 0,
visible = 1,
choices =
{
“Off”, “0”,
“1000”, “1000”,
“2000”, “2000”,
“3000”, “3000”,
“5000”, “5000”,
“10000”, “10000”,
“20000”, “20000”,
“30000”, “30000”,
“50000”, “50000”,
},
},
{
name = “IntervalTime”,
locName = “Injection Interval”,
tooltip = “Manages interval time that resources would be given to the players”,
default = 0,
visible = 1,
choices =
{
“1 Minute”, “60”,
“2 Minutes”, “120”,
“3 Minutes”, “180”,
“5 Minutes”, “300”,
“10 Minutes”, “600”,
“15 Minutes”, “900”,
“20 Minutes”, “1200”,
“30 Minutes”, “1800”,
},
},
{
name = “challenges”,
locName = “$2994”,
tooltip = “$2995”,
default = 0,
visible = 1,
choices =
{
"$3183", “0”,
"$3184", “1”,
},
},
{
name = “relics”,
locName = “$3003”,
tooltip = “$3004”,
default = 0,
visible = 1,
choices =
{
"$3183", “0”,
"$3184", “1”,
},
},
{
name = “crates”,
locName = “$2996”,
tooltip = “$2997”,
default = 0,
visible = 1,
choices =
{
"$3183", “0”,
"$3184", “1”,
},
},
{
name = “BuildSpeed”,
locName = “Fixed Build Speed”,
tooltip = “Select how fast the ships should be built”,
default = 0,
visible = 1,
choices =
{
“No”, “0”,
“1x”, “1”,
“2x”, “2”,
“3x”, “3”,
“4x”, “4”,
“5x”, “5”,
“10x”, “10”,
“100x”, “100”,
},
},
{
name = “Squadrons”,
locName = “Squadrons”,
tooltip = “Allows the HW1 races to build fighters and corvettes on squadrons”,
default = 0,
visible = 1,
choices =
{
"$3183", “no”,
"$3184", “yes”,
},
},
{
name = “Hyperspace”,
locName = “Hyperspace”,
tooltip = “Grants Hyperspcace since the beginning of the match”,
default = 0,
visible = 1,
choices =
{
"$3183", “no”,
"$3184", “yes”,
},
},
{
name = “Balance”,
locName = “Ships Balance”,
tooltip = “Allows to select the balance for weapons and upgrades for HW1 ships”,
default = 0,
visible = 1,
choices =
{
“HW1”, “HW1”,
“HW1 with Upgrades”, “HW1U”,
“HW2 no Upgrades”, “HW2nU”,
“HW2 Full”, “HW2”,
“Experimental”, “Experimental”,
},
},
{
name = “StartFleet”,
locName = “Starting Fleet”,
tooltip = “Allows you to select which production ships to start with”,
default = 0,
visible = 1,
choices =
{
“Mothership”, “default”,
“Carrier”, “_C”,
“Mothersip w/ Carrier”, “_MSC”
},
},
{
name = “norushtime”,
locName = “$3000”,
tooltip = “$3001”,
default = 0,
visible = 1,
choices =
{
"$5455", “0”,
"$2992", “5”,
"$2993", “10”,
"$3002", “15”,
},
},
}

dofilepath(“data:scripts/rules/deathmatch/deathmatch.lua”)

[/code][/details]

[details=Second section that is inside scripts\Deathmatch\Deathmatch.lua][code]

dofilepath(“data:scripts/SCAR/SCAR_Util.lua”)
dofilepath(“data:scripts/scar/restrict.lua”)
dofilepath(“data:leveldata/multiplayer/lib/lib.lua”)
dofilepath(“data:leveldata/multiplayer/lib/crates.lua”)
dofilepath(“data:leveldata/multiplayer/lib/relics.lua”)
dofilepath(“data:leveldata/multiplayer/lib/challenges.lua”)
dofilepath(“data:leveldata/multiplayer/lib/norushtime.lua”)
dofilepath(“data:leveldata/multiplayer/lib/research.lua”)
dofilepath(“data:leveldata/multiplayer/lib/ruinjections.lua”)
dofilepath(“data:leveldata/multiplayer/lib/bounties.lua”)
dofilepath(“data:leveldata/multiplayer/lib/cpuplayers.lua”)
dofilepath(“data:leveldata/multiplayer/lib/ui.lua”)
dofilepath(“data:leveldata/multiplayer/lib/dev.lua”)
dofilepath(“data:leveldata/multiplayer/lib/main.lua”)
dofilepath(“data:leveldata/multiplayer/lib/carriersonly.lua”)
dofilepath(“data:leveldata/multiplayer/lib/Squads.lua”)
dofilepath(“data:leveldata/multiplayer/lib/HW2Balance.lua”)
–dofilepath([[data:scripts/race.lua]])

function OnInit()
Volume_AddSphere(“centre”, {-11111, 11111, 11111,}, 10)
MPRestrict()
BuildMultiplier = tonumber(GetGameSettingAsString(“BuildSpeed”))
if (BuildMultiplier > 0) then
Rule_AddInterval(“BuildSpeedMultiplier”,1)
end
– DroneToggle()
– if (GetGameSettingAsString(“Squadrons”) == “yes”) then
– SquadToggle()
– end
if (GetGameSettingAsString(“Hyperspace”) == “yes”) then
GrantHyperspaceToggle()
end
NewStartingFleet = (GetGameSettingAsString(“StartFleet”))

InjectAmount = tonumber(GetGameSettingAsString("RUsInjection"))
if (InjectAmount > 0) then
	Rule_AddInterval("RUsInject",GetGameSettingAsString("IntervalTime"))
end

if (GetGameSettingAsString("Balance") == "HW1") or (GetGameSettingAsString("Balance") == "HW1U") then
if NewStartingFleet ~= "default" then
	SetStartFleetSuffix(NewStartingFleet)
end
else
	if NewStartingFleet ~= "default" then
	NewStartingFleet = (GetGameSettingAsString("StartFleet").."HW2")
	SetStartFleetSuffix(NewStartingFleet)
else
	SetStartFleetSuffix("HW2")
end
end
if (GetGameSettingAsString("Balance") == "HW1") then
    	HW1BalanceToggle()	
	elseif (GetGameSettingAsString("Balance") == "HW2") then
    	HW2BalanceToggle()	
elseif (GetGameSettingAsString("Balance") == "HW1U") then
    	HW1UpgradesToggle()	
elseif (GetGameSettingAsString("Balance") == "HW2nU") then
    	HW2noUpgradesToggle()	
else
    	HW2ExperimentalToggle()	
end

cpuplayers = GetGameSettingAsNumber("cpuplayers")
bounties = GetGameSettingAsNumber("bounties")
research = GetGameSettingAsNumber("research")

– ruinjections = GetGameSettingAsNumber(“ruinjections”)
challenges = GetGameSettingAsNumber(“challenges”)
relics = GetGameSettingAsNumber(“relics”)
crates = GetGameSettingAsNumber(“crates”)
norushtime = GetGameSettingAsNumber(“norushtime”)
UI_SetElementEnabled(“NewTaskbar”, “btnObjectives”, 0)
UI_SetElementEnabled(“NewTaskbar”, “btnRecall”, 0)
UI_SetElementEnabled(“NewTaskbar”, “btnBuild”, 0)
UI_SetElementEnabled(“NewTaskbar”, “btnResearch”, 0)
UI_SetElementEnabled(“NewTaskbar”, “btnLaunch”, 0)
Rule_AddInterval(“timer_updating”,1.02) --timed with doai
SobGroup_Create(“AllShips”)
Rule_AddInterval(“AllShips”,5)
end

function AllShips()
SobGroup_Clear(“AllShips”)
for iPlayerIndex = 0, Universe_PlayerCount() - 1 do
if (Player_IsAlive(iPlayerIndex) == 1) then
SobGroup_SobGroupAdd(“AllShips”, “Player_Ships”…iPlayerIndex)
end
end
end

timer_timing = 1
timer_interval = 5.1

function timer_updating()
if timer_timing == 1 then
for playerIndex = 0,Universe_PlayerCount()-1,1 do
if Player_IsAlive(playerIndex) == 1 then
if Player_HasShipWithBuildQueue(playerIndex) == 1 then
Player_RestrictBuildOption(playerIndex, PlayerRace_GetString(playerIndex, “dm_build_restrict”, “”))
end
end
end
Rule_AddInterval(“sobgroups_init”,1)
–Rule_AddInterval(“sobgroups_updating”,1)
Rule_AddInterval(“UI_init”,0.1)
Rule_AddInterval(“UI_updating”,0.5)
Rule_AddInterval(“cpuplayers_updating”,0.1)
Rule_AddInterval(“balancing_updating”,0.25) --dev. to remove
if research == 0 then
Rule_AddInterval(“research_init”,timer_interval)
end
if bounties > 0 then
Rule_AddInterval(“bounties_updating”,timer_interval2)
end
if norushtime > 0 then
Rule_AddInterval(“norushtime_updating”,timer_interval
2)
end
Rule_AddInterval(“mainrule_updating”,timer_interval3)
elseif timer_timing == 2 then
if relics > 0 then
relics_init()
Rule_AddInterval(“relics_updating”,timer_interval
4)
end
elseif timer_timing == 3 then
if challenges > 0 then
Rule_AddInterval(“challenges_updating”,timer_interval)
end
elseif timer_timing == 4 then
if crates > 0 then
crates_init()
Rule_AddInterval(“CheckCratesRule”,timer_interval)
Rule_AddInterval(“SpawnCratesRule”,timer_interval60)
end
elseif timer_timing == 5 then
if InjectAmount > 0 then
– Rule_AddInterval(“ruinjections_updating”,timer_interval
48)
end
elseif timer_timing == 6 then
UI_SetElementEnabled(“NewTaskbar”, “btnObjectives”, 1)
UI_SetElementEnabled(“NewTaskbar”, “btnRecall”, 1)
UI_SetElementEnabled(“NewTaskbar”, “btnBuild”, 1)
if research == 1 then
UI_SetElementEnabled(“NewTaskbar”, “btnResearch”, 1)
end
UI_SetElementEnabled(“NewTaskbar”, “btnLaunch”, 1)
end
timer_timing = timer_timing + 1
if timer_timing > 6 then
Rule_Remove(“timer_updating”)
end
end

function BuildSpeedMultiplier()
local iPlayer = 0
local iPlayerCount = Universe_PlayerCount()
while (iPlayer < iPlayerCount) do
if (Player_IsAlive(iPlayer) == 1) then
SobGroup_SetBuildSpeedMultiplier(“Player_Ships”…iPlayer, BuildMultiplier)
end
iPlayer = iPlayer + 1
end
end

function RUsInject()
local playerIndex = 0
for playerIndex = 0,Universe_PlayerCount()-1,1 do
if Player_IsAlive(playerIndex) == 1 then
if Player_HasShipWithBuildQueue(playerIndex) == 1 then
Player_SetRU(playerIndex,Player_GetRU(playerIndex)+InjectAmount)
Stats_RUInjectionRUs[playerIndex+1] = Stats_RUInjectionRUs[playerIndex+1] + InjectAmount
local subtitleMessage = Message_FormatFf("$14705", InjectAmount)
Subtitle_Message_Handlerw(subtitleMessage, 2, “data:sound\speech\allships\emperor\STATUS_RUINJECTION_1”, playerIndex)
end
end
end
end

function Dronef(playerid)
Player_RestrictBuildOption(playerid, PlayerRace_GetString(playerid, “DroneAIrestrict”, “”))
Player_UnrestrictBuildOption(playerid, PlayerRace_GetString(playerid, “DroneAIunrestrict”, “”))
end

function DroneToggle()
local i=1;
local numplayers=Universe_PlayerCount();
while (i<numplayers) do
Dronef(i);
i=(i + 1);
end
end

function GHyperspace(playerid)
Player_GrantResearchOption(playerid, PlayerRace_GetString(playerid, “GrantHyperspace”, “”))
end

function GrantHyperspaceToggle()
local i=0;
local numplayers=Universe_PlayerCount();
while (i<numplayers) do
GHyperspace(i);
i=(i + 1);
end
end

Events = {}
Events.endGame =
{
{
{ “wID = Wait_Start(5)”,“Wait_End(wID)”},
},
}
Events.startcinematic =
{
{HW2_Letterbox(1),},
{
{ “Camera_AllowControl(0)”, “”, },
{ “Universe_EnableSkip(0)”, “”, },
{ “Universe_AllowPlayerOrders(0)”, “”, },
{ “SobGroup_DeSelectAll()”, “”, },
{ “Sensors_Toggle(0)”, “”, },
},
}
Events.startcinematic_focusrestore =
{
{HW2_Letterbox(1),},
{
{ “Camera_AllowControl(0)”, “”, },
{ “Universe_EnableSkip(0)”, “”, },
{ “Universe_AllowPlayerOrders(0)”, “”, },
{ “SobGroup_DeSelectAll()”, “”, },
{ “Camera_FocusSave()”, “”, },
{ “Sensors_Toggle(0)”, “”, },
},
}
Events.stopcinematic =
{
{HW2_Letterbox(0),},
{
{ “Universe_AllowPlayerOrders(1)”, “”, },
{ “Camera_AllowControl(1)”, “”, },
},
}
Events.stopcinematic_focusrestore =
{
{HW2_Letterbox(0),},
{
{ “Universe_AllowPlayerOrders(1)”, “”, },
{ “Camera_FocusRestore()”, “”, },
{ “Camera_AllowControl(1)”, “”, },
},
}

[code][/details]

I also get many of these:

[code]
luaplayer 300: Player_GrantResearchOption: unable to grant (cpuplayers_defensive)
parameter: 1
stack traceback:
1: function `research_init’ at line 26 [string “”]
[\code]

Those may have something to do with each other.

I found the problem, the research were unable to be granted, restricted or unrestricted because those were not inside scripts\research, but I had them in the def_research.lua as in the previous version.

2 Likes