AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Mattie's Plugins (https://forums.alliedmods.net/forumdisplay.php?f=71)
-   -   Trivia (https://forums.alliedmods.net/showthread.php?t=38082)

volmasoft 05-26-2005 17:35

Trivia
 
Ok this is one for AJAX

I'm looking for an events script that can, when people die whisper the question to them, and this happens for each player in turn, (same question) and then the first correct answer gets a cash reward.

I know how to do the player death whispering, the cash reward, however selecting a question from a text file or database and the answer bit I don't have a clue.

So ajax can you help me make this?
Nat

ajax 05-26-2005 17:51

okay first of all i don't see why this question is ajax-restricted, but thanks for the shout out. i don't want the responsibility of answering all questions :D

some people have done something similar before (random selection) but i don't remember the threads. basically you use es_rand to generate a random number. then...

Quote:

(this is not code)
if number=1, then question=question1, answer=answer1
if number=2, then question=question1, answer=answer2
if number=3, then question=question1, answer=answer3
etc.
you'll have to write this out explicitly, so no drawing from a database. but the cfg file running this code would essentially serve as your database.

volmasoft 05-26-2005 17:52

AHA cheers ajax

volmasoft 05-26-2005 17:54

What do you mean by "this is not the code" ?? I understand it though and how to write it (I think)

I'm guessing this will have to be a script pack as I need to use the player_say.cfg to get the answers?

volmasoft 05-26-2005 18:01

I've got this:
random_question.cfg
Code:

setinfo questionnum 0
es_rand questionnum 1 2

// Question
if (rsoundnum equalto 1) then es_setinfo question how do you spell hello?
if (rsoundnum equalto 1) then es_setinfo answer hello
if (rsoundnum equalto 2) then es_setinfo question Does this work?
if (rsoundnum equalto 2) then es_setinfo answer dunno

I'm unsure whether the question and answer variables are set correctly, can you tell me Ajax? Do they have to be in quotation marks?
Nat

ajax 05-26-2005 18:04

Quote:

Originally Posted by volmasoft
What do you mean by "this is not the code" ?? I understand it though and how to write it (I think)

i mean if it was code it would look something like this
Code:

//sample code
if (server_var(my_random_number) equalto 3) then es_setinfo my_question_text "how smart is ichy? (a) not very (b) not very (c) not very (d) all of the above"
if (server_var(my_random_number) equalto 3) then es_setinfo my_answer_text "d"

Quote:

I'm guessing this will have to be a script pack as I need to use the player_say.cfg to get the answers?
nothing ever really NEEDS to be a script pack. script packs just allow for easier installation and will work no matter what eventscript_subdirectory is set to.

ichthys 05-26-2005 18:10

An Idea of how to make it more complicated; The more answers they get right the harder they get!

ajax 05-26-2005 18:16

Quote:

Originally Posted by volmasoft
I've got this:
random_question.cfg
Code:

setinfo questionnum 0
es_rand questionnum 1 2

// Question
if (rsoundnum equalto 1) then es_setinfo question how do you spell hello?
if (rsoundnum equalto 1) then es_setinfo answer hello
if (rsoundnum equalto 2) then es_setinfo question Does this work?
if (rsoundnum equalto 2) then es_setinfo answer dunno

I'm unsure whether the question and answer variables are set correctly, can you tell me Ajax? Do they have to be in quotation marks?
Nat

well rsoundnum should be server_var(questionnum) but other than that i'm not sure about the quotation marks.

you could also do something like this
Code:

// here's your database
es_setinfo question1 "blah?"
es_setinfo answer1 "blah"
es_setinfo question2 "blah blah?"
es_setinfo answer2 "blah blah"
es_setinfo question3 "blah blah blah?"
es_setinfo answer3 "blah blah blah"

Code:

// references your database
if (server_var(questionnum) equalto 1) then es_setinfo question server_var(question1)
if (server_var(questionnum) equalto 1) then es_setinfo answer server_var(answer1)

actually you could token your questionnum # into your server_var(question#) if your database is huge, but that's more advanced.

ajax 05-26-2005 18:18

Quote:

Originally Posted by ichthys
An Idea of how to make it more complicated; The more answers they get right the harder they get!

yeah i guess the sample question i used as an example is pretty easy.

ichthys 05-26-2005 18:27

Quote:

Originally Posted by ajax
Quote:

Originally Posted by ichthys
An Idea of how to make it more complicated; The more answers they get right the harder they get!

yeah i guess the sample question i used as an example is pretty easy.

I can think of an even easier one :D

Whenever a player is asked a question, you should store the answer in a userid specific cvar.


edit: nvm

volmasoft 05-26-2005 18:27

Ok here's my starting blocks that i've made so far, i'm trying to get my head around eventscripts still remember though so any bugs please report ;)

(btw ajax I corrected the variables, that was just adapting some previous coding;))

