EDIT: Reworked to random Q and A
Create file
qanda.lua (corrected) - paste code. Attach qanda.lua to character. You should only need to modify the questions, answers and correct answers.
Walk toward character, question is asked. Walk away, come back and a new random question is asked. (may be the same question however)
Possible additions?
- Close out questions from being asked twice.
- Change quantity of answers per question
1 hour coded and tested. You owe me a beer.
-- script by !nullptr
-- This script is made available for free use within non-commercial or commercial projects only.
-- It cannot be scraped, modified and resold without the authors express permission.
local q = {}
local correctAnswers = {}
q[1] = "Q1 - Answer should be 3"
q[2] = "Q2 - Answer should be 1"
q[3] = "Q3 - Answer should be 2"
q[4] = "Q4 - Answer should be 3"
q[5] = "Q5 - Answer should be 5"
correctAnswers[1] = "3"
correctAnswers[2] = "1"
correctAnswers[3] = "2"
correctAnswers[4] = "3"
correctAnswers[5] = "5"
local a = {}
-- quick hack - start index at 5 to snatch the right answer set from rnd q ( i * 5)
a[5] = "Q1 - A1"
a[6] = "Q1 - A2"
a[7] = "Q1 - A3"
a[8] = "Q1 - A4"
a[9] = "Q1 - A5"
a[10] = "Q2 - A1"
a[11] = "Q2 - A2"
a[12] = "Q2 - A3"
a[13] = "Q2 - A4"
a[14] = "Q2 - A5"
a[15] = "Q3 - A1"
a[16] = "Q3 - A2"
a[17] = "Q3 - A3"
a[18] = "Q3 - A4"
a[19] = "Q3 - A5"
a[20] = "Q4 - A1"
a[21] = "Q4 - A2"
a[22] = "Q4 - A3"
a[23] = "Q4 - A4"
a[24] = "Q4 - A5"
a[25] = "Q5 - A5"
a[26] = "Q5 - A1"
a[27] = "Q5 - A2"
a[28] = "Q5 - A3"
a[29] = "Q5 - A4"
-- NOTE THIS CODE WILL ONLY WORK WITH 5 ANSWERS. (Might be able to leave answers blank?)
function qanda_init(e)
plyrAnswer = 0
pressed = 0
msg = "Get the answer right and ye shall be rewarded, Make your choice."
qAsked = 0
end
function qanda_main(e)
if qAsked == 0 then
qNum = math.random(1,5)
aIndex = qNum *5
qAsked = 1
end
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 150 then
-- show question
TextCenterOnXColor(50,35,1, q[qNum], 100,255,100)
-- show answers
y = 40
for i = 0, 4, 1 do -- start at 0 to allow index additive
TextCenterOnXColor(50,y,1, (i+1).." : "..a[aIndex+i], 100,255,255)
y = y + 2
end
-- show status message
TextCenterOnXColor(50,y + 4,1, msg, 255,100,100)
-- grab keypress
plyrAnswer = GetInKey()
if (plyrAnswer == "1" or plyrAnswer == "2" or plyrAnswer == "3" or plyrAnswer == "4" or plyrAnswer == "5") and pressed==0 then
if plyrAnswer == correctAnswers[qNum] then
msg = "Well aren't you clever..."
else
msg= "No, that is the wrong answer. Try again."
end
pressed=1
end
end
-- player moved away - reset and dial new random - we shoulde xclude what has already been asked but meh.... Test only.
if qAsked == 1 and PlayerDist >= 150 then
qAsked = 0
msg = "Get the answer right and ye shall be rewarded, Make your choice."
end
if plyrAnswer == "" then
pressed=0
end
end
AKA SisterMatic (Steam)
Development/ Gaming Rigs
Sys 1: i7-4770 (3.5)/16Gb/128 SSD/3Tb/970gtx/2 x 23, 1 x 27 LCD - Sys 2: i7/8Gb/670gtx/1.5Tb/1 x 23 LCD - Sys 3: Amd Quad/8Gb/645gtx/1Tb/30" LCD