1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Lua Scripting Possibilities

Discussion in 'Civ2 - General Discussions' started by JPetroski, Jan 21, 2018.

  1. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,774
    Location:
    Ontario
    This seems like a perfectly reasonable restriction. Occasionally, when I've written quick and dirty scripts that have had to write files, I've written directly to the TOT directory, since it is easier. However, that stuff hasn't been meant to be used by the end users of scenarios.

    At the moment, if I'm paranoid, I can search for things in the code like 'os.execute' and 'io.write.' If the code is supposed to be writing stuff, then I have to figure out if what is being written is advertised, which could possibly be a bit more involved.

    What we might do, is write a library with all the possible things you could want to overwrite (or, that are considered 'allowed' to be overwritten). For example, overwrite.rules(newRulesName), overwrite.movpiece(newSoundName).
     
  2. Civinator

    Civinator Blue Lion Supporter

    Joined:
    May 5, 2005
    Messages:
    6,418
    Gender:
    Male
    Prof. Garfield, of course you are not paranoid, but very, very helpful and -in contrary to myself - aware about the dangers that such codes can contain. Thank you very much for your answers. :) Nevertheless it would be nice, if the problem of the very simple Civ 2 'tac...tac...tac- sound' could be upgraded to individual sounds for Civ 2 ToT units, while an 'onmovement' trigger is missing in ToTPP.
     
  3. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,722
    Is there no way to add a count, veteran, and randomize to this:

    Code:
    civ.createUnit(object.uCenturion, object.tEurope,object.lHKInvasionPoint1)
    
    I need to use civ.createUnit vs. civlua.createUnit (which allows those options) because this is a naval invasion and I want the ground force to spawn at sea. Randomize isn't critical here but it is a shame I can't do count or vet as there are several units to get through.
     
  4. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,774
    Location:
    Ontario
    You (or someone else) will have to write equivalent code to civlua.createUnit, with the difference being that placing land units on water is allowed.

    Have you had a look at the code for civlua.createUnit and tried to understand it? There are a couple helper functions, and then the loop that generates units. Or, here is some relevant code from my munition library:

    Code:
            for i=1,numToGenerate do
                local newUnit = civ.createUnit(specification.generatedUnitType,
                    generatingUnit.owner,generatingUnit.location)
                newUnit.veteran = specification.giveVeteran or false
                newUnit.veteran = newUnit.veteran or (specification.copyVeteranStatus and generatingUnit.veteran)
                newUnit.homeCity = nil
                if specification.setHomeCityFunction then
                    newUnit.homeCity = specification.setHomeCityFunction(generatingUnit)
                end
                unitTable[i] = newUnit
            end
    
     
  5. JPetroski

    JPetroski Deity

    Joined:
    Jan 24, 2011
    Messages:
    2,722
    Is there a way to set parameters around what game years an event can randomly fire? I know how to use random turn, but I want there to be a floor and ceiling based on turn numbers for events to fire. How would I do that?

    Basically say I wanted there to be a 25% chance an event would fire once on any turn between 10 and 20. How would I define the range?
     
  6. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,774
    Location:
    Ontario
    If you want there to be a 25% chance to fire on any given turn between turn 10 and 20, use this condition (and a justOnce)

    Code:
    if turn >=10 and turn <=20 and math.random() < 0.25 then
    
    If you want a 25% chance for an event to ever happen, but guarantee that if it happens, it has an equal chance of happening on any turn between turn 10 and turn 20 (both inclusive) then you want something like this

    Code:
    -- define this counter in appropriate location
    counter.define("turnToTriggerEvent",-2)
    
    -- on the turn you want to decide whether the event will happen or not, and on which turn
    
    if turn == decisionTurn then
         if math.random() < 0.25 then
            counter.setValue("turnToTriggerEvent",math.random(10,20))
        end
    end
    
    -- Also, in onTurn (or, maybe, afterProduction) you check if the turn is the same as the counter value
    
    if turn == counter.value("turnToTriggerEvent") then
        -- do event stuff
    end
    
     
    JPetroski likes this.

Share This Page