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

[SOLVED][CS:S][smlib] Clip and ammo function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zack771
Senior Member
Join Date: Apr 2012
Old 04-18-2014 , 12:26   [SOLVED][CS:S][smlib] Clip and ammo function
Reply With Quote #1

Hi,

(sorry for bad english)

I just discovered the smlib libraries (what an awesome thing !), but i don't know how to use certain function to do what i want.

I want to make a turn by turn shot : the terrorist shoot (is deagle is now empty with no ammo), then the ct shoot (same thing), etc and this end when one of the two people die.

So i've tried that :
PHP Code:

public OnPluginStart()
{
    
HookEvent("weapon_fire",WeaponFire);
}

public 
WeaponFire(Handle:event, const String:name[], bool:dontBroadcast) {
    new 
client GetClientOfUserId(GetEventInt(event,"userid"));
    
decl String:weaponFire[32];
    
GetEventString(event,"weapon",weaponFire,sizeof(weaponFire));
    if(
StrEqual(weaponFire,"deagle")) {
       if(
turn==Terro) {
          
Client_SetWeaponAmmo(Terro,"weapon_deagle",0,0,1,0);
          
Client_SetWeaponAmmo(CT,"weapon_deagle",0,0,0,0);
          
turn=CT;
    } else if(
turnRoulette==CT) {
       
Client_SetWeaponAmmo(Terro,"weapon_deagle",0,0,0,0);
       
Client_SetWeaponAmmo(CT,"weapon_deagle",0,0,1,0);
       
turn=Terro;
   }
}
//turn is initiated with turn=Terro in another part of the code 
But it doesn't work : the two people always have 1 bullet in clip and ready to shot, and when they shot it makes no damage.

Does somebody have any idea why it doesn't work please ?
__________________
"Embrace your dreams, and whatever happend protect your honor"
Zack Fair

Last edited by Zack771; 04-25-2014 at 06:15. Reason: Solved subject.
Zack771 is offline
Internet Bully
Member
Join Date: Apr 2014
Old 04-18-2014 , 12:57   Re: [CS:S][smlib] Clip and ammo function
Reply With Quote #2

You're hooking fire, and never returning it, so it never finished shooting.

Try adding "return Plugin_Continue;" at the end of your weaponfire event.

Quote:
  • Plugin_Continue - The original server command will be processed, if there was one. If the server command was created by a plugin, this has no effect.
  • Plugin_Handled - The original server command will not be processed, if there was one. If the server command was created by a plugin, this has no effect.
  • Plugin_Stop - The original server command will not be processed, if there was one. Additionally, no further hooks will be called for this command until it is fired again.

Last edited by Internet Bully; 04-18-2014 at 13:03.
Internet Bully is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-18-2014 , 13:02   Re: [CS:S][smlib] Clip and ammo function
Reply With Quote #3

Quote:
Originally Posted by Internet Bully View Post
You're hooking fire, and never returning it, so it never finished shooting.

Try adding "Plugin_Continue;" at the end of your weaponfire event.
You can't block shooting with events. And events appear late/after player action.
Bacardi is offline
Internet Bully
Member
Join Date: Apr 2014
Old 04-18-2014 , 13:23   Re: [CS:S][smlib] Clip and ammo function
Reply With Quote #4

You could try swapping the event you're hooking.

https://forums.alliedmods.net/showthread.php?t=138332

Though the bullet_impact event will be called if it travels through a surface or anything.

Last edited by Internet Bully; 04-18-2014 at 13:26.
Internet Bully is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 04-18-2014 , 15:07   Re: [CS:S][smlib] Clip and ammo function
Reply With Quote #5

Code:
HookEvent("weapon_fire",WeaponFire);

public WeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event,"userid"));
	decl String:weaponFire[32];
	GetEventString(event,"weapon",weaponFire,sizeof(weaponFire));
	if(StrEqual(weaponFire,"deagle"))
	{
		if(turn==Terro)
		{
			Client_SetWeaponAmmo(Terro,"weapon_deagle",0,0,1,0);
			turn = CT;
		}
		else
		{
			Client_SetWeaponAmmo(CT,"weapon_deagle",0,0,1,0);
			turn = Terro;
		}
	}
	return Plugin_Continue
}
Not much of a need to set ammo to 0 if both clients have only 1 bullet in the first place. They fire it, give enemy 1 bullet and so on.

- Jack

Last edited by Drixevel; 04-18-2014 at 15:07.
Drixevel is offline
Zack771
Senior Member
Join Date: Apr 2012
Old 04-18-2014 , 18:00   Re: [CS:S][smlib] Clip and ammo function
Reply With Quote #6

Quote:
Originally Posted by Internet Bully View Post
You're hooking fire, and never returning it, so it never finished shooting.

Try adding "return Plugin_Continue;" at the end of your weaponfire event.
But hooking doesn't need to always return something ? (I've got other hook that doesn't return anything and work really good).
But i'm gonna try this.

Quote:
Originally Posted by Internet Bully View Post
You could try swapping the event you're hooking.

https://forums.alliedmods.net/showthread.php?t=138332

