AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help, first plugin (https://forums.alliedmods.net/showthread.php?t=274486)

Dyskiu 11-08-2015 15:10

Help, first plugin
 
Hello everyone. This is my first plugin witch i made from nothing. However i have problem, sometimes server freezes and shuts down. Maybe somebody could take a look where i done horrible? Thanks a lot :/

PHP Code:

#include <amxmisc>
#include <amxmodx>
#include <cstrike>
#include <engine>
#include <gunxpmod>
#include <fun>


new const MOD_TITLE[] =       "Supplie drop" 
new const MOD_AUTHOR[] =      "Dyskiu"         
new const MOD_VERSION[] =     "2.1"        


#define drop_reg_dir "drop.log"

new const GiftModel[] = "models/mission2/w_assault.mdl"
new const GiftPlane[] = "ambience/copter.wav"
new const CLASS_NAME[] = "giveGift"
new const Float:RoundA 10.0
new const Float:RoundB 30.0
new const Float:RoundC 10.0
new const Float:RoundD 30.0
const Float:GiftDistance 50.0 //Distance from gift
new const Float:SpeedBoost 50.0
new const Float:GravityBoost 0.9
new Float:Speed[64]
new 
Float:Gravitie[64]

new const 
MaxDrops 3
new Id_ent[3]
new 
Float:F_player_origin[3][3]
#define DropTask 10000
#define EventTask 10060
#define TakingTask 10120
#define RebornTask 10180
#define SpawnTask 10240
new bool:Reborn[64]
new 
HudObj
new d_MaxPlayers 
new TimerElement[64]
new 
bool:ActiveTask[64]
new 
bool:CanBeTakenGift[3]
#define GiftTime 8
new bool:Gravitied[64]
new 
bool:Speedied[64]
new 
TakingEnt[64]

new 
g_szMap[32]
new 
ENABLE // Plugin is disabled for testing purpose


public plugin_precache()

   
precache_model(GiftModel)
   
precache_sound(GiftPlane)

}

public 
plugin_init()
{
    
register_plugin(MOD_TITLEMOD_VERSIONMOD_AUTHOR)
    
register_event("HLTV""event_roundStart""a""1=0""2=0")
    
register_clcmd("say /supplies","show_help");
    
register_clcmd("dyskiuEnable","pluginEnable"); // For testing
    
register_touch("giveGift""player""touch_gift")
    
register_event("DeathMsg","DiedReborn","a")
    
register_event"CurWeapon" "fw_EvCurWeapon" "be" "1=1" )
    
d_MaxPlayers get_maxplayers()
    
HudObj CreateHudSyncObj()
    
get_mapname(g_szMapcharsmax(g_szMap))       
       
    
log_to_file(drop_reg_dir,g_szMap)
}

public 
event_roundStart()
{
    if(
ENABLE==1)
    {
        for (new 
i=0;i<MaxDrops;i++)
        {
            
log_to_file(drop_reg_dir,"Round Start: Setting task EventTask+i")
            if(
task_exists(EventTask+i))
                
remove_task(EventTask+i)
            new 
Float:TimeFloat
            TimeFloat 
random_float(RoundA,RoundB)
            
set_task(TimeFloat,"EventGift",EventTask+i)
            if(
is_valid_ent(Id_ent[i]))
                
remove_entity(Id_ent[i])
            
Id_ent[i]=0
        
}
        for (new 
id=1id <= d_MaxPlayersid++)
        {
            if (
task_exists(id+SpawnTask))
                
remove_task(id+SpawnTask)
            if (
task_exists(id+RebornTask))
                
remove_task(id+RebornTask)
            if (
task_exists(id+DropTask))
                
remove_task(id+DropTask)
            
ActiveTask[id]=false
            Reborn
[id]=false
            Gravitied
[id]=false
            Speedied
[id]=false
        
}
        new 
sMsg[128]
        
format(sMsg127"^x01Nezinai kas tai ^x03[^x04 supplies ^x03]^x01? Parasyk tiesiog ^x03[^x04 /supplies ^x03]^x01.")
        
ColorChat(0,sMsg)
    }
}
public 
pluginEnable()
{
    new 
action[2]
    
read_argv(1action,1)
    new 
number str_to_num(action)
    if (
number==1)
    {
        
log_to_file(drop_reg_dir,"Enabled")
        
ENABLE=1
    
}
    else
    {
        
log_to_file(drop_reg_dir,"Disabled")
        
ENABLE=0
    
}
}

