AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problems with saving and spawning. (https://forums.alliedmods.net/showthread.php?t=75350)

FLR 08-03-2008 17:14

Problems with saving and spawning.
 
1 Attachment(s)
Hi all pr0 coders :)

I have some really annoying problems with my plugin.
The first one is when I spawn my powerups. Sometimes after Ive spawned two or three and then press delete all something fucks up.
Because the next time I spawn, i can only spawn 2, then I have to press the spawn button a few times before the third one shows up.

And the second problem is when saving. Everytime, two rows with just 0.000000 appears in the file. They tend to stay even if I owerwrite the file.

Oh, and I have to mention that this is a modified version of GHW_cronics Power Up Mod 2.0

Well, its not exactly c/p, I have written and rewritten many things, but anyways, credits to you GHW.

Heres the code:
Or if you want, you can dl the sma
PHP Code:

#define VERSION            "0.9.4"
#define AUTHOR            "FLR aka Flayer"
#define    NAME            "HnS Powerups"

#define DELAYID            21543
#define MKSID             45625
#define SPAWNID            57842
#define OFFSET_CAN_LONGJUMP        356
#define ADMINACCESS        ADMIN_KICK

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fakemeta>
#include <fakemeta_util>
#include <engine>
#include <fun>

#define NUM_PUPS    6
#define MAX_PUPS    50 // the maximum number of powerups allowed on a map
 
#pragma semicolon 1;

new const szModels[NUM_PUPS][64] =
{
    
"models/hnsp/hns_powerup_invisibility.mdl",
    
"models/hnsp/hns_powerup_gravity.mdl",
    
"models/hnsp/hns_powerup_speed.mdl",
    
"models/hnsp/hns_powerup_gainhp.mdl",
    
"models/hnsp/hns_powerup_autoheal.mdl",
    
"models/hnsp/hns_powerup_longjump.mdl"
};

new const 
classnames[NUM_PUPS][33] = //To add more powerups edit the NUM_PUPS!
{
    
"FLR_HNSP_Invisibility",
    
"FLR_HNSP_Gravity",
    
"FLR_HNSP_Speed",
    
"FLR_HNSP_GainHP",
    
"FLR_HNSP_Autoheal",
    
"FLR_HNSP_Longjump"
};

new const 
powerupNames[NUM_PUPS][16] = 
{
    
"Invisibility",
    
"Gravity",
    
"Speed",
    
"Gain HP",
    
"Autoheal",
    
"Longjump"
};

new const 
pupinfo[NUM_PUPS][256] = 
{
    
"Invisibility Powerup: Makes you transparent, almost invisible.",
    
"Gravity Powerup: Gives you lower gravity equal to 1/2 of the normal gravity.",
    
"Speed Powerup: Gives you 320 velocity, RUN BITCH, RUN!",
    
"Gain HP Powerup: Gives you a specific amount of HP.(255 is max)",
    
"Autoheal Powerup: Gives you autoheal for 30 seconds.(255 is max)",
    
"Longjump Powerup: Gives you the ability to jump very far."
};

new const 
pupglow[NUM_PUPS][3] =
{
    {
200,     200,     255},
    {
30,     150,     150},
    {
0,     230,     25},
    {
255,     0,     0},
    {
120,     65,     65},
    {
30,    0,    210}
};

/////////////////////////////////
//Random vars   /////////////////
/////////////////////////////////
new ent;
new 
body

new 
szConfigfile[200];
new 
szConfigsdir[200];
new 
szMap[32];
new 
szClassname[32];
new 
globalClassname[32];

new 
type[MAX_PUPS];
new 
ents[MAX_PUPS];
new 
eline[MAX_PUPS];
new 
count_pups;

new 
iInvisAmount;
new 
health;
new 
hpgain;

//--Floats--/////////////////
new Float:fRespawn
new 
Float:MaxBox[3] = {1.0,1.0,1.0} ; 
new 
Float:Color[3];
new 
Float:origins[MAX_PUPS][3];
/////////////////////////////////

/////////////////////////////////
//Player related/////////////////
/////////////////////////////////
new bool:longjump[33];