Ok here goes: (all in a script pack)
player_say.cfg
Code:

// Trivia commands
if (event_var(text) equalto "trivia") then es_msg #lightgreen Trivia version 0.1.0 is active, you will be asked a question when you die ,the first correct answer wins a cash prize.

// Remind the user of the trivia question
if (event_var(text) equalto "question") then es_tell event_var(userid) #lightgreen The trivia question is: server_var(question)

// If the question is answered correctly, tell the user directly and give cash reward.
if (event_var(text) equalto server_var(question)) then es_tell event_var(userid) #yellow CORRECT ANSWER!!!
if (event_var(text) equalto server_var(question)) then ma_givecash event_var(userid) server_var(difficulty)

// Once the question has been answered tell everyone else.
if (event_var(text) equalto server_var(question)) then es_msg #lightgreen The Answer was: server_var(answer), the person who answered it was event_var(userid) and the cash prize rewarded was:

// Clear the answer variable to stop people answering after the first person.
if (event_var(text) equalto server_var(question)) then es_setinfo answer abcdefghijklmnopqrstuvwxyz1234567890

player_death.cfg
Code:

es_tell event_var(userid) #lightgreen The trivia question is: server_var(question)
random_question.cfg
Code:

setinfo questionnum 0
es_rand questionnum 1 3

// Questions
if (questionnum equalto 1) then es_setinfo question how do you spell hello?
if (questionnum equalto 1) then es_setinfo answer hello
if (questionnum equalto 1) then es_setinfo difficulty 500
if (questionnum equalto 2) then es_setinfo question What is 2 plus 2 times 5 divided by 2
if (questionnum equalto 2) then es_setinfo answer 10
if (questionnum equalto 2) then es_setinfo difficulty 500
if (questionnum equalto 3) then es_setinfo question What is es?
if (questionnum equalto 3) then es_setinfo answer eventscripts
if (questionnum equalto 3) then es_setinfo difficulty 1500


Mattie 05-26-2005 18:39

(By the way, I just want to chime in here to state that I think this is a really neat script idea.)

volmasoft 05-26-2005 18:45

Cheers mattie, found any bugs?

ichthys 05-26-2005 18:47

Well done.

But I think your missing the line to exec random_question.cfg! Could be in either round_start.cfg or round_end.cfg!
edit: or you could just change random_question.cfg to round_start.cfg/round_end.cfg

Another thing, you wouldn't want anyone to find out what your default answer is!!! ie. abcdefghij.......890. I suggest es_xsetinfo answer "" because a player cant say nothing!

