ID:157661
 
I wanted to add a Random-Bounty for the server for my game. It would select a random player from the server who isnt in a SafeZone and they would get a Bounty placed on them for 10 minutes for Money or Training Points ( In-game points )- This would be kinda like an event for the whole server.. I will need the person who killed the player with the Bounty to gain the prize of Training Points or Money aswell, Which would probably be in my death proc.

I dont know i will code this all i know that it will probably be similar to an AFK-Check..


I also want to add some NPCs which select a person depending on your race for you to kill ( Say you talk to Grimmjow when your an Arrancar, It would pick a player who is Shinigami for you to kill ).. It would be similar to the first part except it would be an NPC giving it and it would only pick certain races depending on the NPCs and it would last around the same time than the first idea.. If you could help me then thanks! :}
for(mobs in world)
if(not in safe zone)
mob.bounty=100
In response to Ripiz
Alternatively, you could change it up a bit (for instance if you have monsters that you don't want to have a bounty). Create an area called Safezone (if you don't already have one)

proc/Bounty()
for(var/mob/Player/M in world) // Cycle through a specific mob
var/area/A = M.loc // Set this variable to their location.
while(!istype(A, /area)) // Dig down to an area.
A = A:loc // A now equals this area.
if(A.type!=/area/Safezone/)//If they are not on the area
M.Bounty=100 // Set their bounty.
break //Remove if you want more than one?


I'm not sure what you mean for your second part, I assume some sort of auto-selection for bounties? In such a case you just slightly modify what I added there to check for their races.
In response to Sealed Kyuubi
First, you should be encapsulating the area locating in its own procedure, like so:

proc/get_area(atom/A)
while(A && !isarea(A))
A = A.loc
return A


Second, you should be looping through clients, not mobs, and not mob/Players. It's much more straightforward.

Third, you didn't put anything in there that actually picks randomly.

Fourth, your last if() statement didn't work properly.

Anyway, here's a fixed solution:

proc/Bounty()
var/list/options = list()
for(var/client/C)
var/area/A = get_area(C.mob)
if(A && !istype(A, /area/Safe))
options += C.mob
fugitive = pick(options)
In response to Sealed Kyuubi
How would i also make the first part announce to the world who has been chosen for the Bounty and what the reward will be.

I was also wondering couldnt i make the Bounty similar to my AFK check which announces to the world, Because i want to make them appear after the person has been killed or survived 10 minutes.

world
proc
AFKcheck()
set background = 1
vara
spawn(rand(18000)+18000)
world << "AFK check, please say something in OOC in the next minute!"
AFKcheckin = 1
for(var/mob/M in world)
if(M.client)
M.checking = 1
spawn(500)
world << "<You have 10 seconds to say something on the OOC!"
spawn(600)
AFKcheckin = 0
for(var/mob/M in world)
if(M.checking == 1)
world << "[M.name]([M.key]) was booted with [round(M.client.inactivity/10)] seconds since last command."
del M.client
spawn(rand(18000)+18000)
goto vara


For the 2nd part i wanted it to be an NPC that picks the Bounty depending on who you talk to..

Say a Shinigami talks to Soi Fon - It would randomly pick an Arrancar/Espada/Hollow player from the game for them to kill.. Same with talking to Grimmjow for Hollow/Espada/Arrancar but it would pick a Shinigami player
In response to Garthor
Thanks for the help but ive already sorted it out. Got my own system for it now :D

Here is how it looks.

world
proc
random_player()
var/list/l=list()
for(var/mob/M in world)
if(M.client)
if(!M.safe&&!M.loggedoff)
l+=M
var/the = pick(l)
if(the == "")
chosenone = "no players available"
chosenone = "[the]"
world
proc
bounty()
set background = 1
vara
spawn(rand(18500)+18500)
if(chosenone == "no players available")
goto vara
if(randombounty)
goto vara
random_player()
randombounty = 1
var/random = rand(1,2)
if(random == 1)
tpbounty = rand(5000,7000)
world << "<center><font color = yellow><b>Event Info: [chosenone] has been selected as a random bounty with [tpbounty] training points placed on their head!"
if(random == 2)
moneybounty = rand(5000,7000)
world << "<center><font color = yellow><b>Event Info: [chosenone] has been selected as a random bounty with [moneybounty] money placed on their head!"
spawn(6000)
for(var/mob/M in world)
if(M.client)
if(chosenone == M.name&&!M.safe)
if(tpbounty > 0)
world << "<center><font color = yellow><b>Event Info: [chosenone] has successfully defended their life and claimed [tpbounty] training points!"
M.trainingpoints += tpbounty
tpbounty = 0
randombounty = 0
chosenone = ""
if(moneybounty > 0)
world << "<center><font color = yellow><b>Event Info: [chosenone] has successfully defended their life and claimed [moneybounty] money!"
M.money += moneybounty
moneybounty = 0
chosenone = ""
randombounty = 0
spawn(rand(18500)+18500)
goto vara
In response to Michael1234
No. That's an utter mess. Going through it one bit at a time:

for(var/mob/M in world) should be for(var/client/C). Then, you can do var/mob/M = C.mob to get the mob. The if(M.client) line can be replaced with if(M.mob) (there can be mob-less "ghost" clients due to a strange error that's out of your control, it's not common but it's good to be safe).

You should not be picking from the list l until AFTER the for() loop. Technically, doing it every iteration is the same, but it's utterly wasted time.

Comparing the picked element to "" is pointless, as you are only storing mobs in the list. Furthermore, even if it weren't, what you have in the if() statement is immediately replaced by the next line anyway. What you should have is this, outside the for() loop:

if(l.len) chosenone = pick(l)


Also, on a stylistic note, naming variables lower-case L is rather bad as it looks like a one. You really should change it to upper-case.


Next, in bounty(), you should not be using goto. Full stop. goto is ALWAYS the wrong choice. Instead, you should just wrap that whole thing in a while(). If your random_player() proc fails to find a player (which it won't ever do because your conditions are wrong, as I've already mentioned... the proper statement should be if(!chosenone)), random_player() will never get called again because the loop breaks before it can reach that line.

Moving on, you are abusing the hell out of spawn(). It won't really cause any issues here (actually it might, because I have no clue how it interacts with goto), but it's really messy. You should be using sleep() except where spawn() is strictly necessary... which means one spawn() at the beginning of the proc, before the while() loop you need to use.

Again, you are looping through every mob in the world when you should be looping through clients. Same solution to that.

You are storing chosenone as a text string. There is no reason for this. Keep it as a mob reference.
In response to Garthor
It works perfect for me so i aint bothered :P
In response to Michael1234
Then you have an insufficient test case, because that will break utterly under certain circumstances.

But I guess you'll just say "LOL BYOND BUG I JUST GOTTA RESTART THE SERVER MIRITE".
In response to Garthor
Its been in my game for about a week and its not broken so far... As i said it works perfectly fine.
In response to Michael1234
That only means you haven't stumbled upon the conditions under which it breaks.

And also that one mistake is completely covering up another mistake, resulting in a somewhat more minor error. Having no valid targets simply gives you a message like " has been chosen blah blah blah" rather than permanently breaking the whole thing.