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

Random bomsite for de_dust2 and de_dust


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
VINAGHOST
Member
Join Date: Aug 2016
Location: Việt Nam
Old 09-07-2017 , 09:04   Random bomsite for de_dust2 and de_dust
Reply With Quote #1

I want to make random bomsite in every round when cvar bs_on is 1 and when admin turn it to 0 so everything back to normal.
This is my code ._.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>

#define PLUGIN "RANDOM BOMSITE"
#define VERSION "1.0"
#define AUTHOR "VINAGHOST"

new bomsite 0
new bomsite_id 0
new g_szCfgFile[128];
#define MIN_SIZE 180.0
#define ENTITY_CLASS "func_bomb_target"
#define TASK_RADAR 1
#define TASK_BOMBONRADAR_TIME 3.0
#define TASK_LOOK 2
new Array:g_BS;
new Array:
g_BSmaxs;
new Array:
g_BSmins;
new Array:
g_BSorigin;


new 
m_fakeHostagem_fakeHostageDie
new gbPlanted=false;
new 
bool:d_bs 
new bs_on

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("HLTV""newround""a""1=0""2=0")
    
register_event("BombDrop","bomb_planted","a","4=1");
    
    
    
bs_on register_cvar("bs_on""0")
    
    
register_clcmd("say /creat","rb_creat"ADMIN_BAN);
    
register_clcmd("say /save","rb_save"ADMIN_BAN);
    
    
    
m_fakeHostage get_user_msgid("HostagePos");
    