Also.....(last thing i promise, bet ajax's response will be faster than mine lol)
any line that has es or es_ at the beginning will not need es_ for any of the other commands down the like. This will help with performance.
e.g. Instead of:
Code:

if (event_var(text) equalto server_var(question)) then es_tell event_var(userid) #yellow CORRECT ANSWER!!!
Just use:
Code:

if (event_var(text) equalto server_var(question)) then es_xtell event_var(userid) #yellow CORRECT ANSWER!!!
Oh, and I didn't know #yellow was a color in ES? :?

ajax 05-26-2005 18:51

Quote:

Originally Posted by Mattie
(By the way, I just want to chime in here to state that I think this is a really neat script idea.)

i agree. the reason why i started looking into betting scripts was to create things for dead players to do... a mini game of sorts. this is similar.

btw here's something i could use and maybe volmasoft could use it too... es_msg_deadonly

McBain 05-26-2005 18:54

It sounds a great idea, but what concerns me is that for it to be any good, you are going to need hundreds and hundreds of questions and answers, so as they don't repeat over and over again... :?

ajax 05-26-2005 18:58

Quote:

Originally Posted by ichthys
Also.....(last thing i promise, bet ajax's response will be faster than mine lol)
any line that has es or es_ at the beginning will not need es_ for any of the other commands down the like. This will help with performance.

if you look at my code, i hardly ever use x... i'm just lazy that way
and it covers up my shortcomings in ES expansion understanding ;)

volmasoft 05-26-2005 19:06

Cheers guys,

Firstly, to ichthys - I hadn't finished the script and the colour isn't a token colour, just a random one to differentiate as I was in a rush.

Cheers for the ideas on how to minimise it (you can tell i'm new)

I hadn't finished up that's why nothing was there to execute but cheers mate ;)

Also thanks about the variable, I didn't know how to clear it so I made it as long as possible i'll edit that now.

To ajax cheers for that snippet of code it will make it even better, i'm hoping to have this up and ready for testing before 12pm midnight my time (55 minutes) .


This community is so good;)

BTW anyone want to come test it on a server? I'm willing to host (UK) or play on someone elses?

Nat

ichthys 05-26-2005 19:07

Quote:

Originally Posted by ajax
Quote:

Originally Posted by Mattie
(By the way, I just want to chime in here to state that I think this is a really neat script idea.)

i agree. the reason why i started looking into betting scripts was to create things for dead players to do... a mini game of sorts. this is similar.

btw here's something i could use and maybe volmasoft could use it too... es_msg_deadonly

When im motivated I'll include this in my track_player scriptpack

volmasoft 05-26-2005 19:08

mcbain, i'm hoping to put together a massive colleciton of questions so if anyone wants to help please add a list to this post and i'll add them, i'll then release it as a script pack hopefully tommorow evening.

As in my last post i'm hoping to be testing before midnight so i'm going to sotp replying and clear up my coding ;) (and make my usual readme files)

ichthys 05-26-2005 19:17

post the ip and ill ping it.

McBain 05-26-2005 19:17

I might be able to set a load of questions. If I can, I'll mail them to you. Is there any specific format you would want them in?

ajax 05-26-2005 19:21

Quote:

Originally Posted by volmasoft
To ajax cheers for that snippet of code it will make it even better, i'm hoping to have this up and ready for testing before 12pm midnight my time (55 minutes) .

whoa... don't get cocky it's gonna get rocky :D

i think i fixed some bugs in your posted code...
Quote:

// If the question is answered correctly, tell the user directly and give cash reward.
if (event_var(text) equalto server_var(answer)) then es_tell event_var(userid) #yellow CORRECT ANSWER!!!
if (event_var(text) equalto server_var(answer)) then ma_givecash event_var(userid) server_var(difficulty)

// Once the question has been answered tell everyone else.
if (event_var(text) equalto server_var(answer)) then es_msg #lightgreen The Answer was: server_var(answer), the person who answered it was event_var(es_username) and the cash prize rewarded was: server_var(difficulty)

// Clear the answer variable to stop people answering after the first person.
if (event_var(text) equalto server_var(answer)) then es_setinfo answer ""

volmasoft 05-26-2005 19:24

Quote:

Originally Posted by ajax
Quote:

