Raised This Month: $51 Target: $400
 12% 

Simple code what start count headshot [Help]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-24-2010 , 14:30   Simple code what start count headshot [Help]
Reply With Quote #1

First for all, I have not experience coding php, c#, java or similiar...
I'm noob about these.

I started recently practise this try-out mind. (Sorry for bad english)

I've managed so far create like this. (Game Cs:s)

- Hook event when player die
- Get headshot "singal" value, 1/0
- Print Headshot value (or text) in attacker chat
- Print text in chat if headshot event trigged/true

PHP Code:
#include <sourcemod>

public OnPluginStart()
{
    
HookEvent("player_death"Event_PlayerDeath)
}


public 
Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"))
    new 
bool:headshot GetEventBool(event"headshot"//bool give true/false values ??
    //new headshot = GetEventInt(event, "headshot") //Work also 1/0
    //PrintToChat(attacker, "Headshot kill %d", headshot) //I see results in my chat when event fired

    
if(headshot == true//bool:headshot true/false
    
{
        
PrintToChat(attacker"Headshot Kill!")
    }

But now I want add more code so it will start count headshots...
That it will print headshot count in chat, every time when attacker get headshot kill.
1
2
3
4
5 etc. etc.
(not have to reset headshot count at all yet, simply things first )

http://wiki.alliedmods.net/Introduction_to_SourcePawn

So what I have read and understood someway.
I need create Variables to save headshot 1 counts and someway point of code use Increment(++)...
- Problem to get value (true/false or 1/0) to code and start increase value.


But this far I'm lost what to do

If someone helpful could show me example ?
Bacardi is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 04-24-2010 , 15:17   Re: Simple code what start count headshot [Help]
Reply With Quote #2

PHP Code:
#include <sourcemod>

new g_Headshots[MAXPLAYERS+1];

public 
OnPluginStart() {
    
HookEvent("player_death"Event_PlayerDeath);
}


public 
Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast) {

    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    new 
bool:headshot GetEventBool(event"headshot");

    if(
headshot == true) {
        
g_Headshots[attacker]++;
        
PrintToChat(attacker"Headshot number %d!"g_Headshots[attacker]);
    }

Then just set it to zero every time someone connects.

(Btw, semicolons are generally good practice, I've added them above)
__________________
Scone is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-24-2010 , 15:37   Re: Simple code what start count headshot [Help]
Reply With Quote #3

Ok have to try tomorrow, and practice..
Thanks
Bacardi is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-27-2010 , 12:22   Re: Simple code what start count headshot [Help]
Reply With Quote #4

Ok, I want to know, how do I get userid/player index inside code block {} to use in other code block ?
Or how to say, do I have create publick variable ("userid")?

example I take event round_end.
There (not sure) can't get userid.. I only get Team index. T - 2 and CT - 3.
So can I some how "borrow" same variable from other code block.
example take from:
public Event_PlayerDeath { attacker } and use it in public Event_RoundEnd but how ?

Or do I have create new client_id = GetSomeHowClientId(where, "?") ??

Also can this done other variables(value) ? "How do this" maybe better question.


But about this code now, I change little bit for testing purpose and learning.
- I get it print in chat if headshot kill true + or false - and will increase/decrease headshot count.
- I do get work, print on chat headshot amount when player_spawn
- Problem what I want to know How do I get same message round_end ??
("Round End, statistics headshot-kills %d !")

PHP Code:
#include <sourcemod>

new g_Headshots[MAXPLAYERS+1];

public 
OnPluginStart()
{
    
HookEvent("player_death"Event_PlayerDeath);
    
//HookEvent("player_spawn", Event_PlayerSpawn);
    
HookEvent("round_end"Event_RoundEnd);
}

public 
Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{

    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    new 
bool:headshot GetEventBool(event"headshot");

    if(
headshot == true)
    {
        
g_Headshots[attacker]++;
        
PrintToChat(attacker"Headshot +");

    }
    else if(
headshot == false)
    {
        
g_Headshots[attacker]--;
        
PrintToChat(attacker"Headshot -");
    }

    
//PrintToChat(attacker, "Headshot number %d!", g_Headshots[attacker]); // Can keep trace headshot count
}

//public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
//{
//    new client = GetClientOfUserId(GetEventInt(event, "userid"));
//    
//    if(client)
//    {
//        //g_Headshots[client];
//        PrintToChat(client, "Player Spawn, statistics headshot-kills %d !", g_Headshots[client]);
//    }
//}

public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    
//What in here ? How do I get here client/userid/player index ??
    // round_end event have:
    //byte          winner         winner team/user id
    //But I get only team index T - 2, CT -3

    
PrintToChat(client_id"Round End, statistics headshot-kills %d !"g_Headshots[client_id]);
}

public 
bool:OnClientConnect(client//Reset headshot count after map change or re-connect
{
    
g_Headshots[client] = 0;
    return 
true//true allow player connect, false or empty disconenct player immediatelly

PS: Is Headshots reset right ? Anyway it's work.
apologize stupid questions what I have made. heha
Bacardi is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 04-27-2010 , 12:38   Re: Simple code what start count headshot [Help]
Reply With Quote #5

RoundEnd is presumably called once when the round ends, not once for each player like PlayerDeath.

So, you need to loop through all the possible clients individually:

PHP Code:
for(new client 1client <= MaxClientsclient++) {
    if(
IsClientConnected(client) && IsClientInGame(client)) {
        
PrintToChat(client"End of round - you performed %d headshot(s)"g_Headshots[client]);
    }

__________________
Scone is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 04-27-2010 , 12:42   Re: Simple code what start count headshot [Help]
Reply With Quote #6

Quote:
Originally Posted by Bacardi View Post
PS: Is Headshots reset right ? Anyway it's work.
apologize stupid questions what I have made. heha
Sorry, didn't see this before. Yes, it does seem to be reset correctly.
__________________
Scone is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:45.


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