ID:264865
 
Code:
    Death(mob/M)
if(src.Hp <= 0)
Hp = 0
if(!src.client)
if(istype(src,/monster/))
new/obj/bloodtraill(src.loc)
M.Xp += round((src.Xp))
M.TBXp += src.Xp
M.DK += src.DK
M.TK += 1
M.Rep += src.Rep
spawn del src
M << output("<font color=#347C2C> You've gained Xp for killing [src].","info")
M.Rep += 1
if(M.in_party == 1)
for(var/mob/P in usr.party)
for(P in oview(8))
var/fair_share = round(Xp/members)
P.Xp +=fair_share
P << output("<font color=#347C2C> You've gained [fair_share] Xp.","info")
M.Level_up()
M.UpDateB()
spawn del src
respawn(type, locate(sx,sy,sz))
if(src.Npc == 1)
spawn del src
M.Xp += round( (rand(src.Xp * 0.8, src.Xp * 1.2) ))
M.TBXp += src.Xp
M.DK += src.DK
M.TK += src.TK
M.Rep += src.Rep
M << output("<font color=#387C44> You've gained experience for killing [src].","info")
src.SaveC()
spawn del src


Problem description:
Party System will not give exp when some in the party kill a monster

First of all, stop using usr. You are using both src and usr in this code and cluttering it all to hell and back.

Second, I can only imagine you want to increment M's party's experience, not usr's.

                        if(M.in_party == 1) // check if M is in a party
for(var/mob/P in usr.party) // use usr's party.
for(P in oview(8))
var/fair_share = round(Xp/members)
P.Xp +=fair_share
P << output("<font color=#347C2C> You've gained [fair_share] Xp.","info")


Chances are M might be your usr, but I would need to know more to determine that. You're also refering to a members variable that is never defined within the function, so I can only assume it is a member of src...

What I do know is your method of checking the distance their mob is from the party is completely wrong. for(P in oview(8)) is not checking if the value held by P is in oview(8). It's starting a loop and going through all of the mobs in oview(8). For every member of the party. What you want is "if(P in oview(8))". Even better, you should save this value (oview(8)) outside of the loop somewhere, so you don't have to keep generating the list every time.
In response to Keeth
"Even better, you should save this value (oview(8)) outside of the loop somewhere, so you don't have to keep generating the list every time"
That may give some "errors" , for example it can consider a mob whitch was in oview and now it`s not.....

In response to RaZz84
That would never happen, because that's not how threads work.

The only time anything can happen, other than what is happening right now, is for the current thread to give up priority by sleeping or ending. oview(8)'s result has no chance of changing until one of these things happens.

In case what I said wasn't clear enough, I meant creating the oview() list just before the loop. I didn't mean defining it somewhere else arbitrarily, and checking it later.

                        var/list/_oview = oview(M, 8)
if(M.in_party == 1)
for(var/mob/P in M.party)
if(P in _oview)
var/fair_share = round(Xp/members)
P.Xp +=fair_share
P << output("<font color=#347C2C> You've gained [fair_share] Xp.","info")


edit: alternatively, you can use a list AND to return a list that has only mobs in oview(8) and the party.

var/list/party_in_oview = M.party & oview(M,8)
for(var/mob/P in party_in_view)
// etc...
for(var/mob/P in usr.party)
for(P in oview(8))
var/fair_share = round(Xp/members)
P.Xp +=fair_share
P << output("You've gained[fair_share] Xp.","info")

????????????????????????
First of :
usr refers to the initializer of the verb (human player)
src refers to the usr(player or ai) witch called the proc
So you see there are some small diference .

Second :Did you mean :

mob/var/tmp/exp_members =0
mob/var/tmp/Xpgained =0
mob/var/tmp/Xpshare =0
....
....
....
for(P in view(8))//including player
if (P.party ==src.party)//P is the mob in oview ; while src is the mob witch started the proc...
src.exp_members ++//used to see in how many pieces we cut the xp
if (src.Xpgained >0)
src.Xpshare =src.Xpgained/src.exp_members
for (P in view(8))
if (P.party ==src.party)
P.Xp +=src.Xpshare
P << output("You've gained[src.Xpshare] Xp.","info")
src.Xpgained =0
src.exp_members =0//not quite needed....
In response to RaZz84
That's a horrible system.

Partymembers should be a list, so the "members" variable can simply be replaced with Partymembers' len.
No point having 2 loops, nor 2 variables.
There are some.....other things....
For example ?
" Death(mob/M)
if(src.Hp <= 0)
Hp = 0"
Hp =0 -Whose Hp ? The source Hp ? Whitch it`s M ? I mean...the source it is M right ? So it should be src.Hp =0
Oh ...and the code i pasted on my previous post should be a update function(re-spawnable) ,or you need to found who killed the source and change my code src. with whokilled. !