Originally Posted by volmasoft
To ajax cheers for that snippet of code it will make it even better, i'm hoping to have this up and ready for testing before 12pm midnight my time (55 minutes) .

whoa... don't get cocky it's gonna get rocky :D

i think i fixed some bugs in your posted code...
Quote:

// If the question is answered correctly, tell the user directly and give cash reward.
if (event_var(text) equalto server_var(answer)) then es_tell event_var(userid) #yellow CORRECT ANSWER!!!
if (event_var(text) equalto server_var(answer)) then ma_givecash event_var(userid) server_var(difficulty)

// Once the question has been answered tell everyone else.
if (event_var(text) equalto server_var(answer)) then es_msg #lightgreen The Answer was: server_var(answer), the person who answered it was event_var(es_username) and the cash prize rewarded was: server_var(difficulty)

// Clear the answer variable to stop people answering after the first person.
if (event_var(text) equalto server_var(answer)) then es_setinfo answer ""


Cheers ajax, right as usual, every little helps ;)

Server i'm suggesting is 84.234.17.36:27015





For questions, I need the format of:
question
answer

question
answer

Cheers guys for all this help. I'll of course release this tomorrow or as soon as i've got enough questions.

ichthys 05-26-2005 19:27

yeah, latency for me is 250+

volmasoft 05-26-2005 19:28

If u want a diff server suggest it I don't mind ;) (if not then i'll remove the high ping kick for tonight ;))

ajax 05-26-2005 19:34

i'm pinging 200. open it up for us tonight.

ichthys 05-26-2005 19:35

I love matrix fights

volmasoft 05-26-2005 19:35

I'm just running some tests to make sure it works.

I thought i'd done it wrong as it didn't respond a second ago, I forgot to register it in eventscripts ;)

volmasoft 05-26-2005 19:39

Currently i'm getting a blank question, any ideas?

ajax 05-26-2005 19:41

Quote:

Originally Posted by volmasoft
Currently i'm getting a blank question, any ideas?

post your relevant code

volmasoft 05-26-2005 19:44

roundstart.cfg
Code:

setinfo questionnum 0
es_rand questionnum 1 6

// Questions
if (questionnum equalto 1) then es_setinfo question Who invented the lightbulb?
if (questionnum equalto 1) then es_setinfo answer Thomas Edison
if (questionnum equalto 1) then es_setinfo difficulty 1500
if (questionnum equalto 2) then es_setinfo question What is 2 plus 2 times 5 divided by 2
if (questionnum equalto 2) then es_setinfo answer 10
if (questionnum equalto 2) then es_setinfo difficulty 100
if (questionnum equalto 3) then es_setinfo question What is es?
if (questionnum equalto 3) then es_setinfo answer eventscripts
if (questionnum equalto 3) then es_setinfo difficulty 1500
if (questionnum equalto 4) then es_setinfo question Who was the first man on the moon?
if (questionnum equalto 4) then es_setinfo answer Neil Armstrong
if (questionnum equalto 4) then es_setinfo difficulty 1500
if (questionnum equalto 5) then es_setinfo question Who is the negative judge in American Idol?
if (questionnum equalto 5) then es_setinfo answer Simon Cowell
if (questionnum equalto 5) then es_setinfo difficulty 1000
if (questionnum equalto 6) then es_setinfo question Who is the negative judge in American Idol?
if (questionnum equalto 6) then es_setinfo answer Simon Cowell
if (questionnum equalto 6) then es_setinfo difficulty 500

player_say.cfg
Code:

// Trivia commands
if (event_var(text) equalto "trivia") then es_msg #green Trivia version 0.1.0 is active, you will be asked a question when you die ,the first correct answer wins a cash prize.

