====== Generating Dynamic Codes ======
You may have a need to generate dynamic passphrases or codes to be used in your area. This can be useful when you want to ensure that various parts of a puzzle are completed with each run of the zone, and/or to add replayability to the zone.
While this can be done via MPROGs, this example is using an OPROG that gets attached with a LOOK trigger. We generate random numbers that get used as X,Y coordinates (i.e. 50.32, 91.47) and then we show them to the player when they look at the object. We use the 'setval' function to assign these coords to the character so that they are not regenerated each time the character looks at the object.
-- LOOK. Fills the notebook with info, x-y coords most importantly.
coord1 = randnum(10,99)
coord2 = randnum(10,99)
coord3 = randnum(10,99)
coord4 = randnum(10,99)
x_coordinate = x_coordinate or coord1.."."..coord2
y_coordinate = y_coordinate or coord3.."."..coord4
echoat(ch1,"Sentient life confirmed -- 20 of Rustfall..")
echoat(ch1," ")
echoat(ch1,"L1 ="..x_coordinate)
echoat(ch1,"L2 ="..y_coordinate)
echoat(ch1," ")
if ch1:getval("colossus_x_coords") == nil then
ch1:setval("colossus_x_coords", x_coordinate, false)
end
if ch1:getval("colossus_y_coords") == nil then
ch1:setval("colossus_y_coords", y_coordinate, false)
end
====== Accepting the password or codes ======
In this example we have a MPROG triggered via 'SPEECH *' that accepts the coordinates. If the character says the wrong coordinates, they're damaged. If they give the correct coordinates, the targeting computer mob does some RP speech and then loads a portal in a nearby room.
-- SPEECH. Accepts Coordinates to fire upon.
function doorOpen()
mob:goto(20172)
mob.room:oload(20133)
mob:goto(20174)
echo("The sound of a lock depressurizing can be heard in the near distance.")
ch:setval("colossus_x_coords", nil)
ch:setval("colossus_y_coords", nil)
end
function gotEm()
echo("Target acquired at "..x.." , "..y)
delay(3, doorOpen)
end
function codeCheck(ch, arg)
x = ch:getval("colossus_x_coords")
y = ch:getval("colossus_y_coords")
x_given = x_given or 0
y_given = y_given or 0
if arg == x then
echo("X coordinates accepted, calibrating X-axis")
x_given = 1
end
if arg == y then
echo("Y coordinates accepted, calibrating Y-axis")
y_given = 1
end
if not (arg == x) and not (arg == y) then
echo("{MA Targeting Computer{x} attempts to calibrate to "..trigger)
say("Invalid location specified")
echo("You're shocked by {MA Targeting Computer{x for entering invalid coordinates.")
ch:damage(ch, 2000, true)
end
if x_given == 1 and y_given == 1 then
echo(" ")
echo("Coordinates accepted...")
echo("Recalibrating...")
echo("Locating Bastion")
delay(4, gotEm)
end
end
if ch:getval("colossus_x_coords") == nil or ch:getval("colossus_y_coords") == nil then
echo("You haven't learned the coordinates yet.")
return
else
codeCheck(ch, trigger)
end