smellymummy
King
- Joined
- Jul 31, 2002
- Messages
- 705
well is anyone else able to get that function to run at game init or is it just me?
-- Lua Script1
--------------------------------------------------------------
local trackarg1 = nil;
local trackarg2 = nil;
local trackarg3 = nil;
local trackarg4 = nil;
local moveai = 0;
function utrack (arg1, arg2, arg3, arg4)
trackarg1 = arg1;
trackarg2 = arg2;
trackarg3 = arg3;
trackarg4 = arg4;
local player = Players[ arg1 ];
local unit = player:GetUnitByID( arg2 );
local hx, hy = ToGridFromHex( trackarg3, trackarg4 );
local plot = Map.GetPlot(hx, hy);
unit:SetXY(hx, hy);
end
function validplot (pciv,unittag,arg1,arg2)
valid = 0;
iterations =0;
local hx, hy = ToGridFromHex( arg1, arg2 );
local plot = Map.GetPlot(hx, hy);
--not owned
if ( not plot:IsOwned() ) then
--is passable
if ( not plot:IsImpassable() ) then
--is land
if ( not plot:IsWater() ) then
--has no units
if ( plot:GetNumUnits()==0 ) then
valid=1;
end
end
end
end
print(valid);
if (valid==0) then
--choose another random spot
local iW, iH = Map.GetGridSize();
--validplot (rand)
posx = math.random (1,iW);
posy = math.random (1,iH);
validplot (pciv,unittag,posx,posy);
else
--order move unit
utrack (pciv,unittag,arg1,arg2);
end
end
function movesettlers ()
local player = Players[ 0 ];
for unit in player:Units() do
if (string.find( unit:GetName(), 'Settler') ) then
local iW, iH = Map.GetGridSize();
--validplot (rand)
posx = math.random (1,iW);
posy = math.random (1,iH);
validplot (0,unit:GetID(),posx,posy);
end
end
end
Events.SequenceGameInitComplete.Add ( movesettlers );
function realstart ()
print("Really really just started a game!");
end
--Events.SequenceGameInitComplete.Add ( realstart );
-- first let the game read in objects
local a = 0;
function init ()
print( "Hello World!" );
end
-- now that those are processed, the script can use those
if ( a == 0 ) then
init();
end
function realstart ()
print("====Really really just started a game!");
end
Events.SequenceGameInitComplete.Add ( realstart );
Events.GameplaySetActivePlayer.Add ( realstart );
Events.LoadScreenClose.Add ( realstart );
LuaEvents.DisplayMessage("test3");
--[[
MessagePopup.lua
Creator: alpaca
Last Change: 27.01.2011
Description:
Creates an event to display a generic pop-up message with a title and a text. Copies a lot of code from GenericPopup.lua
]]--
-- Shows popup window.
function ShowWindow()
ResizeWindow();
UIManager:QueuePopup( ContextPtr, PopupPriority.GenericPopup );
end
-- Hides popup window.
function HideWindow()
UIManager:DequeuePopup( ContextPtr );
ClearChildren();
end
function ResizeWindow()
Controls.ButtonStack:CalculateSize();
Controls.ButtonStackFrame:DoAutoSize();
end
function AddText(popupText)
local instance = {}
ContextPtr:BuildInstanceForControl("MessageLabelInstance", instance, Controls.ButtonStack)
instance.MessageLabel:SetText(popupText)
instance.MessageLabel:SetHide(false)
end
function SetPopupTitle(popupTitle)
if popupTitle then
Controls.PopupTitle:SetText(popupTitle);
Controls.PopupTitle:SetHide(false);
else
Controls.PopupTitle:SetHide(true);
end
end
function ClearChildren()
Controls.ButtonStack:DestroyAllChildren();
ResizeWindow();
end
-- Add a button to popup.
-- NOTE: Current Limitation is 4 buttons
function AddButton(buttonText, buttonClickFunc, strToolTip)
local instance = {}
ContextPtr:BuildInstanceForControl("MessageButtonInstance", instance, Controls.ButtonStack)
local button = instance.MessageButton --Controls["Button"..i];
if button then
local buttonLabel = instance.MessageButtonText
buttonLabel:SetText( buttonText );
if strToolTip then
button:SetToolTipString(strToolTip);
end
--By default, button clicks will hide the popup window after
--executing the click function
local clickHandler = function()
if buttonClickFunc then
buttonClickFunc();
end
HideWindow();
end
button:RegisterCallback(Mouse.eLClick, clickHandler);
button:SetHide(false);
return;
end
end
function ShowHideHandler( bIsHide, bIsInit )
if bIsInit or bIsHide then
Controls.ButtonStackFrame:SetHide(true)
else
Controls.ButtonStackFrame:SetHide(false)
end
end
ContextPtr:SetShowHideHandler( ShowHideHandler );
--[[
Displays a pop-up with a custom set-up.
Arguments:
fSetupFunction: function. Function that sets up all the buttons and texts itself
]]--
function DisplayPopup(fSetupFunction)
fSetupFunction()
ShowWindow()
end
LuaEvents.DisplayPopup.Add(DisplayPopup)
--[[
Displays a pre-made message pop-up
Arguments:
sText: string. Text to display. Required
sTitle: string. The title, will default to "Message"
tButtons: table. A table containing the buttons you want to display. Table keys are what to put on the button label, values is a tooltip (use false if you don't want one). Optional use: string. Interpreted as text for a single button, in which case tButtonIDs is interpreted as an optional tooltip and tHandlers as a callback function
tButtonIDs: table. A numeric table containing an ordered list of buttons if desired
tHandlers: table. Click handler functions for the buttons. Must be indexed by the key
]]--
function DisplayMessage(sText, sTitle, tButtons, tButtonIDs, tHandlers)
ClearChildren()
AddText(sText)
SetPopupTitle(sTitle)
if type(tButtons) == "table" then
-- buttons are given
if tButtonIDs then
-- ordered list
for _, buttonText in ipairs(tButtonIDs) do
local handler
if tHandlers then
handler = tHandlers[buttonText] or nil
end
local tooltip = tButtons[buttonText] and tButtons[buttonText] or nil
AddButton(tostring(buttonText), handler, tooltip)
end
else
-- unordered list
for buttonText, buttonTip in pairs(tButtons) do
local handler
if tHandlers then
handler = tHandlers[buttonText] or nil
end
AddButton(tostring(buttonText), handler, buttonTip and tostring(buttonTip) or nil)
end
end
elseif type(tButtons) == "string" then
-- only one button, interpret as strings
AddButton(tButtons, tHandlers, tostring(tButtonIDs))
else
AddButton(Locale.ConvertTextKey("TXT_KEY_CLOSE"))
end
ShowWindow()
end
LuaEvents.DisplayMessage.Add(DisplayMessage);
Double check your VFS settings?
It's kind of the first question for just about anything it seems. Like that first line in the trouble shooting guide of any wall powered product: Is the unit plugged in?
I have all debugoption on, i think.
Not what he means. Go into the mod's modinfo file, and check if the files in question have
import="1"
instead of
import="0"
for any Lua files that override existing logic. In ModBuddy, you can check this in the Properties window (it'll be true/false there with a pulldown), but the modinfo file is how you'd show us if it's working.
Is it possible to add event from map script level?
I don't think so. They get processed at a point well before the game has fully initialized, so I don't think you can get a popup-type event to work inside them. A lot of things are like that.
Map scripts can have altered versions of existing Lua functions, which will override the core game's versions. One of the more annoying bits is that maps also override mods; if my mod has changed AssignStartingPlots.lua, and the map script has its own variants of the resource distributions, then it'll use the map's version in preference to my own (which to me is backwards). But that's VERY different than triggering a new event.
And you don't need ModBuddy for ANY mods, really. All ModBuddy does when it "compiles" is copy all of your files to a Mods directory and create a .modinfo text file, which you can adjust by hand. It's not an actual software compiler; the only complex parts of the modinfo file are the checksum bits, AFAIK. So the fact that a map script can be done without it doesn't really mean much.
-----------------------------------------------------------------------------------
-----------------------------Map settings info-------------------------------------
-----------------------------------------------------------------------------------
local IronHorse_useroption = Map.GetCustomOption(9);
if IronHorse_useroption == 7 then
ScripSetText = ScripSetText .. " IronHorseQty=Random";
else
IronHorse_useroption = IronHorse_useroption + 1;
ScripSetText = ScripSetText .. " IronHorseQty=" .. IronHorse_useroption ;
end
local Uranium_useroption = Map.GetCustomOption(3);
if Uranium_useroption == 1 then
ScripSetText = ScripSetText .. " UraniumQty=None";
end
if Uranium_useroption == 2 then
ScripSetText = ScripSetText .. " UraniumQty=Rare" ;
end
if Uranium_useroption == 3 then
ScripSetText = ScripSetText .. " UraniumQty=Balanced" ;
end
for player_ID = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
player = Players[player_ID];
if ( isValidPlayer(player) and player:IsHuman() == true ) then
local CivName1 = player:GetName();
playerStartPlot = player:GetStartingPlot();
plotX = playerStartPlot:GetX();
plotY = playerStartPlot:GetY();
local playerteam_ID = player:GetTeam();
local lineQty = 1 ;
local areaID = playerStartPlot:GetArea();
local area = Map.GetArea(areaID);
local numTiles = area:GetNumTiles();
ScripSetText = ScripSetText .. " AreaTitles=" .. numTiles .. " ";
for i = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
if i ~= player_ID then
local playerProx = Players[i];
if isValidPlayer(playerProx) then
local playerProxteam_ID = playerProx:GetTeam();
if playerProxteam_ID ~= playerteam_ID then
local playerProxStartPlot = playerProx:GetStartingPlot();
local plotX2 = playerProxStartPlot:GetX();
local plotY2 = playerProxStartPlot:GetY();
local ProximityToPlayer = Map.PlotDistance(plotX, plotY, plotX2, plotY2);
if (ProximityToPlayer > 0 and lineQty < 6 ) then
local CivName2 = playerProx:GetName();
if mirrordebug == 1 then
print(">>>> ProximityToPlayer:",ProximityToPlayer,CivName1,CivName2);
end
lineQty = lineQty + 1;
ScripSetText = ScripSetText .. " " .. CivName1 .. "<-->" .. CivName2 .. "=" .. ProximityToPlayer .. " ";
end
end
end
end
end
if(ScripSetText ~= nil) then
if mirrordebug == 1 then
print(">>>> ScripSetText:",ScripSetText);
end
[B]player:AddNotification(NotificationTypes.NOTIFICATION_DIPLOMACY_DECLARATION, ScripSetText , "Map setup description...", plotX, plotY);[/B]
end
end
end