Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

"You've got the lead" Goto page Previous 1, 2, 3 Next

| Inside3d Forums Forum Index -> QuakeC Programming

View previous topic :: View next topic
Author | Message
--- | ---
redrum Joined: 28 Mar 2007 Posts: 367 Location: Long Island, New York |

Posted: Fri Nov 16, 2007 3:54 am Post subject: |

I guess there would be no oldleader at the time of the first frag. So, I guess, we can put this somewhere:

Code:
self = oldleader;

So everyone who starts the game would be the "oldleader"?
_________________
Welcome to the Overlook Hotel 69.113.123.178:27500

Back to top |

daemon Joined: 07 Nov 2007 Posts: 62 |

Posted: Fri Nov 16, 2007 4:45 am Post subject: |

oldleader is a local entity created each time the function spawns, defaulting to world, then once set by "oldleader = leader" oldleader will be the current leader. the global entity, leader, defaults to world at the begenning of the game, and when the function is called and leader is world, oldleader will also end up as world. this causes no problem UNLESS you try to sprint to oldleader while it is a non-client. since world isn't a client, it will cause an error while there is no leader before the function is called.
ultimately you'll want to check somewhere if the entity you're either looking at or trying to sprint to is a client or not. this can be done a few different ways:

Code:
if(entity.classname == "player")

or

Code:
if(entity.flags & FL_CLIENT)

I would use the 2nd method if doing any checks inside loops for speed purposes, but I always like to use floats instead of strings when possible because strings can be rather slow at times.

Quote:
self = oldleader;

that would set self to whichever entity oldleader is pointing to, and since self is always the entity that is looking at the code, there would be no reason to do that in this situation.
but once you understand all of this, question 3 still remains:

Quote:
3) How can the same crash occur with the current code?

_________________
-daemon [ daemonforge.org ]

Back to top |

redrum Joined: 28 Mar 2007 Posts: 367 Location: Long Island, New York |

Posted: Fri Nov 16, 2007 4:57 am Post subject: |

I kinda understand but not fully. Maybe it would happen if a player left the game while being the leader? _________________ Welcome to the Overlook Hotel 69.113.123.178:27500

Back to top |

daemon Joined: 07 Nov 2007 Posts: 62 |

Posted: Fri Nov 16, 2007 5:45 am Post subject: |

look more closely at this part of the function, noting that all entities are being looked at here, not just players.

Code:
head = nextent(world); while(head) { if(head.frags > leader.frags) leader = head;
head = nextent(head);
}

then this part, remembering that sprinting to a non-client results in an error.

Code:
sprint(leader, "You've got the lead.\n");

_________________
-daemon [ daemonforge.org ]

Back to top |

redrum Joined: 28 Mar 2007 Posts: 367 Location: Long Island, New York |

Posted: Fri Nov 16, 2007 4:58 pm Post subject: |

Wouldn't only clients acquire frags though? So how would a non-client become "leader"? _________________ Welcome to the Overlook Hotel 69.113.123.178:27500

Back to top |

Preach Joined: 25 Nov 2004 Posts: 122 |

Posted: Fri Nov 16, 2007 5:26 pm Post subject: |

redrum wrote:
Wouldn't only clients acquire frags though? So how would a non-client become "leader"?

Ah, that's the cunning part. If you suicide you lose frags, so it's possible for all the players on the map to have < 0 frags. Then something else on the map, which starts with 0 frags, would take the lead. You wouldn't have to worry about this if players can only gain frags.

Back to top |

redrum Joined: 28 Mar 2007 Posts: 367 Location: Long Island, New York |

Posted: Fri Nov 16, 2007 7:33 pm Post subject: |

I see. I did notice in my mod that when I am -5, and someone is -7 that I am not the leader. But it doesn't crash though. So I guess it's ok. I would like it to work in the negative numbers though. Where should I put

Code:
if(entity.classname == "player")

for it to work?
_________________
Welcome to the Overlook Hotel 69.113.123.178:27500

Back to top |

daemon Joined: 07 Nov 2007 Posts: 62 |

Posted: Fri Nov 16, 2007 9:13 pm Post subject: |

yes, or the non-string version:

Code:
if(entity.flags & FL_CLIENT)

but where would you put it?
also remember, using strings in loops can be very slow.
_________________
-daemon [ daemonforge.org ]

Back to top |

redrum Joined: 28 Mar 2007 Posts: 367 Location: Long Island, New York |

Posted: Fri Nov 16, 2007 9:50 pm Post subject: |