new 
szCnum[32];

new 
iPlrCooldown[33];
new 
plrHavePup[33]; 
new 
player_rewards[NUM_PUPS][33]; 

new 
Float:velocity[3];
//--Loop-related/////////////////
new players[32];
new 
num;
/////////////////////////////////

/////////////////////////////////
//Cvar variables/////////////////
/////////////////////////////////
new iEnabled
new 
iLast;
new 
iOnlyOnePup
new 
iHealamount;
new 
iHealduration;
new 
iHpPerSec;
new 
iCooldown;
new 
iWarningTrigg;
new 
iWarningInt;
new 
fpRespawn;
new 
health_add;
new 
iInvisAmt;
new 
iInvisDur;
new 
iAutoSave;
/////////////////////////////////

/////////////////////////////////
//Menu variables/////////////////
/////////////////////////////////
new iPowerup[33];
new 
create[32];
new 
place[3];
new 
data[6];
new 
iName[64];

new 
iCvarnum;
new 
Float:fCvarnum;

new 
gMainMenu;
new 
gTypeMenu ;
new 
gSettings;
/////////////////////////////////

/////////////////////////////////
//Save func variables////////////
/////////////////////////////////
new szData[128];
/////////////////////////////////

public plugin_init()
{
    
//Cvars and such////////////////////////////////////////////////////////////
    
register_plugin        (NAME,VERSION,AUTHOR);

    
register_concmd        ("hnsp_create","cmd_create",ADMIN_KICK,"<type>");
    
register_concmd        ("hnsp_remove","cmd_remove",ADMIN_KICK,"Removes nearest Powerup spawn to you.");
    
register_concmd        ("hnsp_removeall","cmd_removeall",ADMIN_KICK,"Removes all the powerups on the map");
    
    
register_clcmd        ("say /hnsp""showMenu",ADMIN_KICK);
    
register_clcmd        ("say_team /hnsp","showMenu",ADMIN_KICK);
    
register_clcmd        ("hnsp_menu","showMenu",ADMIN_KICK);
    
    
iLast =             register_cvar("hnsp_last","20");
    
iEnabled =         register_cvar("hnsp_enabled","1");
    
iAutoSave =         register_cvar("hnsp_autosave","1");
    
iOnlyOnePup =         register_cvar("hnsp_onlyonepup""1");
    
iHealamount =         register_cvar("hnsp_healamount""50");
    
iHealduration =         register_cvar("hnsp_healduration""15");
    
iHpPerSec =         register_cvar("hnsp_hpsec","2");
    
iCooldown =         register_cvar("hnsp_cooldown""10");
    
iWarningInt=         register_cvar("hnsp_warningtrigg","5");
    
fpRespawn =         register_cvar("hnsp_puprespawntime","10.0");
    
iInvisAmt =         register_cvar("hnsp_invisamt""50");
    
iInvisDur =         register_cvar("hnsp_invisdur","5");
    
    
register_event        ("CurWeapon","CurWeapon","be");
    
register_logevent    ("new_round",2,    "1=Round_Start");

    
register_forward    (FM_Touch"FM_touch");
    
register_forward    (FM_PlayerPreThink"preThink");
    
    
    
//Get cvars////////////////////////////////////////
    
iWarningTrigg =         get_pcvar_num(iWarningInt);
    
fRespawn =         get_pcvar_float(fpRespawn);
    
health_add =         get_pcvar_num(iHealamount);
    
iInvisAmount =         get_pcvar_num(iInvisAmt);
    
    
//Load config /////////////////////////////////////
    
get_mapname(szMap,31);

    
get_configsdir(szConfigsdir,199);

    
format(szConfigsdir,199,"%s/HnSP",szConfigsdir);
    
format(szConfigfile,199,"%s/%s.ini",szConfigsdir,szMap);
    
    if(!
dir_exists(szConfigsdir))
    { 
        
mkdir(szConfigsdir);
    }

    
load_powerups();

    
//tasks////////////////////////////////////////////
    
set_task(1.0,"ability_think",0,"",0,"b");
    
set_task(fRespawn,"respawnPups",SPAWNID,"",0,"b");
    
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// Menus and stuff /////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

 
public createMenu(id)
 {
 
 
/////////////Main menu///////////////////////////////////////////////////////////
    
gMainMenu menu_create("\rFLR's HnS Powerups: Main""mnuMain");
    
    
format(create,31,"\wCreate Powerup: %s",powerupNames[iPowerup[id]]);
    
    
menu_additem(gMainMenu create,"1"ADMIN_KICK);
    
menu_additem(gMainMenu "\wChange Powerup Type""2"ADMIN_KICK);
    
menu_additem(gMainMenu "\wRemove Powerup(aiming)""3"ADMIN_KICK);
    
menu_additem(gMainMenu "\wRemove All Powerups""4"ADMIN_KICK);
    
menu_additem(gMainMenu"\wSave Config""5"ADMIN_KICK);
    
menu_additem(gMainMenu"\wCvar Settings","6",ADMIN_KICK);
    
    
format(create,31,"\wAutoSave: (%i)"get_pcvar_num(iAutoSave));
    
menu_additem(gMainMenucreate,"7",ADMIN_KICK);
    

/////////////////////////////////////////////////////////////////////////////////
/////////////Powerup types menu//////////////////////////////////////////////////
    
gTypeMenu menu_create("\rFLR's HnS Powerups: Powerups""mnuPups");
    
     
// loop through all the powerups. The i = 1 is because the menu goes from 1-x, not 0-x
     // and therefore the iPowerup is set to key-1 in the handler when choosing. Else the player
     // would select the wrong one
     
    
for(new 1NUM_PUPS+1i++)
    {
        
format(create31"\w%s",powerupNames[i-1]);
        
format(place,2,"%i",i);
        
        
menu_additem(gTypeMenu,create,place,ADMIN_KICK);
    }
    
format(place,2,"%i",NUM_PUPS+2);
    
    
menu_additem(gTypeMenu,"\wBack",place,ADMIN_KICK);
    
    
menu_setprop(gTypeMenu,MPROP_PERPAGE,0);

/////////////////////////////////////////////////////////////////////////////////    
/////////////Settings menu///////////////////////////////////////////////////////
    
gSettings menu_create("\rFLR's HnS Powerups: Settings""mnuSett");
    
    
format(create,31,"\wPowerup Last: (%i)"get_pcvar_num(iLast));
    
menu_additem(gSettings,create,"1",ADMIN_KICK);
    
    
format(create,31,"\wPowerup Cooldown: (%i)"get_pcvar_num(iCooldown));
    
menu_additem(gSettings,create,"2",ADMIN_KICK);
    
    
format(create,31,"\wPowerup Healamount: (%i)"get_pcvar_num(iHealamount));
    
menu_additem(gSettings,create,"3",ADMIN_KICK);
    
    
format(create,31,"\wPowerup Heal Duration: (%i)"get_pcvar_num(iHealduration));
    
menu_additem(gSettings,create,"4",ADMIN_KICK);
    
    
format(create,31,"\wPowerup HP per sec: (%i)"get_pcvar_num(iHpPerSec));
    
menu_additem(gSettings,create,"5",ADMIN_KICK);
    
    
format(create,31,"\wPup Invis amount: (%i)"get_pcvar_num(iInvisAmt));
    
menu_additem(gSettings,create,"6",ADMIN_KICK);
    
    
format(create,31,"\wPup Invis Duration: (%i)"get_pcvar_num(iInvisDur));
    
menu_additem(gSettings,create,"7",ADMIN_KICK);
    
    
format(create,31,"\wPowerup Respawn time: (%0.0f)"get_pcvar_float(fpRespawn) );
    
menu_additem(gSettings,create,"8",ADMIN_KICK);
    
    
menu_additem(gSettings,"\wBack","9",ADMIN_KICK);
    
    
menu_setprop(gSettings,MPROP_PERPAGE,0);
    
/////////////////////////////////////////////////////////////////////////////////
    
 
}

 public 
mnuMain(idmenuitem)
 {
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }

    new 
accesscallback;
   
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);

    new 