m_fakeHostageDie get_user_msgid("HostageK");
}
public 
plugin_cfg(){
    
get_configsdir(g_szCfgFile75);    
    new 
szMapName[32];
    
get_mapname(szMapName31);
    
    
format(g_szCfgFile127"%s/randomBS/%s.ini"g_szCfgFileszMapName);
    
    
g_BS ArrayCreate(12);
    
g_BSmaxs ArrayCreate(32);
    
g_BSmins ArrayCreate(32);
    
g_BSorigin ArrayCreate(32);
        
    
//BombSites
    
if(file_exists(g_szCfgFile)){
        
LoadFromFile();
        
    }
    else{
        
set_task(1.0"task_Look4BS"TASK_LOOK);
    }
    
    
d_bs true
}
public 
task_Look4BS(){
    new 
ent = -1;
    new 
Float:fMax[3], Float:fMin[3], Float:fOrigin[3];
    new 
Float:fMinS[3], Float:fMaxS[3];
    do{
        
ent find_ent_by_class entENTITY_CLASS);
        if(
is_valid_ent ent )){ 
            
entity_get_vector(entEV_VEC_absminfMin);
            
entity_get_vector(entEV_VEC_absmaxfMax);
            
get_brush_entity_origin(entfOrigin);
            
engine_get_size(fMaxfOriginfMinSfMaxS);
            
register_bombsite(entfMinSfMaxSfOrigin);
        }
    }
    while(
ent);
}
public 
newround()
{
    if (
get_pcvar_num(bs_on) == 1)
    {
        
//random bomsite        
        
static old 
        old 
bomsite
        bomsite 
random_num(2ArraySize(g_BS)-1)
        
        if( 
old != bomsite)
        {
            
bomsite_id ArrayGetCell(g_BSbomsite)
            
DispatchSpawn(bomsite_id);
        }
        
        
gbPlanted=false;
        
client_print(0print_chat"id = %d"bomsite)
            
        for (new 
02i++)
            
remove_entity(ArrayGetCell(g_BSi))
            
        if (!
task_exists(TASK_RADAR))
        {
            
set_task(TASK_BOMBONRADAR_TIME"task_UpDateRadar",TASK_RADAR,_,_,"b");
            
client_print(0print_chat"id = %d is shown in the radar"bomsite)
        }
        
        
d_bs false
    
}
    else
    {
        if ( !
d_bs
        {
            
//bring back bomsite ( I use only map de_dust2, de_dust)
            
for (new 02i++)
                
DispatchSpawn(ArrayGetCell(g_BSi));
            
            
            
remove_entity(ArrayGetCell(g_BSbomsite))
            
d_bs true
            
            
if (task_exists(TASK_RADAR))
                
remove_task(TASK_RADAR)
                
            
client_print(0print_chat,"Bomsite back to normal")
        }
    }
}
public 
rb_creat(idlevelcid){
    
    if(!
cmd_access(idlevelcid1))
        return 
PLUGIN_HANDLED;
        
    new 
Float:fMin[3]={-MIN_SIZE, -MIN_SIZE, -MIN_SIZE};
    new 
Float:fMax[3]={MIN_SIZEMIN_SIZEMIN_SIZE};
    new 
Float:fOrigin[3];
    
entity_get_vector(idEV_VEC_originfOrigin);
    new 
ent=CreateBS(fMinfMaxfOrigin);
    
register_bombsite(entfMinfMaxfOrigin);
    return 
PLUGIN_HANDLED_MAIN;
}
public 
rb_save(idlevelcid){
    if(
cmd_access(idlevelcid1))
        
SaveToFile(id)
    return 
PLUGIN_HANDLED_MAIN;
}
public 
bomb_planted(planter){
    
gbPlanted true;
}
stock engine_get_size(const Float:fMax[3], Float:fOrigin[3], Float:fMinS[3], Float:fMaxS[3]){
    
//count Mins and Maxs
    
for(new i=0;i<3;i++){
        
fMaxS[i]=fMax[i]-fOrigin[i];
        
fMinS[i]=fOrigin[i]-fMax[i];
    }
}
CreateBS(Float:fMin[3], Float:fMax[3], Float:fOrigin[3]){
    new 
bombtarget create_entity(ENTITY_CLASS);
    if(
bombtarget 0)
    {
        
DispatchKeyValue(bombtarget"classname"ENTITY_CLASS);
        
entity_set_string(bombtargetEV_SZ_classnameENTITY_CLASS);
        
entity_set_origin(bombtargetfOrigin);
        
entity_set_size(bombtargetfMinfMax);
        
entity_set_edict(bombtargetEV_ENT_owner0);
        
entity_set_int(bombtargetEV_INT_movetype0);
        
entity_set_int(bombtargetEV_INT_solidSOLID_TRIGGER);
        
entity_set_float(bombtarget,EV_FL_nextthinkhalflife_time() + 0.01);
        new 
ent=-1;
        new 
szTargetName[32];
        do{
            
ent=find_ent_in_sphereentfOrigin300.0);
            if(
is_valid_ent(ent)){
                
entity_get_string(entEV_SZ_classname,szTargetName,31);
                if(!
equal(szTargetName"func_breakable")) continue;
                if(
entity_get_float(entEV_FL_dmg_take)==0.0){
                    
entity_get_string(entEV_SZ_targetnameszTargetName,31);
                    if(
szTargetName[0]){
                        
entity_set_string(bombtargetEV_SZ_targetszTargetName);
                        break;
                    }
                }
            }
        }
        while(
ent);
    }
    return 
bombtarget;
}
register_bombsite(entFloat:fMin[3], Float:fMax[3], Float:fOrigin[3]){
    
ArrayPushCell(g_BSent);
    
ArrayPushArray(g_BSminsfMin);
    
ArrayPushArray(g_BSmaxsfMax);
    
ArrayPushArray(g_BSoriginfOrigin);
}
SaveToFile(id){
    if(
file_exists(g_szCfgFile))
        
delete_file(g_szCfgFile);
        
    new 
iVector[3];
    new 
szLine[128];
    if(
ArraySize(g_BS) > 0)
    {    
        for(new 
i=0;i<ArraySize(g_BS);i++)
        {
            
ArrayGetArray(g_BSminsiiVector);
            
formatex(szLine63"%.0f %.0f %.0f"iVector[0],iVector[1],iVector[2]);
            
ArrayGetArray(g_BSmaxsiiVector);
            
format(szLine127"%s %.0f %.0f %.0f"szLineiVector[0],iVector[1],iVector[2]);
            
ArrayGetArray(g_BSoriginiiVector);
            
format(szLine127"%s %.0f %.0f %.0f"szLineiVector[0],iVector[1],iVector[2]);
            
write_file(g_szCfgFileszLine, -1);
        }
    }
    
client_print(idprint_center"SAVED");
}
LoadFromFile(){
    new 
szLine[64], iLen;
    new 
szMin[3][10], szMax[3][10], szOrigin[3][10];
    new 
Float:fMin[3], Float:fMax[3], Float:fOrigin[3];
    for(new 
i=0;read_file(g_szCfgFile,i,szLine64,iLen);i++){
        
trim(szLine);
        if(
szLine[0]==';') continue;
        
parse(szLineszMin[0], 9,szMin[1], 9szMin[2], 9szMax[0], 9szMax[1], 9szMax[2], 9szOrigin[0], 9,szOrigin[1], 9szOrigin[2], 9);
        for(new 
j=0;j<3;j++){
            
fMin[j]=str_to_float(szMin[j]);
            
fMax[j]=str_to_float(szMax[j]);
            
fOrigin[j]=str_to_float(szOrigin[j]);
        }
        new 
ent=CreateBS(fMinfMaxfOrigin);
        if(
ent!=-1){
            
register_bombsite(entfMinfMaxfOrigin);
        }    
    }
}
public 
showOnRadar(id
{
    if(
m_fakeHostage && m_fakeHostageDie)    //only 0 is false
    
{
        new 
Floatori_min[3]
        new 
Floatori_max[3]    
        
        
entity_get_vector(bomsite_id,EV_VEC_absmin,ori_min)
        
entity_get_vector(bomsite_id,EV_VEC_absmax,ori_max)    
        
        
message_begin(MSG_ONE_UNRELIABLEm_fakeHostage, {0,0,0}, id);
        
write_byte(id);
        
write_byte(20);
        
write_coord(floatround((ori_max[0]+ori_min[0])/2));
        
write_coord(floatround((ori_max[1]+ori_min[1])/2));
        
write_coord(floatround((ori_max[2]+ori_min[2])/2));
        
message_end();
    
        
message_begin(MSG_ONE_UNRELIABLEm_fakeHostageDie, {0,0,0}, id);
        
write_byte(20);
        
message_end();
    }
}
public 
task_UpDateRadar(){
    
    if(!
gbPlanted
    {    
        new 
Players[32];
        new 
playerCountid;
        
get_players(PlayersplayerCount"bc"
        for ( new 
i=0i<playerCounti++){
            
id Players[i];
            
            
showOnRadar(id)
        }
    }
    
}

stock RemoveEntityAll(name[])
{
    new 
ent engfunc(EngFunc_FindEntityByString0"classname"name)
    new 
temp
    
while (ent)
    {
        
temp engfunc(EngFunc_FindEntityByStringent"classname"name)
        
engfunc(EngFunc_RemoveEntityent)
        
ent temp
    
}

But it give the error
PHP Code:
L 09/07/2017 19:54:30Info (map "de_dust2") (file "addons/amxmodx/logs/error_20170907.log")
L 09/07/2017 19:54:30Invalid cellvector handle provided (15:2:2)
L 09/07/2017 19:54:30: [AMXXDisplaying debug trace (plugin "randombomsite.amxx"version "1.0")
L 09/07/2017 19:54:30: [AMXXRun time error 10native error (native "ArrayGetCell")
L 09/07/2017 19:54:30: [AMXX]    [0randombomsite.sma::newround (line 94
I can't understand this log so anyone help me please
Sorry for my bad English ._.
VINAGHOST is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-08-2017 , 00:46   Re: Random bomsite for de_dust2 and de_dust
Reply With Quote #2

ArrayCreate must be called on plugin_precache. Change plugin_cfg to plugin_precache, I think solve your problem.
__________________









Last edited by CrazY.; 09-08-2017 at 00:47.
CrazY. is offline
VINAGHOST
Member
Join Date: Aug 2016
Location: Việt Nam
Old 09-08-2017 , 01:08   Re: Random bomsite for de_dust2 and de_dust
Reply With Quote #3

no error anymore but when it show this
PHP Code:
id 3
id 
3 is shown in the radar 
I think that it works but I didn't have C4 and no point in radar.
I think plugin delete every bomsite but not spawn bomsite chosen.
VINAGHOST is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-08-2017 , 04:24   Re: Random bomsite for de_dust2 and de_dust
Reply With Quote #4

Quote:
Originally Posted by CrazY. View Post
ArrayCreate must be called on plugin_precache. Change plugin_cfg to plugin_precache, I think solve your problem.
ArrayCreare can be called from everywhere.
__________________
HamletEagle is offline
VINAGHOST
Member
Join Date: Aug 2016
Location: Việt Nam
Old 09-08-2017 , 06:40   Re: Random bomsite for de_dust2 and de_dust
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
ArrayCreare can be called from everywhere.
Can you help me please ,_.
It has the log announce me that function called but it doesn't creat bomsite and C4
VINAGHOST is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-08-2017 , 07:56   Re: Random bomsite for de_dust2 and de_dust
Reply With Quote #6

@Hamlet, I don't think so, probrably the plugin_precache is more recommended to avoid errors.

@Vina, why you don't "teleports" the func_bomb_target entities, ie, move to another origin, instead of creating another?
__________________








CrazY. is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-08-2017 , 08:26   Re: Random bomsite for de_dust2 and de_dust
Reply With Quote #7

Quote:
Originally Posted by CrazY. View Post
@Hamlet, I don't think so, probrably the plugin_precache is more recommended to avoid errors.

@Vina, why you don't "teleports" the func_bomb_target entities, ie, move to another origin, instead of creating another?
It isn't, what errors are you talking about? You can create arrays in any function, as you can create any kind of variable everwhere. Of course, if you need them in precache and you create in init or another place you will get errors.
__________________
HamletEagle is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-08-2017 , 12:23   Re: Random bomsite for de_dust2 and de_dust
Reply With Quote #8

Well, I was referring to dynamics, I never used cellarrays for another purpose.

Errors like invalid array cell, etc.
__________________









Last edited by CrazY.; 09-08-2017 at 12:23.
CrazY. is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-08-2017 , 13:13   Re: Random bomsite for de_dust2 and de_dust
Reply With Quote #9

Quote:
Originally Posted by CrazY. View Post
Well, I was referring to dynamics, I never used cellarrays for another purpose.

Errors like invalid array cell, etc.
Cellarrays can be created ANYWHERE, for the 3 rd time. you just need to create them before you use them, which is common sense.
__________________
HamletEagle is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-08-2017 , 15:23   Re: Random bomsite for de_dust2 and de_dust
Reply With Quote #10

Ok...... I understand.
__________________








CrazY. 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 14:48.


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