// Remind the user of the trivia question
if (event_var(text) equalto "question") then es_tell event_var(userid) #green The trivia question is: server_var(question)
if (event_var(text) equalto "test" then es_tell event_var(userid) server_var(question)

// If the question is answered correctly, tell the user directly and give cash reward.
if (event_var(text) equalto server_var(answer)) then es_tell event_var(userid) #green CORRECT ANSWER!!!
if (event_var(text) equalto server_var(answer)) then ma_givecash event_var(userid) server_var(difficulty)

// Once the question has been answered tell everyone else.
if (event_var(text) equalto server_var(answer)) then es_msg #green The Answer was: server_var(answer), the person who answered it was event_var(es_username) and the cash prize rewarded was: server_var(difficulty)

// Clear the answer variable to stop people answering after the first person.
if (event_var(text) equalto server_var(answer)) then es_setinfo answer ""
if (event_var(text) equalto server_var(answer)) then es_setinfo question ""
if (event_var(text) equalto server_var(answer)) then es_setinfo difficulty ""

I don't think it's setting the variables? or maybe i'm calling the wrong variables? Prehaps it needs quotation marks? (i'll try whilst u reply)

volmasoft 05-26-2005 19:48

Just noticed another problem, the alive players can say Trivia and get the question, and can therefore guess the answer? I'll take a look at ajax's suggestion about telling dead people.

ajax 05-26-2005 19:52

Quote:

// Questions
if (server_var(questionnum) equalto 1) then es_setinfo question Who invented the lightbulb?
if (server_var(questionnum) equalto 1) then es_setinfo answer Thomas Edison
if (server_var(questionnum) equalto 1) then es_setinfo difficulty 1500
Quote:

Originally Posted by volmasoft
Just noticed another problem, the alive players can say Trivia and get the question, and can therefore guess the answer? I'll take a look at ajax's suggestion about telling dead people.

i was requesting something that doesn't exist. use "if (event_var(es_userdead) equalto 1)" to check if they are dead.

you've got 6 minutes ;)

volmasoft 05-26-2005 19:55

Quote:

Originally Posted by ajax
Quote:

// Questions
if (server_var(questionnum) equalto 1) then es_setinfo question Who invented the lightbulb?
if (server_var(questionnum) equalto 1) then es_setinfo answer Thomas Edison
if (server_var(questionnum) equalto 1) then es_setinfo difficulty 1500
Quote:

Originally Posted by volmasoft
Just noticed another problem, the alive players can say Trivia and get the question, and can therefore guess the answer? I'll take a look at ajax's suggestion about telling dead people.

i was requesting something that doesn't exist. use "if (event_var(es_userdead) equalto 1)" to check if they are dead.

you've got 6 minutes ;)


I've got around the dead thing, it now has this line.
Code:

if (event_var(text) equalto "question") then es_msg_deadonly event_var(userid) #green The trivia question is: server_var(question)

ajax 05-26-2005 20:06

Quote:

Originally Posted by volmasoft
I've got around the dead thing, it now has this line.
Code:

if (event_var(text) equalto "question") then es_msg_deadonly event_var(userid) #green The trivia question is: server_var(question)

hehe... es_msg_deadonly doesn't exist yet.

ready or not here we come!

volmasoft 05-26-2005 20:07

Currently only selects the same question in round_Start.cfg (see above posts)

It only selects the first question? I'm hoping that my fix of resetting the random number in round_end might work (yet to test)

Also the money works great they get the amount, but the money it says that has been given to all of the users misses a 0 from the end which seems odd.

Match is delayed hopefully only 20 mins but might be until 1.

volmasoft 05-26-2005 20:47

Ok in conclusion.

After the lovely match of spam wars between ajax and ich to get the most money, the var's aren't clearing so i'm going to fix them now ;)

ajax 05-26-2005 20:51

you could add a var trivia_answered = 0/1

volmasoft 05-26-2005 20:55

hmm, and use if statements? yes it could be done.

However if I can set the question to a random one then there is no way to answer anyway ;) And it's cleaner code.


All times are GMT -4. The time now is 08:53.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.