AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Armor drop plug-in problem. (https://forums.alliedmods.net/showthread.php?t=62928)

sQn 11-07-2007 16:34

Armor drop plug-in problem.
 
Hi. In order to at bringing up (coming up) vest listen sound tr_kelvar.wav

Code
PHP Code:

/*
 * Title:
 *  CS Armor Drop (on death)
 *
 * Summary:
 *  When a player dies, if they have armor, they will drop their armor on the ground next to their corpse.
 *   A player can then walk over it and pick it up, letting them get a "percentage" of the armor left behind.
 *  Also, the player will recieve the same armor type as what they picked up.
 *  All armor will be deleted when round ends. Or on specified time (see cvars).
 *
 * Cvars:  
 *   armor_pct - (Default 20%) This is percentage of armor that will be received when its picked up.
 *   armor_max - (Default 100) This is the max amount of armor a user can get from picking up.  
 *   armor_min - (Default 15)  Minimum armor needed, for player to drop when killed.
 *   armor_removetime - (Default 2min) Time before armor is removed from map (unless round ends).
 *
 *
 * Requires : AMXX 1.60
 * Modules : Engine, FakeMeta
 * Tested : Win32 (Linux untested)
 *
 * Author:  OneEyed
 * Version: 1.1
 *
 * Thanks : ccnncc99, sXy-Schreck, phear of rice, and Aunt Friggin' Connie, 
 *   For helping me test and fix this plugin!
 *
 *
 * - Change Log:
 *  -v1.1 
 *  - Fixed to work on AMXX 1.60
 *  - Added "Armor Drop" CVAR for queries to pick up.
 */
#include <amxmodx>
#include <engine>
#include <fakemeta>
//---------------These values are default, they are added to the CVAR's---------------------
//---------------Change if you want these to be defaulted to the CVAR on SERVER RESTART-----
//----------------------------------------------------------------------
//This is percentage, if its 25, only 25% of dropped armor will be given.
#define ARMOR_TAX "50"
//----------------------------------------------------------------------
// MAX armor allowed, default = 100 (Set higher, if you want players to go over 100 armor.)
#define MAXARMOR "100"
//----------------------------------------------------------------------
// Minimum armor needed for armor to drop when player dies.
#define MINARMOR "35"
//----------------------------------------------------------------------
// Time before Armor is removed from the map in seconds (unless round ends) default=2mins
#define REMOVE_TIME "180"
//----------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-----------------------------------DO NOT EDIT BELOW THIS LINE-----------------------------------------------
//-------------------------------------------------------------------------------------------------------------
#define KEVLAR   1
#define VESTHELM  2
#define ARMORTYPE_OFFSET 112
#define TITLE "Armor Drop"
#define VERSION "1.0"
#define AUTHOR "OneEyed"
new g_ArmorType[33], Float:g_ArmorAmount[33], fArmor[33]
//Change this if you want a custom kevlar model
new armormodel[] = "models/new/w_kevlar.mdl"
new armorsound[] = "sound/items/tr_kevlar.wav"
new Float:multiplier
//-------------------------------------------------------------------------------------------------------------
public plugin_precache()
{
 
precache_model(armormodel)
 
precache_sound(armorsound)
 
}
//-------------------------------------------------------------------------------------------------------------
public plugin_init() {
 
register_plugin(TITLEVERSIONAUTHOR)
 
register_cvar(TITLE,VERSION,FCVAR_SERVER)
 
 if(!
cvar_exists("armor_pct"))
  
register_cvar("armor_pct",ARMOR_TAX)
 if(!
cvar_exists("armor_max"))
  
register_cvar("armor_max",MINARMOR)
 if(!
cvar_exists("armor_min"))
  
register_cvar("armor_min",MINARMOR)
 if(!
cvar_exists("armor_removetime"))
  
register_cvar("armor_removetime",REMOVE_TIME)
  
 
register_touch("FakeArmor","player","grabArmor")
 
 
register_event("DeathMsg","createArmor","a")
 
register_event"SendAudio""EndRound""a""2=%!MRAD_terwin""2=%!MRAD_ctwin""2=%!MRAD_rounddraw" )
}
//-------------------------------------------------------------------------------------------------------------
//-----------Delayed it to be right at the end, (doesnt work if i try to erase it on Round Start)--------------
public EndRound()
 