Though the bullet_impact event will be called if it travels through a surface or anything.
But the weapon_fire (Post) is good too, isn't it ? I'll try to "return Plugin_Continue;" first and i feedback the result.

Quote:
Originally Posted by r3dw3r3w0lf View Post
Code:
HookEvent("weapon_fire",WeaponFire);

public WeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(event,"userid"));
    decl String:weaponFire[32];
    GetEventString(event,"weapon",weaponFire,sizeof(weaponFire));
    if(StrEqual(weaponFire,"deagle"))
    {
        if(turn==Terro)
        {
            Client_SetWeaponAmmo(Terro,"weapon_deagle",0,0,1,0);
            turn = CT;
        }
        else
        {
            Client_SetWeaponAmmo(CT,"weapon_deagle",0,0,1,0);
            turn = Terro;
        }
    }
    return Plugin_Continue
}
Not much of a need to set ammo to 0 if both clients have only 1 bullet in the first place. They fire it, give enemy 1 bullet and so on.

- Jack
Yeah, thanks for tip
__________________
"Embrace your dreams, and whatever happend protect your honor"
Zack Fair
Zack771 is offline
Zack771
Senior Member
Join Date: Apr 2012
Old 04-22-2014 , 20:01   Re: [CS:S][smlib] Clip and ammo function
Reply With Quote #7

Feedback : Doesn't work. The 2 players have only 1 shot, then no bullet spawn in the deagle.
__________________
"Embrace your dreams, and whatever happend protect your honor"
Zack Fair

Last edited by Zack771; 04-22-2014 at 20:01.
Zack771 is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 04-22-2014 , 22:09   Re: [CS:S][smlib] Clip and ammo function
Reply With Quote #8

Quote:
Originally Posted by Zack771 View Post
Feedback : Doesn't work. The 2 players have only 1 shot, then no bullet spawn in the deagle.
Not sure how your bools are setup but if you set both guns to 1 bullet each, they fire then they don't have a bullet so you should just give a new bullet to someone who needs to shoot next. You could also just remove all ammo then give them both 1 bullet each per turn and do that instead.

- Jack
Drixevel is offline
Zack771
Senior Member
Join Date: Apr 2012
Old 04-23-2014 , 09:32   Re: [CS:S][smlib] Clip and ammo function
Reply With Quote #9

Quote:
Originally Posted by r3dw3r3w0lf View Post
Not sure how your bools are setup but if you set both guns to 1 bullet each, they fire then they don't have a bullet so you should just give a new bullet to someone who needs to shoot next.
But here it's made to change turn every time a player shoot :
PHP Code:
public Action:WeaponFire(Handle:event, const String:name[], bool:dontBroadcast) {
    new 
client GetClientOfUserId(GetEventInt(event,"userid"));
    
decl String:weaponFire[32];
    
GetEventString(event,"weapon",weaponFire,sizeof(weaponFire));
    if(
good) {
        
//some if and else if
        
else if(StrEqual(dvName,"roulette") && StrEqual(weaponFire,"deagle")) {
            if(
turn==Terro) {
                
Client_SetWeaponAmmo(Terro,"weapon_deagle",0,0,1,0);
                
turn=CT;
                return 
Plugin_Continue;
            } else {
                
Client_SetWeaponAmmo(CT,"weapon_deagle",0,0,1,0);
                
turn=Terro;
                return 
Plugin_Continue;
            }
        }
    }
    return 
Plugin_Continue;

So every time the terro or the CT fire the weapon, it should give one bullet to the good person. But it doesn't give.
Maybe i've made some errors but i don't see them.

Quote:
Originally Posted by r3dw3r3w0lf View Post
You could also just remove all ammo then give them both 1 bullet each per turn and do that instead.
- Jack
It's what i'm actually doing, when a player shoot he have no bullet anymore, then the other player got 1 bullet.
__________________
"Embrace your dreams, and whatever happend protect your honor"
Zack Fair

Last edited by Zack771; 04-23-2014 at 09:33.
Zack771 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 04-23-2014 , 11:04   Re: [CS:S][smlib] Clip and ammo function
Reply With Quote #10

yikes, you have a random else if inside of an if loop...
PHP Code:
public Action:WeaponFire(Handle:event, const String:name[], bool:dontBroadcast) {
    if(
good) { //wtf is 'good'?
        
new client GetClientOfUserId(GetEventInt(event,"userid"));
        
decl String:weaponFire[32]; //since you dont need the variable till after the 'good' check.
        
GetEventString(event,"weapon",weaponFire,sizeof(weaponFire));
        if(
StrEqual(dvName,"roulette") && StrEqual(weaponFire,"deagle")) {
            if(
turn==Terro) { //let's just hope you are setting Terro to the client index...
                
Client_SetWeaponAmmo(Terro,"weapon_deagle",0,0,1,0);
                
turn=CT;
            } else {
                
Client_SetWeaponAmmo(CT,"weapon_deagle",0,0,1,0);
                
turn=Terro;
            }
        }
    }
    return 
Plugin_Continue;

Mitchell 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 09:12.


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