AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Help] Aim @player shows total kills? (https://forums.alliedmods.net/showthread.php?t=47757)

trehmilou 11-25-2006 15:43

[Help] Aim @player shows total kills?
 
Hello,

I want to show a players' total kills in a small hudmessage when pointing at that guy.
My problem: after "Killz:" everybody seems to have the same value.

Here is my code so far:
Code:
public client_PreThink(id) {     new u_guy, body;     get_user_aiming(id, u_guy, body)     new u_stats[8]     new u_hits[8]     if (is_user_alive(u_guy))     {         get_user_stats(u_guy, u_stats, u_hits)                 set_hudmessage(10, 255, 10, 0.5, 0.55, 0, 6.0, 0.1)         show_hudmessage(id, "Killz: %i", u_stats[0])     } }

BIG THX!

@mods: sorry for all the mess :/

stupok 11-26-2006 22:56

Re: [Help] Aim @player shows total kills?
 
I don't see a reason for that code not to work, but I'd like to suggest two changes.

1. Make the body variable a global one, since you don't use it anyway, so that it is not re-created every frame.

2. Remove if_user_alive(u_guy), I don't think you can look at a dead player, I may be wrong.

Also, I don't know if you know this:
Quote:

Gets overall stats which are stored in file on server and updated on every respawn or user disconnect.

Emp` 11-27-2006 00:08

Re: [Help] Aim @player shows total kills?
 
Quote:

Originally Posted by stupok69 (Post 407751)
2. Remove if_user_alive(u_guy), I don't think you can look at a dead player, I may be wrong.

its just a simple way to check if its a player and not a different ent or not an ent at all

dutchmeat 11-27-2006 02:43

Re: [Help] Aim @player shows total kills?
 
Make sure you realise that the stats get's updated by respawn:
Quote:

Gets overall stats which are stored in file on server and updated on every respawn or user disconnect
Also you might want to debug u_guy...

Code:
public client_PreThink(id) {     new u_guy, body;     get_user_aiming(id, u_guy, body)     new u_stats[8]     new u_hits[8]     new name[33]     if (is_user_alive(u_guy))     {         get_user_name(id, name, 32)         set_hudmessage(10, 255, 10, 0.5, 0.55, 0, 6.0, 0.1)         show_hudmessage(id, "Players name: %s", name)     } }

trehmilou 11-28-2006 09:06

Re: [Help] Aim @player shows total kills?
 
Thx for helping me guys :)

- I'll make the body variable global. Won't that get inconsistent values as I point at several players? Recreating the value every time was the secure way
- I get the kill value from rank stats. Every round start the rank seems to update, so that works good so far
- Is there any other way to update the kill display, but still using rank stats? Cuz now the kills only update every round start.

I dunno know why but somehow the kill values are shown correctly for each player now. I just deleted the csstats.dat file and now everything works fine? LOL

dutchmeat 11-28-2006 09:42

Re: [Help] Aim @player shows total kills?
 
You could count the kills youself, like i did on esf:

Code:
new kills[33] public Kills(msg_id, msg_dest, msg_entity){ //Count the kills new killer = get_msg_arg_int(1) new victim = get_msg_arg_int(2) if(killer == 0 || killer == victim || killer > 32) //first argument is the killer, 0 if worldspawn           return PLUGIN_HANDLED   kills[killer]++ //we count all the kills made return PLUGIN_CONTINUE }

stupok 11-28-2006 17:07

Re: [Help] Aim @player shows total kills?
 
The reason I would make the body variable global is because you don't ever make use of the data stored in that variable. If you do use that data elsewhere in the plugin, don't make it global. It's not a big deal either way, just a slight optimization.

With dutchmeat's example, hook onto the DeathMsg event.

dutchmeat 11-29-2006 06:15

Re: [Help] Aim @player shows total kills?
 
sorry, i forgot,

Code:

register_message(get_user_msgid("DeathMsg"), "Kills")

trehmilou 12-01-2006 09:46

Re: [Help] Aim @player shows total kills?
 
Ah thx dutchmeat i'll try that. :)


All times are GMT -4. The time now is 06:56.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.