Jump to content
SubSpace Forum Network

Recommended Posts

Posted

This will be posted in public as a tutorial, so be as informative as you can.

 

 

 

I want to create my own module, preferably python. I want someone who knows how, to explain to me each step of the way how this module is written:

 

Theres three bases. Untitled_7.png

 

At the beginning of a game, I want to send out an arena message saying "Next game will begin in a moment" "Which base do you want to use? Vote 1, 2, or 3 (in public chat)"

 

Then it needs to read public chat and see which number was said the most, one vote per person, and if they change their vote, the module will consider their latest vote and ignore the previous votes from that player.

 

Once the module determines which base to use, it will close the other two doors on the map, closing off the other two base. Then warp everyone to center and start the game.

 

Off the top of my head I suppose I need the 'interface' "chat" to record what players vote, and I need the 'interface' "game" to control doors and warp players. Is that correct? And do I need more?

import ASSS

chat = ASSS.getInterface(!@#$%^&*s.I_CHAT)
game = ASSS.getInterface(!@#$%^&*s.I_GAME)

 

Now what? I'm a noob.

Posted

You'll need cfg/I_CONFIG to change the doors via settings.

 

For vote code you can look at elim in py or sgm_vote in C. Despite its name, sgm_vote is intended to swap between different game types, such as ctf and turf, so will need editing. The C version only counts the first number the player typed, I didn't double check the py version.

 

One major thing you didn't mention is what defines the beginning/end of a game. Can't really make the module without knowing that. Commands could be used if you haven't decided yet (it can be changed later).

Posted

import ASSS

chat = ASSS.getInterface(!@#$%^&*s.I_CHAT)
game = ASSS.getInterface(!@#$%^&*s.I_GAME)
cfg = ASSS.getInterface(!@#$%^&*s.I_CONFIG)

# vote

# allows players to say any positive number into pub chat and it will get
# recorded as a vote.
def vote_chatmsg(p, mtype, sound, to, freq, text):
if mtype == MSG_PUB:
	value = 0
try:
		value = int(text)
except:
	p!@#$%^&*

if value > 0:
	p.vote_value = value

def vote_make_timer(arena, maxoption, timelimit, callback):
def vote_timer():
	# stop allowing votes
arena.vote_ref1 = None
arena.vote_ref2 = None

	# initialise the array
	sums = []
for i in range(maxoption):
	sums.append(0)

	# count the votes
def cb_count_votes(p):
	if p.arena == arena and \
		p.vote_value > 0 and \
	p.vote_value <= maxoption:
		sums[p.vote_value - 1] += 1
for_each_player(cb_count_votes)

	# find the most popular vote
besti = -1
best = 0
for i in range(maxoption):
	if sums[i] > best:
		best = sums[i]
	besti = i

	callback(arena, best, besti + 1)
#arena.vote_ref3 = None
return 0
return set_timer(vote_timer, timelimit, 1000)

def vote_paction(p, action, arena):
if action == PA_ENTERARENA:
	p.vote_value = 0

def vote_start(arena, question, maxoption, timelimit, callback):
# reset all votes for this arena
def cb_reset_votes(p):
	if p.arena == arena:
	p.vote_value = 0
for_each_player(cb_reset_votes)

chat.SendArenaMessage(arena, "%s" % question)
arena.vote_ref1 = reg_callback(CB_CHATMSG, vote_chatmsg, arena)
arena.vote_ref2 = reg_callback(CB_PLAYERACTION, vote_paction, arena)
arena.vote_ref3 = vote_make_timer(arena, maxoption, timelimit, callback)

# stops the voting process
def vote_stop(arena):
arena.vote_ref1 = None
arena.vote_ref2 = None
arena.vote_ref3 = None

 

Is that all the code I need? Also, can you explain these 'function parameters'? Example:

def vote_chatmsg(p, mtype, sound, to, freq, text)

Posted

All that code will handle the voting. I doubt it will work without reformatting, it looks like it is using a mixture of tabs and spaces for indenting, and the forum coverted tabs to spaces, so copy/pasting it now will just break it.

 

For the parameters, that function is actually the CB_CHATMSG callback, so you could check chat.h but I will explain it here:

p - player

mtype - message type (pub, team, etc, check the .h files for the constants)

sound - optional bong, 0=no sound, check defs.h for the sound constants

to - I didn't check this but it's probably a player object, only valid if mtype is a priv message

freq - same as above but for team messages

text - the typed message

Posted

gotcha

 

ok, now i need to know how the function parameters are 'utilized' below the declaration of them, highlighted in red

 

Untitled_2_copy.png

 

just explain exactly what each value does and how it all interacts with eachother, in other words, where is the logic?

  • 3 weeks later...
Posted
you p!@#$%^&* it into the function whenever person casts a vote i guess i didn't look that carefully, and it would be a pretty big pain to make a vote bot that counts several votes and not double votes

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...