public 
client_disconnect(id)
{
  
ActiveTask[id]=false
  Speedied
[id]=false
  Gravitied
[id]=false
}
public 
client_connect(id)
{
  
ActiveTask[id]=false
  Speedied
[id]=false
  Gravitied
[id]=false
}

public 
EventGift(idTask)
{
    
log_to_file(drop_reg_dir,"EventGift: dropping search")
    new 
iidTask EventTask
    
new j=0
    
new GiftPlace[32]
    for(new 
id=1id<=d_MaxPlayers;id++)
    {
        if(
is_user_alive(id) && cs_get_user_team(id)==CS_TEAM_CT)
        {
            
GiftPlace[j]=id;
            
j++
        }
    }
    new 
place
    place 
random_num(0,j-1)
    
entity_get_vector(GiftPlace[place],EV_VEC_originF_player_origin[i])
    new 
Float:GiftDrop
    GiftDrop 
random_float(RoundC,RoundD)
    
CanBeTakenGift[i]=false
    set_task
(GiftDrop"DropGift"i+DropTask)
}

public 
DropGift(idTask)
{
    
log_to_file(drop_reg_dir,"DropGift: dropping")
    new 
idTask DropTask
    CanBeTakenGift
[i]=true
    
new ent create_entity("info_target")
    
Id_ent[i]=ent
    emit_sound
(entCHAN_STATICGiftPlane0.7ATTN_NORM0PITCH_NORM);
    
entity_set_string(entEV_SZ_classnameCLASS_NAME)
    
entity_set_model(entGiftModel)
    
entity_set_int(entEV_INT_movetypeMOVETYPE_TOSS)
    
entity_set_int(entEV_INT_solidSOLID_TRIGGER)
    
entity_set_vector(entEV_VEC_originF_player_origin[i])
    
set_rendering (entkRenderFxGlowShell,100,100,100,kRenderNormal,25
    
set_hudmessage(2550255, -1.00.3004.04.0)
    
ShowSyncHudMsg(0HudObj"Supplies for war just arrived!");
}

public 
touch_gift(entid)
{
    new 
i=0
    
for (new j=0;j<MaxDrops;j++)
        if(
Id_ent[j]==ent)
            
i=j
    
if (!is_user_alive(id) || cs_get_user_team(id)!=CS_TEAM_CT || ActiveTask[id] || !CanBeTakenGift[i])
        return 
PLUGIN_HANDLED
    
if( is_user_alive(id) && cs_get_user_team(id)==CS_TEAM_CT && get_user_weapon(id)==CSW_KNIFE && get_user_buttonid ) & IN_ATTACK)
    {
        if( 
get_user_oldbuttonid ) & IN_ATTACK )
        {
            
log_to_file(drop_reg_dir,"touch_gift: found to take")
            
Bar_Time(id,GiftTime)
            
CanBeTakenGift[i]=false
            ActiveTask
[id]=true
            TakingEnt
[id]=ent
            TimerElement
[id]=0
            set_task
(0.5"Taking"id TakingTask_,_,"b")
        }
    }
    return 
PLUGIN_CONTINUE
}