key str_to_num(data);
    
    switch(
key)
    {
        case 
1:
        {
            
menu_destroy(menu);
            
cmd_create(idiPowerup[id]);
            
showMenu(id);
        }
        case 
2:
        {
            
menu_destroy(menu);
            
menu_display(idgTypeMenu,0);
        }
        case 
3:
        {
            
menu_destroy(menu);
            
cmd_remove(id);
            
showMenu(id);
        }
        case 
4:
        {
            
menu_destroy(menu);
            
cmd_removeall(id);
            
showMenu(id);
        }
        case 
5:
        {
            
menu_destroy(menu);
            
save_powerups(id);
            
showMenu(id);
        }
        case 
6:
        {
            
menu_destroy(menu);
            
menu_display(idgSettings,0);
        }
        case 
7:
        {    
            
menu_destroy(menu);
            
            if(
get_pcvar_num(iAutoSave) == 1)
            {
                
set_pcvar_num(iAutoSave0);
                
client_print(id,print_chat,"[HNSP] Autosave is (Disabled)");
            }
            else
            {
                
set_pcvar_num(iAutoSave1);
                
client_print(id,print_chat,"[HNSP] Autosave is (Enabled)");
            }
            
            
showMenu(id);
        }
    }
    
    return 
PLUGIN_HANDLED;
 }
 
 public 