Code:
if(leader != oldleader && oldleader.flags & FL_CLIENT && leader.flags & FL_CLIENT) { centerprint(leader, "You've got the lead!\n"); centerprint(oldleader, "You've lost the lead!\n"); }

Hows that?
_________________
Welcome to the Overlook Hotel 69.113.123.178:27500

Back to top |

daemon Joined: 07 Nov 2007 Posts: 62 |

Posted: Sat Nov 17, 2007 2:52 am Post subject: |

that would prevent anything being printed to the leader or oldleader if EITHER of them aren't clients, which is almost right for part of it. The first thing you want to do is prevent leader from being set to anything that isn't a client in the loop above that, BUT the first time the function is called, oldleader will still == world, SO, what you need to do is also put an if() statement just above the line that prints to the oldleader.
_________________
-daemon [ daemonforge.org ]

Back to top |

daemon Joined: 07 Nov 2007 Posts: 62 |

Posted: Sat Nov 17, 2007 10:00 pm Post subject: |

another exercise would be to make it check for ties, and then if so sprint to everyone who is tied for the lead instead of sprinting to leader and oldleader. _________________ -daemon [ daemonforge.org ]

Back to top |

redrum Joined: 28 Mar 2007 Posts: 367 Location: Long Island, New York |

Posted: Sun Nov 18, 2007 9:20 pm Post subject: |

Code:
if(leader != oldleader && oldleader.flags & FL_CLIENT && leader.flags & FL_CLIENT)

Let me see if I understand this line of code.
It means if the leader is not the oldleader and the oldleader is a client and the leader is a client?
Let's try the exercise.

Code:
if (leader.frags == oldleader.frags) { bprint (PRINT_MEDIUM,leader.netname); bprint (PRINT_MEDIUM,oldleader.netname); bprint (PRINT_MEDIUM, " are tied for the lead");
}

_________________
Welcome to the Overlook Hotel 69.113.123.178:27500

Back to top |

Orion Joined: 12 Jan 2007 Posts: 414 Location: Brazil |

Posted: Sun Nov 18, 2007 9:35 pm Post subject: |

And notice these lines:

Code:
bprint (PRINT_MEDIUM,leader.netname); bprint (PRINT_MEDIUM,oldleader.netname); bprint (PRINT_MEDIUM, " are tied for the lead");

You should put something between the first two and put a \n after the last letter of the last line, otherwise the in-game string will be like this:

Code:
player1player2 are tied for the leadSome other sprint...

Use this instead:

Code:
if (leader.frags == oldleader.frags) { bprint (PRINT_MEDIUM,leader.netname); bprint (PRINT_MEDIUM, " and "); bprint (PRINT_MEDIUM,oldleader.netname);
bprint (PRINT_MEDIUM, " are tied for the lead\n");
}

And that's it.
_________________
There's no signature here. Stop looking for one.

Back to top |

redrum Joined: 28 Mar 2007 Posts: 367 Location: Long Island, New York |

Posted: Mon Nov 19, 2007 12:28 am Post subject: |

I tested it, this does the trick! if (ent.frags == leader.frags && ent != leader)

Code:
{ bprint (PRINT_MEDIUM,leader.netname); bprint (PRINT_MEDIUM, " and "); bprint (PRINT_MEDIUM,ent.netname); bprint (PRINT_MEDIUM, " are tied for the lead\n");
}

What if 3 players are tied though
_________________
Welcome to the Overlook Hotel 69.113.123.178:27500

Back to top |

Orion Joined: 12 Jan 2007 Posts: 414 Location: Brazil |

Posted: Mon Nov 19, 2007 12:50 am Post subject: |

Well, not just 3, but 4, 5, 6, 7, or 1654984156 players can be tied. But anyways, it's not hard to do that. NOTE: My code might not work correctly, because I'm doing from scratch without testing. Well, let's see... You should create a local entity and do a find().
Then check if more than 2 players are tied, and then, bprint correctly.
Try this:

Code:
local entity t; bprint (PRINT_MEDIUM,leader.netname); bprint (PRINT_MEDIUM,", "); t = find(world, classname, "player"); while (t != world)
{
if (t.frags == leader.frags && t != leader)
{
bprint (PRINT_MEDIUM,t.netname);
bprint (PRINT_MEDIUM,", ");
}
t = find(t, classname, "player");
}
bprint (PRINT_MEDIUM," are tied for the lead\n");

Give it a try... maybe it works.
_________________
There's no signature here. Stop looking for one.

Back to top |

Display posts from previous:

| Inside3d Forums Forum Index -> QuakeC Programming | All times are GMT Goto page Previous 1, 2, 3 Next
Page 2 of 3

Jump to:

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2004 phpBB Group