public 
Taking(idTask)
{
    new 
id=idTask TakingTask
    
new Float:Player_Origin[3]
    new 
Float:Entity_Origin[3]
    new 
i=0
    
for (new j=0;j<MaxDrops;j++)
        if(
Id_ent[j]==TakingEnt[id])
            
i=j
    
if (is_user_alive(id))
        
entity_get_vector(idEV_VEC_originPlayer_Origin)
    if (
is_valid_ent(TakingEnt[id]) )
        
entity_get_vector(TakingEnt[id], EV_VEC_originEntity_Origin)
    if( 
is_user_alive(id) && is_valid_ent(TakingEnt[id]) && get_user_buttonid ) & IN_ATTACK  && get_user_weapon(id)==CSW_KNIFE && get_distance_f(Entity_OriginPlayer_Origin) <= GiftDistance)
    {
        if( 
get_user_oldbuttonid ) & IN_ATTACK )
        {
            
log_to_file(drop_reg_dir,"Taking: taking")
            
TimerElement[id]++
            if (
TimerElement[id]/2==GiftTime)
            {
                
log_to_file(drop_reg_dir,"Taking: taken")
                
ActiveTask[id]=false
                
if (is_valid_ent(TakingEnt[id]) )
                    
remove_entity(TakingEnt[id])
                
TakingEnt[id]=0
                
new GiftAward
                GiftAward 
random_num(1,100)
                new 
sMsg[128]
                if (
GiftAward<26)
                {
                    
Speed[id]=get_user_maxspeed(id)+SpeedBoost
                    set_user_maxspeed
(idSpeed[id])
                    
//format(sMsg, 127, "^x04Gracz ^x03%s ^x04ukonczyl mape w ^x03%02d:%02d", sName, TimerS[id] / 60, TimerS[id] % 60);
                    
format(sMsg127"^x01You collected supplies! You have ^x03[^x04+50speed^x03]^x01!")
                    
Speedied[id]=true
                
}
                else if (
GiftAward>25 && GiftAward<51)
                {
                    new 
Float:gravity get_user_gravity(id)
                    
Gravitie[id]=gravity*GravityBoost
                    set_user_gravity
(idGravitie[id])
                    
format(sMsg127"^x01You collected supplies! You have ^x03[^x04-10proc gravity^x03]^x01!")
                    
Gravitied[id]=true
                
}
                else if (
GiftAward>50 && GiftAward<76)
                {
                    new 
hp get_user_health(id)
                    
set_user_health(idhp+30)
                    
format(sMsg127"^x01You collected supplies! You have ^x03[^x04+30Hp^x03]^x01!")
                }
                else if (
GiftAward>75 && GiftAward<81)
                {
                    
set_user_health(idget_user_health(id)/2)
                    
format(sMsg127"^x01This is not a good supplies! You have ^x03[^x04 been poisoned^x03]^x01!")
                }
                else if (
GiftAward>80 && GiftAward<86)
                {            
                    
Speedied[id]=true
                    Gravitied
[id]=true        
                    Speed
[id]=get_user_maxspeed(id)+SpeedBoost
                    set_user_maxspeed
(idSpeed[id])
                    new 
Float:gravity get_user_gravity(id)
                    
Gravitie[id]=gravity*GravityBoost
                    set_user_gravity
(idGravitie[id])
                    new 
hp get_user_health(id)
                    
set_user_health(idhp+30)
                    
set_user_xp(idget_user_xp(id) +40)
                    
format(sMsg127"^x01You collected ultra supplies! You have ^x03[^x04+30Hp +50speed -10proc gravity +40XP^x03]^x01!")
                }
                else if (
GiftAward>85 && GiftAward<91)
                {
                    
format(sMsg127"^x01You collected Nothing! You have ^x03[^x04NOTHING^x03]^x01!")
                }
                else if (
GiftAward>90 && GiftAward<100)
                {
                    new 
XP get_user_xp(id)
                    
set_user_xp(idXP +40)
                    
format(sMsg127"^x01You collected supplies! You have ^x03[^x04+40XP^x03]^x01!")
                }
                else
                {
                    
Reborn[id]=true
                    format
(sMsg127"^x01You collected supplies! You have ^x03[^x04Reborn^x03]^x01!")
                }
                
ColorChat(id,sMsg)
                
remove_task(id TakingTask)
            }
        }
    }
    else
    {
        
log_to_file(drop_reg_dir,"Taking: not taken")
        
Bar_Time(id,0)
        
TakingEnt[id]=0
        ActiveTask
[id]=false
        CanBeTakenGift
[i]=true
        remove_task
(id TakingTask)
    }
}


public 
RebornAction(idTask)
{
    
log_to_file(drop_reg_dir,"RebornAction: Reborn active")
    new 
id idTask RebornTask
    
if (Reborn[id])
    {
        
spawn(id)
        
Reborn[id]=false
        set_task
(0.5,"SpawnAgain",id+SpawnTask)
    }
}
public 
SpawnAgain(idTask)
{
    
log_to_file(drop_reg_dir,"SpawnAgain: Reborned")
    new 
id=idTask SpawnTask
    spawn
(id)
    new 
sMsg[128]
    
format(sMsg,127,"^x03You can kill again?! ^x04Kill them all!")
    
ColorChat(id,sMsg)
}    