set_task(5.0,"removeArmor",1111)
public 
removeArmor() {
 new 
tempid = -1
 
while ( ( tempid find_ent_by_class(tempid"FakeArmor") ) > 0)
  if(
is_valid_ent(tempid)) {
   
remove_entity(tempid)
   
remove_task(tempid)
  }
 return 
PLUGIN_CONTINUE
}
//-------------------------------------------------------------------------------------------------------------
// Set task to this to remove the armor after specified amount of time. (armor_removetime)
public removeThisArmor(id)
 if(
is_valid_ent(id))
  
remove_entity(id)
//-------------------------------------------------------------------------------------------------------------
public grabArmor(pToucherpTouched) {
 if(
is_user_alive(pTouched) && is_user_connected(pTouched) && entity_get_float(pTouched,EV_FL_armorvalue) < float(get_cvar_num("armor_max"))) {
  new 
owner entity_get_int(pToucherEV_INT_iuser1)
  if(
is_valid_ent(fArmor[owner])) {
   
get_armor_values(pTouched)
   
multiplier float(get_cvar_num("armor_pct")) * 0.01
   
   
//Retrieve armor values left on the dropped kevlar
   
new armortype entity_get_int(fArmor[owner], EV_INT_iuser3)
   new 
armoramt entity_get_int(fArmor[owner], EV_INT_iuser4)
   
   
//Set armor accordingly to how player has theirs, and what type they grab.
   
if(g_ArmorType[pTouched] == 0
    
csset_user_armor(pTouchedarmoramt*multiplier, (armortype==1?KEVLAR:VESTHELM)), emit_sound(0CHAN_AUTOarmorsound1.0ATTN_NORM0PITCH_NORM
   else if(
g_ArmorType[pTouched] == && armortype == 1
    
csset_user_armor(pTouchedentity_get_float(pTouched,EV_FL_armorvalue)+(armoramt*multiplier), KEVLAR), emit_sound(0CHAN_AUTOarmorsound1.0ATTN_NORM0PITCH_NORM
   else if((
g_ArmorType[pTouched] == && armortype == 2) || g_ArmorType[pTouched] == 2
    
csset_user_armor(pTouchedentity_get_float(pTouched,EV_FL_armorvalue)+(armoramt*multiplier), VESTHELM), emit_sound(0CHAN_AUTOarmorsound1.0ATTN_NORM0PITCH_NORM
   
   
// If their armor goes over MAXARMOR set it to MAXARMOR
   
if(entity_get_float(pTouched,EV_FL_armorvalue) > float(get_cvar_num("armor_max")))
    
entity_set_float(pTouched,EV_FL_armorvaluefloat(get_cvar_num("armor_max")))
   
g_ArmorType[pTouched] = armortype
   remove_entity
(fArmor[owner])
   
remove_task(fArmor[owner])
  }
 }
 return 
PLUGIN_HANDLED
}
//-------------------------------------------------------------------------------------------------------------
public createArmor(id) {
 new 
victim read_data(2//grab user ID who died
 
 
get_armor_values(victim)
 
 if(
g_ArmorType[victim] <= || g_ArmorAmount[victim] <= float(get_cvar_num("armor_min")))
  return 
PLUGIN_CONTINUE
 
new origin[3]
 new 
Float:fOrigin[3]
 
get_user_origin(victim,origin)
 for(new 
a=0;a<3;a++)
  
fOrigin[a]=float(origin[a])
 
fArmor[victim] = create_entity("info_target")
 if(
fArmor[victim]) {
  
entity_set_string(fArmor[victim],EV_SZ_classname,"FakeArmor")
  
entity_set_model(fArmor[victim], armormodel)
  
  new 
Float:MinBox[3]
  new 
Float:MaxBox[3]
  
MinBox[0] = -6.0
  MinBox
[1] = -8.0
  MinBox
[2] = -1.5
  MaxBox
[0] = 6.0
  MaxBox
[1] = 8.0
  MaxBox
[2] = 1.5
  
  entity_set_vector
(fArmor[victim], EV_VEC_minsMinBox)
  
entity_set_vector(fArmor[victim], EV_VEC_maxsMaxBox)
  
  
entity_set_int(fArmor[victim], EV_INT_solidSOLID_BBOX
  
entity_set_int(fArmor[victim], EV_INT_movetypeMOVETYPE_TOSS)
  
  
// Sets iuser1 to victim ID
  
entity_set_int(fArmor[victim], EV_INT_iuser1victim)
  
// Sets iuser3 to Armor Type (kevlar of vest+helm)
  
entity_set_int(fArmor[victim], EV_INT_iuser3g_ArmorType[victim])
  
// Sets iuser4 to Armor Value (amount victim had when he died)
  
entity_set_int(fArmor[victim], EV_INT_iuser4floatround(g_ArmorAmount[victim]))
  
entity_set_origin(fArmor[victim], fOrigin)
  
set_task(float(get_cvar_num("armor_removetime")),"removeThisArmor",fArmor[victim])
 }
 return 
PLUGIN_HANDLED
}
//-------------------------------------------------------------------------------------------------------------
public get_armor_values(id) {
 if(
entity_get_float(id,EV_FL_armorvalue) <= 0.0)
  
g_ArmorType[id] = 0
 
else {
  
g_ArmorAmount[id] = entity_get_float(id,EV_FL_armorvalue)
  
g_ArmorType[id] = get_pdata_int(id,ARMORTYPE_OFFSET)
 } 
}
//-------------------------------------------------------------------------------------------------------------
//Cstrike.inc has this function, but its broken, so i made my own that works =).
public csset_user_armor(idFloat:amounttype) {
 
entity_set_float(id,EV_FL_armorvalueamount)
 
set_pdata_int(id,ARMORTYPE_OFFSET,type
}
//------------------------------------------------------------------------------------------------------------- 


sQn 11-07-2007 16:35

Re: Armor drop plug-in problem.
 
I easy compine this plug-in :)

Wilson [29th ID] 11-07-2007 17:53

Re: Armor drop plug-in problem.
 
Probably

sQn 11-08-2007 06:09

Re: Armor drop plug-in problem.
 
Fix my plug-in and send me fixed code. :mrgreen:

Wilson [29th ID] 11-08-2007 09:22

Re: Armor drop plug-in problem.
 
sQn.

No one knows what you said in the first two posts.
You should say what is wrong with the plugin, and paste the errors you are getting.

sQn 11-08-2007 11:34

Re: Armor drop plug-in problem.
 
I wont listen sound tr_kelvar.wav when bringing up armour.This plug-in doesn't work [I don't listen sound when i bring up armour].

ConnorMcLeod 11-08-2007 12:54

Re: Armor drop plug-in problem.
 
Try this :
PHP Code:

/*
 * Title:
 *  CS Armor Drop (on death)
 *
 * Summary:
 *  When a player dies, if they have armor, they will drop their armor on the ground next to their corpse.
 *   A player can then walk over it and pick it up, letting them get a "percentage" of the armor left behind.
 *  Also, the player will recieve the same armor type as what they picked up.
 *  All armor will be deleted when round ends. Or on specified time (see cvars).
 *
 * Cvars:  
 *   armor_pct - (Default 20%) This is percentage of armor that will be received when its picked up.
 *   armor_max - (Default 100) This is the max amount of armor a user can get from picking up.  
 *   armor_min - (Default 15)  Minimum armor needed, for player to drop when killed.
 *   armor_removetime - (Default 2min) Time before armor is removed from map (unless round ends).
 *
 *
 * Requires : AMXX 1.60
 * Modules : Engine, FakeMeta
 * Tested : Win32 (Linux untested)
 *
 * Author:  OneEyed
 * Version: 1.1
 *
 * Thanks : ccnncc99, sXy-Schreck, phear of rice, and Aunt Friggin' Connie, 
 *   For helping me test and fix this plugin!
 *
 *
 * - Change Log:
 *  -v1.1 
 *  - Fixed to work on AMXX 1.60
 *  - Added "Armor Drop" CVAR for queries to pick up.
 */
#include <amxmodx>
#include <engine>
#include <fakemeta>
//---------------These values are default, they are added to the CVAR's---------------------
//---------------Change if you want these to be defaulted to the CVAR on SERVER RESTART-----
//----------------------------------------------------------------------
//This is percentage, if its 25, only 25% of dropped armor will be given.
#define ARMOR_TAX "50"
//----------------------------------------------------------------------
// MAX armor allowed, default = 100 (Set higher, if you want players to go over 100 armor.)
#define MAXARMOR "100"
//----------------------------------------------------------------------
// Minimum armor needed for armor to drop when player dies.
#define MINARMOR "35"
//----------------------------------------------------------------------
// Time before Armor is removed from the map in seconds (unless round ends) default=2mins
#define REMOVE_TIME "180"
//----------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-----------------------------------DO NOT EDIT BELOW THIS LINE-----------------------------------------------
//-------------------------------------------------------------------------------------------------------------
#define KEVLAR   1
#define VESTHELM  2
#define ARMORTYPE_OFFSET 112
#define TITLE "Armor Drop"
#define VERSION "1.0"
#define AUTHOR "OneEyed"
new g_ArmorType[33], Float:g_ArmorAmount[33], fArmor[33]
//Change this if you want a custom kevlar model
new const armormodel[] = "models/new/w_kevlar.mdl"
new const armorsound[] = "items/tr_kevlar.wav"
new Float:multiplier
//-------------------------------------------------------------------------------------------------------------
public plugin_precache()
{
 
precache_model(armormodel)
 
precache_sound(armorsound)
 
}
//-------------------------------------------------------------------------------------------------------------
public plugin_init() {
 
register_plugin(TITLEVERSIONAUTHOR)
 
register_cvar(TITLE,VERSION,FCVAR_SERVER)
 
 if(!
cvar_exists("armor_pct"))
  
register_cvar("armor_pct",ARMOR_TAX)
 if(!
cvar_exists("armor_max"))
  
register_cvar("armor_max",MINARMOR)
 if(!
cvar_exists("armor_min"))
  
register_cvar("armor_min",MINARMOR)
 if(!
cvar_exists("armor_removetime"))
  
register_cvar("armor_removetime",REMOVE_TIME)
  
 
register_touch("FakeArmor","player","grabArmor")
 
 
register_event("DeathMsg","createArmor","a")
 
register_event"SendAudio""EndRound""a""2=%!MRAD_terwin""2=%!MRAD_ctwin""2=%!MRAD_rounddraw" )
}
//-------------------------------------------------------------------------------------------------------------
//-----------Delayed it to be right at the end, (doesnt work if i try to erase it on Round Start)--------------
public EndRound()
 
set_task(5.0,"removeArmor",1111)
public 
removeArmor() {
 new 
tempid = -1
 
while ( ( tempid find_ent_by_class(tempid"FakeArmor") ) > 0)
  if(
is_valid_ent(tempid)) {
   
remove_entity(tempid)
   
remove_task(tempid)
  }
 return 
PLUGIN_CONTINUE
}
//-------------------------------------------------------------------------------------------------------------
// Set task to this to remove the armor after specified amount of time. (armor_removetime)
public removeThisArmor(id)
 if(
is_valid_ent(id))
  
remove_entity(id)
//-------------------------------------------------------------------------------------------------------------
public grabArmor(pToucherpTouched) {
 if(
is_user_alive(pTouched) && is_user_connected(pTouched) && entity_get_float(pTouched,EV_FL_armorvalue) < float(get_cvar_num("armor_max"))) {
  new 
owner entity_get_int(pToucherEV_INT_iuser1)
  if(
is_valid_ent(fArmor[owner])) {
   
get_armor_values(pTouched)
   
multiplier float(get_cvar_num("armor_pct")) * 0.01
   
   
//Retrieve armor values left on the dropped kevlar
   
new armortype entity_get_int(fArmor[owner], EV_INT_iuser3)
   new 
armoramt entity_get_int(fArmor[owner], EV_INT_iuser4)
   
   
//Set armor accordingly to how player has theirs, and what type they grab.
   
if(g_ArmorType[pTouched] == 0)
   {
    
csset_user_armor(pTouchedarmoramt*multiplier, (armortype==1?KEVLAR:VESTHELM))
    
emit_sound(pTouchedCHAN_ITEMarmorsound1.0ATTN_NORM0PITCH_NORM
   }
   else if(
g_ArmorType[pTouched] == && armortype == 1)
   { 
    
csset_user_armor(pTouchedentity_get_float(pTouched,EV_FL_armorvalue)+(armoramt*multiplier), KEVLAR)
    
emit_sound(pTouchedCHAN_ITEMarmorsound1.0ATTN_NORM0PITCH_NORM
   }
   else if((
g_ArmorType[pTouched] == && armortype == 2) || g_ArmorType[pTouched] == 2
   {
    
csset_user_armor(pTouchedentity_get_float(pTouched,EV_FL_armorvalue)+(armoramt*multiplier), VESTHELM)
    
emit_sound(pTouchedCHAN_ITEMarmorsound1.0ATTN_NORM0PITCH_NORM
   }   
   
// If their armor goes over MAXARMOR set it to MAXARMOR
   
if(entity_get_float(pTouched,EV_FL_armorvalue) > float(get_cvar_num("armor_max")))
    
entity_set_float(pTouched,EV_FL_armorvaluefloat(get_cvar_num("armor_max")))
   
g_ArmorType[pTouched] = armortype
   remove_entity
(fArmor[owner])
   
remove_task(fArmor[owner])
  }
 }
 return 
PLUGIN_HANDLED
}
//-------------------------------------------------------------------------------------------------------------
public createArmor(id) {
 new 
victim read_data(2//grab user ID who died
 
 
get_armor_values(victim)
 
 if(
g_ArmorType[victim] <= || g_ArmorAmount[victim] <= float(get_cvar_num("armor_min")))
  return 
PLUGIN_CONTINUE
 
new origin[3]
 new 
Float:fOrigin[3]
 
get_user_origin(victim,origin)
 for(new 
a=0;a<3;a++)
  
fOrigin[a]=float(origin[a])
 
fArmor[victim] = create_entity("info_target")
 if(
fArmor[victim]) {
  
entity_set_string(fArmor[victim],EV_SZ_classname,"FakeArmor")
  
entity_set_model(fArmor[victim], armormodel)
  
  new 
Float:MinBox[3]
  new 
Float:MaxBox[3]
  
MinBox[0] = -6.0
  MinBox
[1] = -8.0
  MinBox
[2] = -1.5
  MaxBox
[0] = 6.0
  MaxBox
[1] = 8.0
  MaxBox
[2] = 1.5
  
  entity_set_vector
(fArmor[victim], EV_VEC_minsMinBox)
  
entity_set_vector(fArmor[victim], EV_VEC_maxsMaxBox)
  
  
entity_set_int(fArmor[victim], EV_INT_solidSOLID_BBOX
  
entity_set_int(fArmor[victim], EV_INT_movetypeMOVETYPE_TOSS)
  
  
// Sets iuser1 to victim ID
  
entity_set_int(fArmor[victim], EV_INT_iuser1victim)
  
// Sets iuser3 to Armor Type (kevlar of vest+helm)
  
entity_set_int(fArmor[victim], EV_INT_iuser3g_ArmorType[victim])
  
// Sets iuser4 to Armor Value (amount victim had when he died)
  
entity_set_int(fArmor[victim], EV_INT_iuser4floatround(g_ArmorAmount[victim]))
  
entity_set_origin(fArmor[victim], fOrigin)
  
set_task(float(get_cvar_num("armor_removetime")),"removeThisArmor",fArmor[victim])
 }
 return 
PLUGIN_HANDLED
}
//-------------------------------------------------------------------------------------------------------------
public get_armor_values(id) {
 if(
entity_get_float(id,EV_FL_armorvalue) <= 0.0)
  
g_ArmorType[id] = 0
 
else {
  
g_ArmorAmount[id] = entity_get_float(id,EV_FL_armorvalue)
  
g_ArmorType[id] = get_pdata_int(id,ARMORTYPE_OFFSET)
 } 
}
//-------------------------------------------------------------------------------------------------------------
//Cstrike.inc has this function, but its broken, so i made my own that works =).
public csset_user_armor(idFloat:amounttype) {
 
entity_set_float(id,EV_FL_armorvalueamount)
 
set_pdata_int(id,ARMORTYPE_OFFSET,type
}
//------------------------------------------------------------------------------------------------------------- 


[ --<-@ ] Black Rose 11-08-2007 13:40

Re: Armor drop plug-in problem.
 
emit_sound(id, CHAN_ITEM, "items/ammopickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);

sQn 11-08-2007 15:13

Re: Armor drop plug-in problem.
 
This doesn't work.I don't listen sound.

ConnorMcLeod 11-08-2007 17:05

Re: Armor drop plug-in problem.
 
edited with CHAN_ITEM instead of CHAN_AUTO, test again :)


All times are GMT -4. The time now is 01:15.

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