Damn...i`n a little incoherent ....my appologies !

The worst think your code do is tellin` to give exp (because it gives - i think...) to mob`s party ...!?!? O_o
In response to Emasym
Yeah... you`re right ! But if i use a array(list) , i think he`ll get even more confused....:/
In response to RaZz84
usr refers to the initializer of the verb (human player)
src refers to the usr(player or ai) witch called the proc

This is a very bad explanation of usr and src. The fact that you used the word "usr" to explain src is quite bad as well...

usr refers to the mob of the client that initiated the call stack that has lead to the current function call (that is to say, the client of the mob that executed the verb that lead to this). If a client did not initiate the stack, it is null.

src refers to the owner of the function. It has nothing to do with who called it.

mob
proc
check_scope()
world << "usr: [usr || "za warudo"]"
world << "src: [src] (what, you were expecting maybe the Adam's Family?)" // TMNT joke lol

verb
test()
check_scope()

test2()
var/mob/m = new
m.name = "not you"
m.check_scope()

world
New()
..()
spawn()
while(1)
for(var/mob/m in world) m.check_scope()
sleep(100)
In response to Emasym
Still you`ll need 2 loops...
1 for deciding witch party members are in view and so creating the list !
2 for adding the exp to the list members....
Am i wrong ? It`s that bad ?
In response to Keeth
"Essentially, usr is an implicit parameter that is passed to every proc or verb. Each procedure inherits the value from its caller. While it can simplify your code in some situations, it can also lead to subtle problems if you are assuming that usr is automatically assigned to src when you call a verb programmatically. It is not."

src-"This is a variable equal to the object containing the proc or verb. It is defined to have the same type as that object.
"

"src refers to the owner of the function. It has nothing to do with who called it." The owner is the caller : if a mobX called the function , that mob is the src .Same if the player call the same function that player is the src !Or again i`m mistaking ?
In response to RaZz84
The concept of "the mob calling the function" is a little ambiguous, and I don't think the terminology is correct. For example, if a mob's function called another mob's function, you could say mob A is calling mob B's function. moba.function() doesn't mean moba is calling function(). It means moba's function() is being called.
In response to Keeth
"a little ambiguous" i see what`s the problem......
Hm....I think whe`re off-topic...:)
However i did not said my example was the best ! Only that it should to the work....I ,however ,didn`t used the lists because that seemed pointless in that examples.....Still need 2 loops...
In response to RaZz84
You need 1 loop, which is through your party members.
The other loops you've suggested are unnecessary. We already know how many members are in the party, and we don't need another loop directly to filter out party members that are in view.

var/xp_gain = 100
var/list/party_in_view = party & oview(8)
var/shared_gain = round(xp_gain / party_in_view.len)

for(var/mob/mob in party_in_view)
mob << "You gain [shared_gain] XP."


Might be necessary to add 1 to the "party length" to account for yourself (if it doesn't already).
In response to RaZz84
You can combine the two.
for(var/mob/p in killer.PartyList) if(p in killer.view(9)) p.AddPartyEXP(src.EXP)
In response to Keeth
"var/list/party_in_view = party & oview(8)"
Beautifull....:D....Can`t say anything.....
Only that his code need to be rewrited ....If i`m still not mistaking...he give xp to killed mob`s party....