Ugh.
Please, please, please,
please wrap your code inside CODE blocks.
You really don't need to be talking out of your ass. Refer to
the Modiki for a list of Lua methods you can use. It's slighty outdated, since it doesn't include anything new to BNW, but it's a start, and contains most of the stuff you will use.
Since you need to find information about a
Player, you will refer to the
Player Object Methods on the Modiki. Checking through that list will reveal to you that
Player:GetGold() is a valid Player method although the way you're trying to use it is not quite correct.
It seems as if you don't quite understand the code you are copying in an attempt to use.
That code is largely separated into two main blocks, each doing a different thing.
Code:
fmBoolean = true;
for i, player in pairs(Players) do
if player:GetBuildingClassCount(GameInfoTypes.BUILDINGCLASS_THEWONDER) then
fmBoolean = false;
end
end
This first section is not wrapped inside any function, and so it means it will run once when the script is loaded. Its purpose is to first set a
boolean value that a later function will refer to. To do so, it
loops through the
Players table, which contains all the data of all the Players in the game, in order to figure out if anyone has a value returned for
GetBuildingClassCount().
The way the condition is written, it doesn't care
what the value is, only that it has a value other than
false or
nil. The problem is I'm not entirely sure if it returns 0 or not if the building doesn't exist; I have yet to test this method.
In any case, if any value is found, it is assumed that the Wonder has been constructed, and it toggles the boolean.
There are two issues I see with this:
- This loop does not check for the Player actually being in the game, so it will loop over all of the nonexistent players as well, needlessly expending CPU cycles.
- This appears to have been potentially written before the last BNW patch which gave us the CityConstructed Game Event, which can fire when the Wonder is built to toggle the boolean then. The only downside to this approach is that you need to persist the boolean across game saves, whereas the above method doesn't rely on it since it manually scans every time.
In any case, the next section does the legwork.
It is a function attached to the
Game Event called
PlayerDoTurn which fires at the start of every Player's turn, right before they gain control. This code
adds a
new user function into that part of the game code, allowing the game to run this additional logic while it processes its own stuff at that point.
This Game Event provides one value: the
Player ID of whoever player's turn it is processing at that moment. This is captured in the custom function via the variable
iPlayer. The function then begins its logic by checking the global boolean that was set beforehand, and if that boolean is true (or rather, any value besides
nil or
false) then it runs another check to see if the current player owns the Wonder.
If it passes, then it toggles the boolean to prevent this function from firing again. After that, you can insert your Gold modifying code. To that point,
Player:GetGold() by itself returns a number. Placing something inside those parentheses means you are trying to pass into that method an argument, which I'm not sure if anything will happen since I don't think it expects any. To do a comparison, you have to compare against the
returned value:
Considering the nature of this function though, I'd imagine you could theoretically save a bit more on computing time by removing the function from the event hook altogether, but I don't believe you can do that as it's currently written, since it's an anonymous function.