Here is an example of what Im trying to do.
Lets say there are 4 different clans you can join. If you join Clan A and kill a monster 1/10 of the exp goes to a var that is considered the amount of exp you've earned for you clan. How can I make is so that same amount is added to a list or global var so all members of Clan A can see how much there comined exp equal.
All members of Clan A:
Bob = 300exp
Dave = 150exp
John = 550exp
Clan A total = 1000exp
Im not looking for this verb to show all that but its just an example of how I want it to add all of Clan A's exp so the Clan can see how much they have earned. When I try to use a list it just says "You have earned [/list] exp for Clan A"
Any help would be appreciated. Thank you.
ID:165423
Dec 28 2006, 7:36 am
|
|
In response to Zythyr
|
|
Ok Thanks. What I wasnt sure about and I didnt really look into was making a var/ClanA and it be something that saves but not directly to a client. I thought it would be a var that would reset when the hub went down. I will give that a try. Thanks.
|
In response to Zythyr
|
|
Zythyr wrote:
Well, here is how I would do it. var/Clan_A_exp = 0 //Clan A's exp This isn't right. You should never ever have vars like clan_A_exp, clan_B_exp, clan_C_exp, etc. if you can simplify. If clans are important to the game, then you need to keep track of them in a better way. You need datums. clan Even in simple games like a CTF between red and blue, it's important not to use too-specific vars like red_score and blue_score, but to use something like this. As for keeping track of which clan a player belongs to, there are two ways you can do it. This is important to decide because it affects how savefiles will work. There's the first way, which is simple but can cause some savefile problems: mob The saving issue comes in when you try to save the mob; it will save the datum too. The datum also has a list of other mobs in the clan, so it'll save them too (which is very bad!) in your character file, but also you'll be saving different versions of the clan along with each member, so it may experience weird bugs like the exp being reset. The better way to keep track would be this: var/list/clans = new Whenever you need to look up the mob's clan, you'd use clans[themob.clan] to find it. When you give the exp, here is what to do. var/exp_gain //The exp your mob is gaining from killing the monster There's a subtle problem there. Both of those calls to round() are rounding down, which means that along the way you're actually losing exp to rounding errors. What you need to do is some regular rounding, then keep track of the result from that. if(clan) You'll notice I'm doing regular rounding first--rounding up if need be for the player's sake--and giving that amount to the player, then taking that out of the remaining exp_gain which goes to the clan. Lummox JR |
Hrm, I already responded to Zythyr's post, but it turns out he wasn't even steering you in the right direction at all. He was thinking you wanted to award partial experience to the clan and keep some yourself, but that isn't it at all. So while the advice I gave him is good for that situation, it won't work in the same way for yours.
What you still need to do is use datums to keep track of your clan. There's no other good way to do this. var/list/clans = new As you see there's no need in your case to keep track of the clan's exp separately. All you wanted to do was to see the players' totals, which this will give you. Lummox JR |
In response to Lummox JR
|
|
Thanks Lummox, I am having problems with the list probly because I dont completly understand them... I use list in my game but I probly use them incorrectly. What I dont know is how to access the list you just showed me.
Most things I work with start out with mob or obj or turf. It throws me off seeing it start with clan. Which I can probly understand as being the list itself. I dont know how to access or use the information you told me. When I use the list you just told me nothing different happens in my game. Thats probly because else where in my code I dont call for it. How is it I can use a list like you just typed to add members or exp. The only thing I could think of was to call it "call(clan/proc/TotalExp)()" I can see that being the incorrect way of using it but Im not sure how I can use it. I read over the "list()" chapter in DM Guide but it doesnt refer to useing a list the way you just typed it. I didnt know if you could explain to me how I use the list in my code. Example: Add a member to my clan list in the Login() proc. Thanks for any or all help. |
In response to Ssdave
|
|
Ssdave wrote:
Thanks Lummox, I am having problems with the list probly because I dont completly understand them... I use list in my game but I probly use them incorrectly. What I dont know is how to access the list you just showed me. By giving each mob a var that holds just the clan's name, you can look up the clan like so:
var/clan/C = clans[themob.clan]
The global clans list is an associative list; you can read mroe about those at BYONDscape, where one of my Dream Tutor columns explores how to use them. Most things I work with start out with mob or obj or turf. It throws me off seeing it start with clan. Which I can probly understand as being the list itself. I dont know how to access or use the information you told me. The clan isn't actually a list, just a piece of structured data. The only difference it has from an obj, mob, etc. is that it is not a physical object--it is not meant to appear on the map. I have a Dream Tutor column on datums as well that's worth your time. When I use the list you just told me nothing different happens in my game. Thats probly because else where in my code I dont call for it. How is it I can use a list like you just typed to add members or exp. The datum column will help explain that for you, but basically you'd have to write procs to add people to the members list. I didn't include those procs because 1) they weren't relevant to the issue at hand, and 2) they're actually a good exercise for you to get comfortable working with datums. The only thing I could think of was to call it "call(clan/proc/TotalExp)()" I can see that being the incorrect way of using it but Im not sure how I can use it. Consider a stat panel: mob/Stat() That's just one way of using it. I read over the "list()" chapter in DM Guide but it doesnt refer to useing a list the way you just typed it. I didnt know if you could explain to me how I use the list in my code. Example: Add a member to my clan list in the Login() proc. Thanks for any or all help. I could provide a quick answer to this, but since it's covered in the columns I mentioned, I think I'll just point you over to those. A good long read-through will answer your questions. Dream Tutor: Learn To Love Associative Lists Dream Tutor: Datums Are Our Friends Lummox JR |
In response to Lummox JR
|
|
Well... I am still having some troubles understanding how to use the list the way you used it here. I read over the tutorials and learned alot more about list but not in the way of starting it off as "clan". I am able to use it under "mob" and with a bumbed get the code started. The part that I was looking for the most is where you passed it right up. Example below.
var/list/teams = list() // a global list of teams team var/name var/list/players var/score = 0 var/colorrgb var/teamicon New(mob/M, nm, r, g, b) // player M starts a new team name = nm players = list() SetColor(r, g, b) Add(M) // add M to the team teams += src // add this team to the global list This is from your tutorial Datums are our friends. When you explain this part after the code you typed. Moving on to New(), it takes 5 arguments: A mob (the founder of the team), a name for the team, and red, green, and blue values for a color. The players list is initialized (it starts out empty), the color is set, the team's founder joins, and the team is added to the global teams list. Where it says the players list is intialized and color is set team founder joins and team is added to global. Thats where I cant figure out how that happens. I printed off both tutorials and have been going over them and testing my code for a few hours and I just cant seem to get it. Thats why I came back for some more direction of what to do. If you can please help me out again I would be very appreciative. Thank you. P.S. I read and followed your "Learn To Love Associative Lists" and was able to make a perfect working bank from it following your directions. It doesnt seem to work in the same way as what im trying to do because it all falls under a mob with a bumbed proc. I am starting to learn alot more but still having problems with the above kind of code. |
There is your variables set, next thing you would have is your DeathCheck or whatever method you have of giving the exp to the person.
When you give the exp, here is what to do.
Something along those lines I would imagine.