Jump to content

Viceroy

Member
  • Posts

    1298
  • Joined

  • Last visited

Community Answers

  1. Viceroy's post in Can anyone please explain getModData() and toModData()? was marked as the answer   
    Here is a script I wrote for you that you can hopefully glean some info from. Should actually be multiplayer compatible too if you execute it client-side by placing it in "MYMOD/media/lua/client/"
     
    Hope it helps
    function placeTheMicrofilm()    local player = getPlayer(); -- This is me    local myModData = player:getModData(); -- This is our reference to our modData    local secretMessage; -- This is a string that we will save in the modData, it is nil now                if (myModData.secret == nil) then --If we have nothing stored in this modData then we place the microfilm and then fill in the modData            print("=========== NO MICROFILM DETECTED ===========");        local RNG                    = ZombRand(1, 4); -- For fun we make a random number between 1 and 4 (Not sure if it is inclusive atm)                if RNG == 1 then            secretMessage = "The microfilm is under the seat.";    -- Based on the RNG we have our string of where the microfilm is placed.        end                if RNG == 2 then            secretMessage = "The microfilm is under your cup.";    -- ditto        end                if RNG == 3 then            secretMessage = "The microfilm is under the table.";        -- ditto        end                if RNG == 4 then            secretMessage = "The CIA is onto me! The microfilm is gone!";        -- ditto        end                myModData.secret = secretMessage; -- Set our secret message        print("============ MICROFILM IS PLACED ============"); --Print to console so we can see if it executed.            elseif (myModData.secret ~= nil) then --If we have something in the modData then we just print console stuff and end            print ("============ MICROFILM IS ALREADY PLACED, SKIPPING PLACEMENT ============");            end    endfunction whereIsTheMicrofilm()    local player = getPlayer(); -- This is me again    local myModData = player:getModData(); -- This is our reference to our modData, again    if (player) then --This is to check if we have a player.        player:Say(myModData.secret); -- if so, let him/her say where the microfilm is.    endendEvents.OnLoad.Add(placeTheMicrofilm); --This is a safety net in case the mod gets activated on a character that already exists. I am unsure if it executes on a new game.Events.OnNewGame.Add(placeTheMicrofilm); --When we start a new game, hide the microfilm comradeEvents.EveryTenMinutes.Add(whereIsTheMicrofilm); --This calls our event
×
×
  • Create New...