mnuPups(idmenuitem)
 {
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
accesscallback;
   
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);

    new 
key str_to_num(data);
  
    if(
key != NUM_PUPS+2)
    {
        
menu_destroy(menu);
        
iPowerup[id] = key-1;
        
showMenu(id);
    }
    else 
    {
        
menu_destroy(menu);
        
showMenu(id);
    }
   
    
    return 
PLUGIN_HANDLED;
 
 }
 
 
 public 
mnuSett(idmenuitem)
 {
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
accesscallback;
   
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);

    new 
key str_to_num(data);
    
    switch(
key)
    {
        case 
1// last
        
{
            
menu_destroy(menu);
            
iCvarnum get_pcvar_num(iLast);
            
            if(
iCvarnum>= 40)
            {
                
set_pcvar_num(iLast,5);
            }
            else
            {
                
set_pcvar_num(iLast,iCvarnum+=5);
            }
            
            
createMenu(id);
            
menu_display(idgSettings,0);
            
        }
        case 
2// cooldown
        
{
            
menu_destroy(menu);
            
iCvarnum get_pcvar_num(iCooldown);
            
            if(
iCvarnum>= 40)
            {
                
set_pcvar_num(iCooldown,5);
            }
            else
            {
                
set_pcvar_num(iCooldown,iCvarnum+=5);
            }
            
            
createMenu(id);
            
menu_display(idgSettings,0);
        }
        case 
3// healamount
        
{
            
menu_destroy(menu);
            
iCvarnum get_pcvar_num(iHealamount);
            
            if(
iCvarnum>= 100)
            {
                
set_pcvar_num(iHealamount,25);
            }
            else
            {
                
set_pcvar_num(iHealamount,iCvarnum+=25);
            }
            
            
createMenu(id);
            
menu_display(idgSettings,0);
        }
        case 
4// heal duration
        
{
            
menu_destroy(menu);
            
iCvarnum get_pcvar_num(iHealduration);
            
            if(
iCvarnum>= 40)
            {
                
set_pcvar_num(iHealduration,5);
            }
            else
            {
                
set_pcvar_num(iHealduration,iCvarnum+=5);
            }
            
            
createMenu(id);
            
menu_display(idgSettings,0);
        }
        case 
5// hp per sec
        
{
            
menu_destroy(menu);
            
iCvarnum get_pcvar_num(iHpPerSec);
            
            if(
iCvarnum>=5)
            {
                
set_pcvar_num(iHpPerSec,1);
            }
            else
            {
                
set_pcvar_num(iHpPerSec,iCvarnum+=1);
            }
            
            
createMenu(id);
            
menu_display(idgSettings,0);
        }
        case 
6// invis amount
        
{
            
menu_destroy(menu);
            
iCvarnum get_pcvar_num(iInvisAmt);
            
            if(
iCvarnum>= 100)
            {
                
set_pcvar_num(iInvisAmt,0);
            }
            else
            {
                
set_pcvar_num(iInvisAmt,iCvarnum+=25);
            }
            
            
createMenu(id);
            
menu_display(idgSettings,0);
        }
        case 
7// the amount of time youre invisible
        
{
            
menu_destroy(menu);
            
iCvarnum get_pcvar_num(iInvisDur);
            
            if(
iCvarnum>= 30)
            {
                
set_pcvar_float(iInvisDur,5.0);
            }
            else
            {
                
set_pcvar_float(iInvisDur,iCvarnum+=5.0);
            }
            
            
createMenu(id);
            
menu_display(idgSettings,0);
        }
        case 
8// pup respawn time (float)
        
{
            
menu_destroy(menu);
            
fCvarnum get_pcvar_float(fpRespawn);
            
            if(
fCvarnum>= 40.0)
            {
                
set_pcvar_float(fpRespawn,5.0);
            }
            else
            {
                
set_pcvar_float(fpRespawn,fCvarnum+=5.0);
            }
            
            
createMenu(id);
            
menu_display(idgSettings,0);
        }
        case 
9:
        {
            
menu_destroy(menu);
            
showMenu(id);
        }
    }
    
    return 