public 
DiedReborn()
{
    if(
ENABLE==1)
    {
        new 
victim_id read_data(2)
        if(
Reborn[victim_id])
        {
            
log_to_file(drop_reg_dir,"DiedReborn: Died")
            
set_task(5.0"RebornAction"victim_id+RebornTask)
        }
    }
}

public 
fw_EvCurWeaponid )
{
    if (
is_user_alive(id) && ENABLE==1)
    {
        if (
cs_get_user_team(id)==CS_TEAM_CT)
        {
            if (
Speedied[id] || Gravitied[id])
            {
                
log_to_file(drop_reg_dir,"fw_EvCurWeapon: swich weapon")
                if (
Speedied[id])
                    
set_user_maxspeed(idSpeed[id])
                if(
Gravitied[id])
                    
set_user_gravity(id,Gravitie[id])
            }
        }
    }



stock ColorChat(idsMessage[])
{
    new 
SayText get_user_msgid("SayText");
    if(
id == 0)
    {
        for(new 
133i++)
        {
            if(
is_user_connected(i))
            {
                
message_begin(MSG_ONESayText, { 00}, i)
                
write_byte(i);
                
write_string(sMessage);
                
message_end();
            }
        }
    }
    else
    {
        
message_begin(MSG_ONESayText, { 00}, id);
        
write_byte(id);
        
write_string(sMessage);
        
message_end();
    }
}

Bar_Time(idTime)
{
    
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("BarTime"),_id)
    
write_short(Time)
    
message_end()
}

public 
show_help(id)
{
    new 
motd[1501],iLen;
    
iLen formatex(motdsizeof motd 1,"<body bgcolor=#000000><font color=#98f5ff size=4><pre>");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""Naudojimosi instrukcija<font color=#ecd707 size=3>");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""Prasidejus raund per pirma minute bus ismesti 3 paketai, kuriuos gali paiimti tik zmones.");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""Paketa paimti galite pjausdydami ji greit su peiliu (MOUSE1). Paketas atsiranda paskui ");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""viena is zmoniu, jo eitame kelyje.");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""<font color=#98f5ff size=4> ");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""Paketo prizai:<font color=#ecd707 size=3>");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""25/100 tikimybes rasti +50 maksimalaus greicio");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""25/100 tikimybes rasti +30 hp");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""25/100 tikimybes rasti -10proc gravitacijos");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""9/100 tikimybes rasti +40 XP");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""5/100 tikimybes rasti ultra bonus (+50 greicio +30 hp -10proc gravitacijos +40XP");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""5/100 tikimybes, jog paketas bus tuscias");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""5/100 tikimybes, jog paketas uznuodydas (-50proc hp)");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""1/100 tikimybes rasti Reborn (prisikelima po mirties). Negalioja bunant paskutiniam gyvam.");

    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""<font color=#bd0101 size=6>");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""Laukiame pasiulymu forume:");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"%s^n""ismetamu daiktu , paketo modelio ir kita.​");
    
iLen += formatex(motd[iLen], (sizeof motd 1) - iLen,"</body></font></pre>");
    
show_motd(id,motd"Supplies info");



redivcram 11-08-2015 15:12

Re: Help, first plugin
 
Check for errors in server console or logs and post them here

Dyskiu 11-08-2015 15:30

Re: Help, first plugin
 
Quote:

Originally Posted by redivcram (Post 2361145)
Check for errors in server console or logs and post them here


That's the problem , there isn't any... there were some before, but i fixed that already. This plugin won't infect server for few maps and then shut it down. It is no sequence when it happens.

Any more suggestions ? :/ I'm lost...

Chihuahuax 11-08-2015 21:58

Re: Help, first plugin
 
By any chance are you testing this plugin on a server with bot(s)?

Dyskiu 11-09-2015 03:18

Re: Help, first plugin
 
Quote:

Originally Posted by Chihuahuax (Post 2361256)
By any chance are you testing this plugin on a server with bot(s)?


No. When i test it alone then i can play as long as i want, but with real people it sometimes happens...


All times are GMT -4. The time now is 18:12.

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