PDA

View Full Version : terrorist can defuse


ÜnLoCo
06-13-2010, 09:09
hello
let's say i gave a terrorist a defuser kit
cs_set_user_defuse(id)

and then
RegisterHam(Ham_Use, "grenade", "C4Used")

what should i write after i know that the defuser is a terrorist

public C4Used(iC4, id, idactivator, use_type, Float:value)
{
if(use_type == 2 && value == 1.0 && get_user_team(id) == 1){
//plz help .. i want this terro to be able to defuse now. !
}
}

i'm writing this plugin so that a ct can pick up the dropped bomb and plant it.
then terrorists have to defuse it.
i have been able to prevent ct from defusing
if(use_type == 2 && value == 1.0 && get_user_team(id) == 2){
return HAM_SUPERCEED
}
but it got trickier when i wanted to allow a terrorist to defuse that c4 bomb.

help!

bibu
01-31-2011, 16:38
bump for this.

Lulu the hero
01-31-2011, 20:42
Quite a crazy idea. Wouldn't it be easier if you would switch all players team quietly with cs_set_user_team, while not changing their model? That way the cts could plant, and the ts could defuse. :)

Seriously try go around it. Check if the user, who wants to defuse is pressing the USE key( check in player pre think ) and pointing against the planted bomb entity( use get_user_aiming, because you can set the distance here ). If so, then start a "defuse progress" animation( you can find a good example for that in the zp_extra_lasermine plugin ). If the progress finished, then remove the bomb entity and force a round end, plus display a message in the center.
Simple! :mrgreen:

Edit:
Never mind the player pre think - pointing - using part. Your Ham function is better.

ConnorMcLeod
02-01-2011, 01:54
Tested and works.

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define VERSION "0.0.1"
#define PLUGIN "Terrorists Can Defuse"

new HamHook:g_ihHC4UsePost

#define XO_PLAYER 5
#define m_iTeam 114
#define TEAM_T 1
#define TEAM_CT 2

public plugin_init()
{
register_plugin(PLUGIN, VERSION, "ConnorMcLeod")
RegisterHam(Ham_Use, "grenade", "C4_Use")
DisableHamForward( g_ihHC4UsePost = RegisterHam(Ham_Use, "grenade", "C4_Use_Post", 1) )
}

public C4_Use(iC4, id, iActivator, use_type, Float:value)
{
if( use_type == 2 && value == 1.0 && get_pdata_int(id, m_iTeam, XO_PLAYER) == TEAM_T )
{
set_pdata_int(id, m_iTeam, TEAM_CT, XO_PLAYER)
EnableHamForward( g_ihHC4UsePost )
return HAM_HANDLED
}
return HAM_IGNORED
}

public C4_Use_Post(iC4, id)
{
set_pdata_int(id, m_iTeam, TEAM_T, XO_PLAYER)
DisableHamForward( g_ihHC4UsePost )
}

Arkshine
02-01-2011, 05:56
There is only 2 ways for that, either changing the team in pre/post like connor above, or blocking use as pre and rewrite all the code. Though changing the team all the time is really ugly.

bibu
02-02-2011, 12:43
Thanks connor, works perfectly, I just wanted to know what these stuff do:

get_pdata_int(id, m_iTeam, XO_PLAYER)
set_pdata_int(id, m_iTeam, TEAM_CT, XO_PLAYER)
set_pdata_int(id, m_iTeam, TEAM_T, XO_PLAYER)

I would say, it gets team, and the other both sets team. In this case, tell me if I am wrong, what's with cs_s(g)et_user_team ?

Arkshine
02-02-2011, 12:51
Both does the same, it uses a player's offset. Though, there is a difference about cs_set_user_team(), it set the team + send ClientUserInfoChanged + send TeamInfo message + pass the team name by reference.

In CC4::Use(), there is a check with the team offset to make sure you are in the CT team. So, all you need here is to set the offset with the CT team value (2), as pre, and restore as post. It does the trick. You don't need all the stuffs that does the cstrike native, that's why using the offset is enough.

bibu
02-02-2011, 14:28
Oh thanks, and how is get_pdata_int, I mean with cstrike you make == CS_TEAM_*

Arkshine
02-02-2011, 14:36
I don't understand what you ask.

bibu
02-02-2011, 14:55
I mean with cstrike, you get team by, cs_get_user_team(id) == CS_TEAM_* and with connors method I don't see how he can get the terror team.

Arkshine
02-02-2011, 15:06
cs_get_user_team uses the team offset (m_iTeam) to get the team index. (1 terro, 2 ct etc.. )

CS_TEAM_* are just defines to integer values. CS_TEAM_T = 1, CS_TEAM_CT = 2, etc.

Lulu the hero
02-02-2011, 20:24
Oh thanks, and how is get_pdata_int, I mean with cstrike you make == CS_TEAM_*

The offset is 114 for teams.

From ConnorMcLeod's get_user_team fix (https://forums.alliedmods.net/showthread.php?t=137996):
new team = get_pdata_int(id, 114, 5);
Where 5 is the linux offset difference.

bibu
02-03-2011, 06:34
Still I couldn't understand it, I would understand something like this more:

get_pdata_int(id, m_iTeam, XO_PLAYER == 1)

Arkshine
02-03-2011, 06:38
The player's offset m_iTeam has as value 114. Value from windows.

But for linux, you need to add +5, and generally for weapons, you need to add +4.

That's why you have a param in such native, it will add this value to the provided offset if you're running linux.

bibu
02-04-2011, 09:51
Looks like no one could understand me. However I didn't see it. I meant this:

get_pdata_int(id, m_iTeam, XO_PLAYER) == TEAM_T

I thought the code gets the wanted team just with get_pdata_int(id, m_iTeam, XO_PLAYER).

Arkshine
02-04-2011, 09:57
It gets the current player's team index like cs_get_user_team(). Both do the same.

bibu
02-04-2011, 10:28
Yep, thanks.