PLUGIN_HANDLED;
 }
 
 
 public 
showMenu(id)
 {
    
createMenu(id);
    
menu_display(id,gMainMenu,0);
 }

////////////////////////////////////////////////////////////////////////////////////////////////////
// Remove powerups /////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
public cmd_remove(id)
{
    if(
get_user_flags(id) & ADMINACCESS)
    {
    
        
get_user_aiming(id,ent,body,320);
        
        if(!
pev_valid(ent))
        {
            return;
        }
        
        
entity_get_string(ent,EV_SZ_globalname,globalClassname,31);
        
        for(new 
0NUM_PUPSg++)
        {
            if(
equali(globalClassname,classnames[g]))
            {
                
engfunc(EngFunc_RemoveEntityent);
                
client_print(idprint_chat,"[HNSP] %s Powerup removed from map."powerupNames[g]);
                
count_pups--;
            }
        }
        
        if(
get_pcvar_num(iAutoSave) == 1)
        {
            
save_powerups(id);
        }
        else
        {
            
load_powerups();
        }
    }    
}    


public 
cmd_removeall(id)
{
    if (
get_user_flags(id) & ADMINACCESS)
    {    
        new 
szName[32];
        new 
file fopen(szConfigfile,"wt");
        
        while((
ent find_ent_by_class(ent,"hnsp_pup")))
        {
            if(
pev_valid(ent))
            {
                
engfunc(EngFunc_RemoveEntity,ent);
                
fputs(file,"");
            }
        }
        
        
fclose(file);
        
        
get_user_name(idszName32);
        
        
client_print(idprint_chat"[HNSP] All powerups deleted from the map."szName);
        
        if(
get_pcvar_num(iAutoSave) == 1)
        {
            
save_powerups(id);
        }
        else
        {
            
load_powerups();
        }
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// Pick up a powerup////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
public FM_touch(ent,id)
{
    if(!
is_user_alive(id) || iPlrCooldown[id])
    {
        return;
    }
    
    
    
pev(ent,pev_globalname,globalClassname,31);
    
    for(new 
i=0;iNUM_PUPS;i++)
    {
        if(
equali(globalClassname,classnames[i]) && player_rewards[i][id])
        {
            
entity_set_int(ent,EV_INT_solid,SOLID_NOT);
            
set_task(1.0"makeSolid",MKSID+ent""0""0);    
            
            
client_print(id,print_chat,"[HNSP] You already have a powerup!(%s)",powerupNames[i]);
        }
        else if(
equali(globalClassname,classnames[i]) && !player_rewards[i][id])
        {
            if(
plrHavePup[id] && iOnlyOnePup && !equali(globalClassnameclassnames[3]))
            {
                return;
            }
            
            
engfunc(EngFunc_RemoveEntity,ent);
            
            if(
get_pcvar_num(iOnlyOnePup))
            {
                
plrHavePup[id] = 1;
            }
            
            
emit_sound(idCHAN_WEAPON"items/gunpickup1.wav"0.5ATTN_NORM0PITCH_NORM);
            
            
handle_reward(id,i);    
        }        
    }
}

public 
makeSolid(ent)
{
    
ent -= MKSID;
    
    if(
pev_valid(ent))
    {
        
entity_set_int(ent,EV_INT_solid,SOLID_BBOX);
    }
}


public 
CurWeapon(id)
{
    if(
player_rewards[2][id])
    {
        
set_pev(id,pev_maxspeed,320.0);
    }
    else if(
player_rewards[1][id])
    {
        
set_pev(id,pev_gravity,0.5);
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//Handle rewards ///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
public remove_reward(id,type)
{
    if(
get_pcvar_num(iOnlyOnePup))
    {
        
plrHavePup[id] = 0;
    }
    
    if(
get_pcvar_num(iCooldown) >= && get_pcvar_num(iOnlyOnePup))
    {
        new 
cooldown get_pcvar_num(iCooldown);
        
iPlrCooldown[id] = cooldown;
    }
    
    switch(
type)
    {
        case 
0:
        {    
set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderTransAlpha255);
            
client_print(idprint_chat"[HNSP] You are no longer invisible.");
        }
        case 
1:
        {
            
set_pev(id,pev_gravity,1.0);
            
client_print(id,print_chat"[HNSP You no longer have Low gravity.");
        }
        case 
2:
        {
            
set_pev(id,pev_maxspeed,250.0);
            
client_print(id,print_chat"[HNSP] You no longer have Superspeed.");
        }
        
        case 
4:
        {
            
client_print(id,print_chat"[HNSP] You no longer have Autoheal.");
        }
        case 
5:
        {
            
player_rewards[type][id] = 0;
            
client_print(id,print_chat,"[HNSP] You longer have the longjump ability.");
            
fm_set_user_longjump(idlongjump[id] =false);
        }
    }
}

public 
handle_reward(id,type)
{    
    switch(
type)
    {
        case 
0:
        {    
            
player_rewards[type][id] = get_pcvar_num(iInvisDur);
            
set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderTransAlphaiInvisAmount);
            
client_print(idprint_chat"[HNSP] You just gained invisibility! (%i seconds)"player_rewards[type][id]);
            
        }
        case 
1:
        {
            
player_rewards[type][id] = get_pcvar_num(iLast);
            
            
client_print(id,print_chat,"[HNSP] You gained Lower Gravity! (%i seconds)",player_rewards[type][id]);
            
            
set_pev(id,pev_gravity,0.5);
        }
        case 
2:
        {
            
set_pev(id,pev_maxspeed,320.0);
            
            
player_rewards[type][id] = get_pcvar_num(iLast);
            
            
client_print(idprint_chat,"[HNSP] You just gained 320 movementspeed! (%i seconds)"player_rewards[type][id]);
            
        }
        case 
3:
        {
            new 
health pev(id,pev_health);
        
            if(
health 205)
            {
                
set_pev(id,pev_health,255.0);
            }
            else
            {
                
health += health_add+0.0;
        
                
set_pev(id,pev_health,health);
            }
            
            
client_print(id,print_chat,"[HNSP] You gained %i health!"health_add);
        }
        
        case 
4:
        {
            
player_rewards[type][id] = get_pcvar_num(iHealduration);
            
client_print(id,print_chat,"[HNSP] You just gained Auto-Heal! (%i seconds)",player_rewards[type][id]);
        }
        case 
5:
        {
            
player_rewards[type][id] = get_pcvar_num(iLast);
            
client_print(id,print_chat,"[HNSP] You just gained longjump ability! (%i seconds)"player_rewards[type][id]);
            
fm_set_user_longjump(idlongjump[id] =true);
        }
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//create powerups///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
public cmd_create(iditem)
{
    if(
get_user_flags(id) & ADMINACCESS)
    {

        if(
count_pups>=MAX_PUPS)
        {
            
client_print(id,print_chat,"[HNSP] %d Powerups exist. Only %d allowed. Could not create new one.",count_pups,MAX_PUPS);
            return;
        }
    
        
type[count_pups] = item;
        
        
fm_get_aim_origin(id,origins[count_pups]);
        
origins[count_pups][2] += 35;
        
        
count_pups++;
    
        
respawnPups();
        
        if(
get_pcvar_num(iAutoSave) == 1)
        {
            
save_powerups(id);
        }
        
        
client_print(id,print_chat,"[HNSP] Powerup created at your aim location.");
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
public new_round()
{
    for(new 
0sizeof(plrHavePup); e++) // just to be sure nobody have a powerup on new round
    
{
        
plrHavePup[e] = 0;
        
    }
    
    for(new 
033f++)
    {
        for(new 
0NUM_PUPS;g++)
        {
            
player_rewards[g][f] = 0;
        }
    }
    
    
respawnPups();
}

public 
respawnPups()
{
    for(new 
i=0;count_pups ;i++)
    {
        if((!
ents[i] || !pev_valid(ents[i])))
        {
            
spawn_pup(i+50);
        }
    }
}

public 
client_disconnect(id)
{
    while(
task_exists(id))
    {
        
remove_task(id);
    }
    
    for(new 
0;NUM_PUPSi++) 
    {
        
player_rewards[i][id] = 0;
    }
}

public 
plugin_precache()
{
    
precache_sound("items/gunpickup1.wav");
    
    for(new 
i=0;NUM_PUPS;i++)
    {
        
precache_model(szModels[i]);
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//Spawn pups on new round && load origins on mapload ///////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
public spawn_pup(num)
{
    
num -= 50;
    
    if(
get_pcvar_num(iEnabled) && type[num] != -1)
    {
        
ents[num] = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"));
        
        
set_pev(ents[num],pev_classname,"hnsp_pup");
        
set_pev(ents[num],pev_globalname,classnames[type[num]]);
        
engfunc(EngFunc_SetModel,ents[num],szModels[type[num]]);
                
        
Color[0] = float(pupglow[type[num]][0]);
        
Color[1] = float(pupglow[type[num]][1]);
        
Color[2] = float(pupglow[type[num]][2]);
    
        
dllfunc(DLLFunc_Spawnents[num]);
        
        
entity_set_int(ents[num], EV_INT_renderfxkRenderFxGlowShell);
        
entity_set_float(ents[num], EV_FL_renderamt150.0);
        
entity_set_int(ents[num], EV_INT_rendermodekRenderTransAlpha);
        
entity_set_vector(ents[num], EV_VEC_rendercolor,Color);
        
        
entity_set_vector(ents[num], EV_VEC_maxsMaxBox);
        
entity_set_origin(ents[num],origins[num]);
        
entity_set_int(ents[num], EV_INT_effects32);
        
entity_set_int(ents[num], EV_INT_solidSOLID_BBOX);
        
entity_set_int(ents[num], EV_INT_movetypeMOVETYPE_FLY);
        
entity_set_edict(ents[num],EV_ENT_owner,33);
        
    }
}

public 
load_powerups() // this shit is almost just copy/paste. Havent done much on this. GJ GHW!
{
    if(
file_exists(szConfigfile))
    {
        new 
Fsize file_size(szConfigfile,1);
        new 
read[64], trash;
        new 
left[64];
        
        
count_pups 0;
        
        for(new 
i=-1;i<Fsize;i++)
        {
            
read_file(szConfigfile,i,read,63,trash);
            
            if((
read[0] != ';' || read[0] != '0') &&  count_pups MAX_PUPS  &&  strlenread ) > 10)
            {
                
strbreak(read,left,63,read,63);
                
origins[count_pups][0] = str_to_float(left);
                
                
strbreak(read,left,63,read,63);
                
origins[count_pups][1] = str_to_float(left);
                
                
strbreak(read,left,63,read,63);
                
origins[count_pups][2] = str_to_float(left);
                
                
type[count_pups] = str_to_num(read);
                
eline[count_pups] = i;
                
                
count_pups++;
            }
        }
        
respawnPups();
    }
}

public 
save_powerups(id)
{
    new 
rclassname[32];
    new 
file fopen(szConfigfile"wt");
    
ent = -1;
    new 
Float:vOrigin[3];
    
    while((
ent find_ent_by_class(ent,"hnsp_pup")))
    {
        
pev(ent,pev_globalname,rclassname,31);
        
pev(ent,pev_origin,vOrigin);
        
        for(new 
0NUM_PUPSi++)
        {        
            if(
equali(rclassname,classnames[i]) && pev_valid(ent))
            {
                
format(szData128"%f %f %f %i^n",vOrigin[0] ,vOrigin[1] ,vOrigin[2] ,i);
                
fputs(fileszData);
            }
        }
    }
    
    
fclose(file);
    
client_print(idprint_chat,"[HNSP] Config Saved.");
    
    
load_powerups();
    
    return 
PLUGIN_HANDLED;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Called every second, used for countdowns/////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
public ability_think(id)
{
    
get_players(players,num,"ah");
    
    for(new 
i=0;i<= num;i++)
    {
        if(
iPlrCooldown[players[i]])
        {
            
set_hudmessage(02550, -1.00.01,_,_,1.0,0.0,0.0,4);
            
show_hudmessage(players[i], "Cooldown: %i",iPlrCooldown[players[i]]);
            
            
iPlrCooldown[players[i]]--;
        }
    
        for(new 
0;NUM_PUPSj++)
        {
                
//om player_rewards[numret som = j][spelare med numret = i] && inte iPlrcooldown > 0
            
if(player_rewards[j][players[i]] )
            {
                if(
player_rewards[4][players[i]])
                {
                    
health pev(players[i],pev_health);
                    
hpgain get_pcvar_num(iHpPerSec);
                    
                    if(
health >= 223
                    {
                        
health 255;
                    }
                    else 
                    {
                        
health += hpgain;
                    }
                    
                    
set_pev(players[i],pev_health,health+0.0);
                }
                
                if(
player_rewards[j][players[i]] > iWarningTrigg )
                {
                    
set_hudmessage(02550, -1.00.01,_,_,1.0,0.0,0.0,4);
                    
show_hudmessage(players[i], "%s: %i",powerupNames[j],player_rewards[j][players[i]]);
                }
                    
                
                if((
player_rewards[j][players[i]] <= iWarningTrigg  && player_rewards[j][players[i]] != 0))
                {    
                    
set_hudmessage(200200200, -1.0,-1.0,_,_,1.0,0.0,0.0,3);
                    
show_hudmessage(players[i], "%i Seconds left of your %s powerup",player_rewards[j][players[i]], powerupNames[j]);
                    
                    
num_to_word(player_rewards[j][players[i]], szCnum32);
                    
client_cmd(players[i],"speak ^"vox/%s^""szCnum);
                }
                
                
// this is the "countdown" for the abilities  -1 per sec
                
player_rewards[j][players[i]]--; 
                
////////////////////////////////////////////////////////
                
                
if(player_rewards[j][players[i]] <= 0)
                {
                    
remove_reward(players[i],j);
                    
player_rewards[j][players[i]] = 0;
                    
                }
            }
        }    
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//Prethink, ispup() and help. random shit. /////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
public preThink(id)
{
    if(
is_user_alive(id))
    {
        
get_user_aiming(identbody320);
        
        
entity_get_string(ent,EV_SZ_globalnameszClassname32);
            
        for(new 
0NUM_PUPSi++)
        {
            if (
equali(szClassnameclassnames[i]))
            {    
                
set_hudmessage(02550, -1.00.01,_,_,0.1,0.0,0.0,4);
                
show_hudmessage(id"%s"pupinfo[i]);
            }
        }
    }

        
    
// to detect the longjump and remove it.
    
pevidpev_velocityvelocity );
        
    if(
velocity[2] > 285 && player_rewards[5][id])
    {
        
remove_reward(id,5);
    }




All times are GMT -4. The time now is 05:39.

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