AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SCript help, FIX Bug Please!! (https://forums.alliedmods.net/showthread.php?t=295257)

D3XT3R 03-20-2017 12:40

SCript help, FIX Bug Please!!
 
Hi i have problem in this code of gunxp supply boxes
it spawn in the map and player get it and player it get it and get random xp from 1-500
and it write
[GunXP] you found 200 XP

and some times its write
[GunXP] you found 120 XP
[GunXP] you found 54XP

in same box whitch player found so what i mean
i mean when player found it , some times (not always give 2 casses) its give him 2 casses in same time so i wanna fix it and get always give 1 case mean [GunXP] you found ...XP not troubling in it and thanx .

PHP Code:

public round_end() 

    if(!
total_presents) return 
    
remove_all_presents() 


public 
round_start() 

    if(!
total_presents) return 
    
remove_task(1337
    
set_task(get_pcvar_float(spawn_time), "spawn_random_presents"1337__"b"


public 
spawn_random_presents() 

    new 
num random_num(get_pcvar_num(min_presents),get_pcvar_num(max_presents)) 
    if(
num != 0) for(new ii=0;ii<num;ii++) spawn_present(present_data[random(total_presents)]) 


public 
present_touch(ent,id)
{
    
give_random_present(entid);
    return 
0;
}
        
public 
give_random_present(ent,id
{
    new 
xp 0;
    
xp random_num(1500);
    
set_user_xp(idget_user_xp(id) + xp);
    
ColorChat(id,GREEN,"^x04[^x03GunXP^x04]^x01 You Found^x04 %i^x01 XP!"xp);
    
emit_sound(ent,CHAN_AUTO,"supplyboxes/presents_get.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM);
    
remove_entity(ent



D3XT3R 03-20-2017 16:59

Re: SCript help Fix this Bug...
 
any help?

Natsheh 03-20-2017 23:35

Re: Other Simple SCript help :)
 
PHP Code:

public present_touch(ent,id

    if(!
pev_valid(ent)) return 0// check if its not the world or its a valid entity
    
if(is_user_alive(id)) give_random_present(entid); 
    return 
0


U might need to check if its a carepackage by it classname idk how ur hooking the touch

D3XT3R 03-21-2017 03:18

Re: Other Simple SCript help :)
 
hier full code ^^ i tired and i dont know what is misstake in it
i will explain simple more
when some one found box its get one case mean one ammount of xp for the box
but some times its get 2 casses in same box and it write in chat
[Gunxp] you found 12XP
[Gunxp] you found 350XP

and i want fix this bug, i want it give always only 1 case when player found it.
PHP Code:

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

#define OWNER_PRESENT_SPAWN ADMIN_RCON // Access level for gxm_ps_spawn command 
#define OWNER_PRESENT_REMOVE ADMIN_RCON // Access level for gxm_ps_remove command 
#define OWNER_PRESENT_STOP ADMIN_RCON // Access level for gxm_ps_stop command 
#define OWNER_PRESENT_START ADMIN_RCON // Access level for gxm_ps_start command 

#define PRESENT_LIMIT 100 // Maximum amount of presents 

new const present_model[] = "models/presents/usercs_present.mdl"
new const sound_spawn[] = "supplyboxes/presents_respawn.wav"
new const sound_get[] = "supplyboxes/presents_get.wav"

enum Color 
    
NORMAL 1
    
GREEN
    
TEAM_COLOR
    
GREY
    
RED
    
BLUE


new 
TeamName[][] = { 
    
""
    
"TERRORIST"
    
"CT"
    
"SPECTATOR" 


new 
file[78],total_presentsFloat:present_data[PRESENT_LIMIT 1][3], 
present_glow,present_light,present_light_radius,present_rot
spawn_time,min_presents,max_presents

public plugin_init()

    
register_plugin("[GunXP] Addon: Presents Supply Boxes","1.0","DeXTeR / Veco")
    
register_cvar("gxm_supply_boxes_version","1.0",FCVAR_SERVER FCVAR_SPONLY
    
present_glow register_cvar("gxm_ps_present_glow","1")
    
present_light register_cvar("gxm_ps_present_light","1")
    
present_light_radius register_cvar("gxm_ps_present_light_radius","8")
    
present_rot register_cvar("gxm_ps_present_rotate","1")
    
spawn_time register_cvar("gxm_ps_spawn_presents_time","30.0")
    
min_presents register_cvar("gxm_ps_min_spawn_presents","5"
    
max_presents register_cvar("gxm_ps_max_spawn_presents","10"
    
register_concmd("gxm_ps_spawn","Owner_Present_Spawn",OWNER_PRESENT_SPAWN
    
register_concmd("gxm_ps_remove","Owner_Present_Remove",OWNER_PRESENT_REMOVE
    
register_concmd("gxm_ps_stop","Owner_Present_Stop",OWNER_PRESENT_STOP
    
register_concmd("gxm_ps_start","Owner_Present_Start",OWNER_PRESENT_START
    
register_touch("info_present","player","present_touch"
    
register_think("info_present","present_think"
    
register_logevent("round_end",2,"1=Round_End")
    
register_logevent("round_start",2,"1=Round_Start")
     
    new 
mapname[32
    
get_mapname(mapname,31
    
format(file,77,"addons/amxmodx/configs/presents/%s.ini",mapname
     
    
load_presents() 


public 
plugin_precache()
{
    
precache_model(present_model)
    
precache_sound(sound_spawn)
    
precache_sound(sound_get)
}

public 
Owner_Present_Spawn(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    
if(total_presents == PRESENT_LIMIT
    { 
        
console_print(id,"[GunXP] Present limit exceeded! Maximum amount of presents is %i.",PRESENT_LIMIT
        return 
PLUGIN_HANDLED 
    

     
    new 
Float:origin[3
    
entity_get_vector(id,EV_VEC_origin,origin
     
    
origin[2] -= 30.0 
     
    save_present
(id,origin
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Remove(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
console_print(id,"[GunXP] All presents were removed for this round."
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Stop(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
total_presents 
    console_print
(id,"[GunXP] All presents were removed for this map."
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Start(id,level,cid

    if(!
cmd_access(id,level,cid,1) || total_presents 0) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
load_presents() 
    
console_print(id,"[GunXP] All presents were loaded for this map."
     
    return 
PLUGIN_HANDLED 


public 
round_end() 

    if(!
total_presents) return 
    
remove_all_presents() 


public 
round_start() 

    if(!
total_presents) return 
    
remove_task(1337
    
set_task(get_pcvar_float(spawn_time), "spawn_random_presents"1337__"b"


public 
spawn_random_presents() 

    new 
num random_num(get_pcvar_num(min_presents),get_pcvar_num(max_presents)) 
    if(
num != 0) for(new ii=0;ii<num;ii++) spawn_present(present_data[random(total_presents)]) 


public 
present_touch(ent,id)
{
    
give_random_present(entid);
    return 
0;
}
        
public 
give_random_present(ent,id
{
    new 
xp 0;
    
xp random_num(1500);
    
set_user_xp(idget_user_xp(id) + xp);
    
ColorChat(id,GREEN,"^x04[^x03GunXP^x04]^x01 You Found^x04 %i^x01 XP!"xp);
    
emit_sound(ent,CHAN_AUTO,"supplyboxes/presents_get.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM);
    
remove_entity(ent
}

public 
present_think(ent

    if(
get_pcvar_num(present_light)) 
    { 
        static 
Float:origin[3
        
entity_get_vector(ent,EV_VEC_origin,origin
         
        
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYorigin0
        
write_byte(TE_DLIGHT
        
engfunc(EngFunc_WriteCoordorigin[0]) 
        
engfunc(EngFunc_WriteCoordorigin[1]) 
        
engfunc(EngFunc_WriteCoordorigin[2]) 
        
write_byte(get_pcvar_num(present_light_radius)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser1)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser2)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser3)) 
        
write_byte(2
        
write_byte(0
        
message_end() 
    } 
     
    if(
get_pcvar_num(present_rot)) 
    { 
        static 
Float:angles[3
        
entity_get_vector(ent,EV_VEC_angles,angles
         
        
angles[1]-- 
         
        
entity_set_vector(ent,EV_VEC_angles,angles
    } 
     
    
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01


public 
remove_all_presents() remove_entity_name("info_present"


public 
load_presents() 

    
total_presents 
     
    
new buffer[128], x[12],y[12],z[12
    if(
file_exists(file)) 
    { 
        new 
save fopen(file,"rt"
         
        if(!
save) return 
         
        while(!
feof(save)) 
        { 
            
fgets(save,buffer,127
             
            if(
buffer[0] == ';' || !buffer[0]) continue 
             
            
parse(bufferx,11y,11z,11
             
            
present_data[total_presents][0] = str_to_float(x
            
present_data[total_presents][1] = str_to_float(y
            
present_data[total_presents][2] = str_to_float(z
             
            
total_presents++ 
        } 
         
        
fclose(save
    }     


public 
spawn_present(Float:origin[3]) 

    new 
ent create_entity("info_target"
    if(
ent
    { 
        
entity_set_string(ent,EV_SZ_classname,"info_present"
        
entity_set_model(ent,present_model
         
        
entity_set_int(ent,EV_INT_solid,SOLID_TRIGGER
        
entity_set_int(ent,EV_INT_movetype,MOVETYPE_TOSS
         
        
entity_set_float(ent,EV_FL_gravity,1.0
         
        if(
get_pcvar_num(present_glow)) 
        { 
            
entity_set_int(ent,EV_INT_iuser1,random(255)) 
            
entity_set_int(ent,EV_INT_iuser2,random(255)) 
            
entity_set_int(ent,EV_INT_iuser3,random(255)) 
             
            
set_rendering(ent,kRenderFxGlowShell,entity_get_int(ent,EV_INT_iuser1),entity_get_int(ent,EV_INT_iuser2),entity_get_int(ent,EV_INT_iuser3),kRenderNormal,60
        } 
         
        
entity_set_origin(ent,origin
         
        
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01
         
        
emit_sound(ent,CHAN_AUTO,"supplyboxes/presents_respawn.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM
    } 


public 
save_present(id,Float:origin[3]) 

    new 
save fopen(file,"at"
    if(
save
    { 
        
fprintf(save,"%.2f %.2f %.2f^n",origin[0],origin[1],origin[2]) 
        
fclose(save
         
        
console_print(id,"[GunXP] Present Spawn: successfully added at x:y:z(%.2f : %.2f : %.2f).",origin[0],origin[1],origin[2]) 
        
load_presents() 
    } 


ColorChat(idColor:type, const msg[], {FloatSqlResult,_}:...) { 
    new 
message[256

    switch(
type) { 
        case 
NORMALmessage[0] = 0x01 
        
case GREENmessage[0] = 0x04 
        
default: message[0] = 0x03 
    


    
vformat(message[1], 251msg4

    
message[192] = '^0' 

    
new teamColorChangeindexMSG_Type 

    
if(id) { 
        
MSG_Type MSG_ONE 
        index 
id 
    
} else { 
        
index FindPlayer() 
        
MSG_Type MSG_ALL 
    


    
team get_user_team(index
    
ColorChange ColorSelection(indexMSG_Typetype

    
ShowColorMessage(indexMSG_Typemessage

    if(
ColorChange
        
Team_Info(indexMSG_TypeTeamName[team]) 


ShowColorMessage(idtypemessage[]) { 
    static 
bool:saytext_used 
    
static get_user_msgid_saytext 

    
if(!saytext_used) { 
        
get_user_msgid_saytext get_user_msgid("SayText"
        
saytext_used true 
    


    
message_begin(typeget_user_msgid_saytext_id
    
write_byte(id
    
write_string(message
    
message_end() 


Team_Info(idtypeteam[]) { 
    static 
bool:teaminfo_used 
    
static get_user_msgid_teaminfo 

    
if(!teaminfo_used) { 
        
get_user_msgid_teaminfo get_user_msgid("TeamInfo"
        
teaminfo_used true 
    


    
message_begin(typeget_user_msgid_teaminfo_id
    
write_byte(id
    
write_string(team
    
message_end() 

    return 



ColorSelection(indextypeColor:Type) { 
    switch(
Type) { 
        case 
RED: return Team_Info(indextypeTeamName[1]) 
        case 
BLUE: return Team_Info(indextypeTeamName[2]) 
        case 
GREY: return Team_Info(indextypeTeamName[0]) 
    } 

    return 



FindPlayer() { 
    new 
= -

    
while(<= get_maxplayers()) { 
        if(
is_user_connected(++i)) 
            return 

    


    return -




D3XT3R 03-21-2017 04:39

Re: Other Simple SCript help :)
 
Quote:

Originally Posted by Natsheh (Post 2505285)
PHP Code:

public present_touch(ent,id

    if(!
pev_valid(ent)) return 0// check if its not the world or its a valid entity
    
if(is_user_alive(id)) give_random_present(entid); 
    return 
0


U might need to check if its a carepackage by it classname idk how ur hooking the touch

its same with that bug.... this not fix any thing... please fix :D

Depresie 03-21-2017 19:58

Re: SCript help, FIX Bug Please!!
 
Just a hunch, try and let me know if it works
PHP Code:

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

#define OWNER_PRESENT_SPAWN ADMIN_RCON // Access level for gxm_ps_spawn command 
#define OWNER_PRESENT_REMOVE ADMIN_RCON // Access level for gxm_ps_remove command 
#define OWNER_PRESENT_STOP ADMIN_RCON // Access level for gxm_ps_stop command 
#define OWNER_PRESENT_START ADMIN_RCON // Access level for gxm_ps_start command 

#define PRESENT_LIMIT 100 // Maximum amount of presents 

new const present_model[] = "models/presents/usercs_present.mdl"
new const sound_spawn[] = "supplyboxes/presents_respawn.wav"
new const sound_get[] = "supplyboxes/presents_get.wav"

enum Color 
    
NORMAL 1
    
GREEN
    
TEAM_COLOR
    
GREY
    
RED
    
BLUE


new 
TeamName[][] = { 
    
""
    
"TERRORIST"
    
"CT"
    
"SPECTATOR" 


new 
file[78],total_presentsFloat:present_data[PRESENT_LIMIT 1][3], 
present_glow,present_light,present_light_radius,present_rot
spawn_time,min_presents,max_presents

public plugin_init()

    
register_plugin("[GunXP] Addon: Presents Supply Boxes","1.0","DeXTeR / Alliedmodders")
    
register_cvar("gxm_supply_boxes_version","1.0",FCVAR_SERVER FCVAR_SPONLY
    
present_glow register_cvar("gxm_ps_present_glow","1")
    
present_light register_cvar("gxm_ps_present_light","1")
    
present_light_radius register_cvar("gxm_ps_present_light_radius","8")
    
present_rot register_cvar("gxm_ps_present_rotate","1")
    
spawn_time register_cvar("gxm_ps_spawn_presents_time","30.0")
    
min_presents register_cvar("gxm_ps_min_spawn_presents","5"
    
max_presents register_cvar("gxm_ps_max_spawn_presents","10"
    
register_concmd("gxm_ps_spawn","Owner_Present_Spawn",OWNER_PRESENT_SPAWN
    
register_concmd("gxm_ps_remove","Owner_Present_Remove",OWNER_PRESENT_REMOVE
    
register_concmd("gxm_ps_stop","Owner_Present_Stop",OWNER_PRESENT_STOP
    
register_concmd("gxm_ps_start","Owner_Present_Start",OWNER_PRESENT_START
    
register_touch("info_present","player","present_touch"
    
register_think("info_present","present_think"
    
register_logevent("round_end",2,"1=Round_End")
    
register_logevent("round_start",2,"1=Round_Start")
     
    new 
mapname[32
    
get_mapname(mapname,31
    
format(file,77,"addons/amxmodx/configs/presents/%s.ini",mapname
     
    
load_presents() 


public 
plugin_precache()
{
    
precache_model(present_model)
    
precache_sound(sound_spawn)
    
precache_sound(sound_get)
}

public 
Owner_Present_Spawn(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    
if(total_presents == PRESENT_LIMIT
    { 
        
console_print(id,"[GunXP] Present limit exceeded! Maximum amount of presents is %i.",PRESENT_LIMIT
        return 
PLUGIN_HANDLED 
    

     
    new 
Float:origin[3
    
entity_get_vector(id,EV_VEC_origin,origin
     
    
origin[2] -= 30.0 
     
    save_present
(id,origin
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Remove(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
console_print(id,"[GunXP] All presents were removed for this round."
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Stop(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
total_presents 
    console_print
(id,"[GunXP] All presents were removed for this map."
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Start(id,level,cid

    if(!
cmd_access(id,level,cid,1) || total_presents 0) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
load_presents() 
    
console_print(id,"[GunXP] All presents were loaded for this map."
     
    return 
PLUGIN_HANDLED 


public 
round_end() 

    if(!
total_presents) return 
    
remove_all_presents() 


public 
round_start() 

    if(!
total_presents) return 
    
remove_task(1337
    
set_task(get_pcvar_float(spawn_time), "spawn_random_presents"1337__"b"


public 
spawn_random_presents() 

    new 
num random_num(get_pcvar_num(min_presents),get_pcvar_num(max_presents)) 
    if(
num != 0) for(new ii=0;ii<num;ii++) spawn_present(present_data[random(total_presents)]) 


public 
present_touch(ent,id)
{
     
emit_sound(ent,CHAN_AUTO,"supplyboxes/presents_get.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM);
     
remove_entity(ent
     
     new 
xp 0;
    
xp random_num(1500);
    
set_user_xp(idget_user_xp(id) + xp);
    
ColorChat(id,GREEN,"^x04[^x03GunXP^x04]^x01 You Found^x04 %i^x01 XP!"xp);
}

public 
present_think(ent

    if(
get_pcvar_num(present_light)) 
    { 
        static 
Float:origin[3
        
entity_get_vector(ent,EV_VEC_origin,origin
         
        
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYorigin0
        
write_byte(TE_DLIGHT
        
engfunc(EngFunc_WriteCoordorigin[0]) 
        
engfunc(EngFunc_WriteCoordorigin[1]) 
        
engfunc(EngFunc_WriteCoordorigin[2]) 
        
write_byte(get_pcvar_num(present_light_radius)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser1)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser2)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser3)) 
        
write_byte(2
        
write_byte(0
        
message_end() 
    } 
     
    if(
get_pcvar_num(present_rot)) 
    { 
        static 
Float:angles[3
        
entity_get_vector(ent,EV_VEC_angles,angles
         
        
angles[1]-- 
         
        
entity_set_vector(ent,EV_VEC_angles,angles
    } 
     
    
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01


public 
remove_all_presents() remove_entity_name("info_present"


public 
load_presents() 

    
total_presents 
     
    
new buffer[128], x[12],y[12],z[12
    if(
file_exists(file)) 
    { 
        new 
save fopen(file,"rt"
         
        if(!
save) return 
         
        while(!
feof(save)) 
        { 
            
fgets(save,buffer,127
             
            if(
buffer[0] == ';' || !buffer[0]) continue 
             
            
parse(bufferx,11y,11z,11
             
            
present_data[total_presents][0] = str_to_float(x
            
present_data[total_presents][1] = str_to_float(y
            
present_data[total_presents][2] = str_to_float(z
             
            
total_presents++ 
        } 
         
        
fclose(save
    }     


public 
spawn_present(Float:origin[3]) 

    new 
ent create_entity("info_target"
    if(
ent
    { 
        
entity_set_string(ent,EV_SZ_classname,"info_present"
        
entity_set_model(ent,present_model
         
        
entity_set_int(ent,EV_INT_solid,SOLID_TRIGGER
        
entity_set_int(ent,EV_INT_movetype,MOVETYPE_TOSS
         
        
entity_set_float(ent,EV_FL_gravity,1.0
         
        if(
get_pcvar_num(present_glow)) 
        { 
            
entity_set_int(ent,EV_INT_iuser1,random(255)) 
            
entity_set_int(ent,EV_INT_iuser2,random(255)) 
            
entity_set_int(ent,EV_INT_iuser3,random(255)) 
             
            
set_rendering(ent,kRenderFxGlowShell,entity_get_int(ent,EV_INT_iuser1),entity_get_int(ent,EV_INT_iuser2),entity_get_int(ent,EV_INT_iuser3),kRenderNormal,60
        } 
         
        
entity_set_origin(ent,origin
         
        
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01
         
        
emit_sound(ent,CHAN_AUTO,"supplyboxes/presents_respawn.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM
    } 


public 
save_present(id,Float:origin[3]) 

    new 
save fopen(file,"at"
    if(
save
    { 
        
fprintf(save,"%.2f %.2f %.2f^n",origin[0],origin[1],origin[2]) 
        
fclose(save
         
        
console_print(id,"[GunXP] Present Spawn: successfully added at x:y:z(%.2f : %.2f : %.2f).",origin[0],origin[1],origin[2]) 
        
load_presents() 
    } 


ColorChat(idColor:type, const msg[], {FloatSqlResult,_}:...) { 
    new 
message[256

    switch(
type) { 
        case 
NORMALmessage[0] = 0x01 
        
case GREENmessage[0] = 0x04 
        
default: message[0] = 0x03 
    


    
vformat(message[1], 251msg4

    
message[192] = '^0' 

    
new teamColorChangeindexMSG_Type 

    
if(id) { 
        
MSG_Type MSG_ONE 
        index 
id 
    
} else { 
        
index FindPlayer() 
        
MSG_Type MSG_ALL 
    


    
team get_user_team(index
    
ColorChange ColorSelection(indexMSG_Typetype

    
ShowColorMessage(indexMSG_Typemessage

    if(
ColorChange
        
Team_Info(indexMSG_TypeTeamName[team]) 


ShowColorMessage(idtypemessage[]) { 
    static 
bool:saytext_used 
    
static get_user_msgid_saytext 

    
if(!saytext_used) { 
        
get_user_msgid_saytext get_user_msgid("SayText"
        
saytext_used true 
    


    
message_begin(typeget_user_msgid_saytext_id
    
write_byte(id
    
write_string(message
    
message_end() 


Team_Info(idtypeteam[]) { 
    static 
bool:teaminfo_used 
    
static get_user_msgid_teaminfo 

    
if(!teaminfo_used) { 
        
get_user_msgid_teaminfo get_user_msgid("TeamInfo"
        
teaminfo_used true 
    


    
message_begin(typeget_user_msgid_teaminfo_id
    
write_byte(id
    
write_string(team
    
message_end() 

    return 



ColorSelection(indextypeColor:Type) { 
    switch(
Type) { 
        case 
RED: return Team_Info(indextypeTeamName[1]) 
        case 
BLUE: return Team_Info(indextypeTeamName[2]) 
        case 
GREY: return Team_Info(indextypeTeamName[0]) 
    } 

    return 



FindPlayer() { 
    new 
= -

    
while(<= get_maxplayers()) { 
        if(
is_user_connected(++i)) 
            return 

    


    return -




D3XT3R 03-22-2017 08:24

Re: SCript help, FIX Bug Please!!
 
tested and stile buggy
it some times give 2 casses mean problem not in toche function like i think maybe some thing wroung or smting

Depresie 03-22-2017 11:05

Re: SCript help, FIX Bug Please!!
 
Try this, let me know if it works..

I think the problem is coming from touch, the touch hook is called a second time before the entity is removed

PHP Code:

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

#define OWNER_PRESENT_SPAWN ADMIN_RCON // Access level for gxm_ps_spawn command 
#define OWNER_PRESENT_REMOVE ADMIN_RCON // Access level for gxm_ps_remove command 
#define OWNER_PRESENT_STOP ADMIN_RCON // Access level for gxm_ps_stop command 
#define OWNER_PRESENT_START ADMIN_RCON // Access level for gxm_ps_start command 

#define PRESENT_LIMIT 100 // Maximum amount of presents 

new const present_model[] = "models/presents/usercs_present.mdl"
new const sound_spawn[] = "supplyboxes/presents_respawn.wav"
new const sound_get[] = "supplyboxes/presents_get.wav"

enum Color 
    
NORMAL 1
    
GREEN
    
TEAM_COLOR
    
GREY
    
RED
    
BLUE


new 
TeamName[][] = { 
    
""
    
"TERRORIST"
    
"CT"
    
"SPECTATOR" 


new 
file[78],total_presentsFloat:present_data[PRESENT_LIMIT 1][3], 
present_glow,present_light,present_light_radius,present_rot
spawn_time,min_presents,max_presents

new g_RecievedReward[33]

public 
plugin_init()

    
register_plugin("[GunXP] Addon: Presents Supply Boxes","1.0","DeXTeR / Alliedmodders")
    
register_cvar("gxm_supply_boxes_version","1.0",FCVAR_SERVER FCVAR_SPONLY
    
present_glow register_cvar("gxm_ps_present_glow","1")
    
present_light register_cvar("gxm_ps_present_light","1")
    
present_light_radius register_cvar("gxm_ps_present_light_radius","8")
    
present_rot register_cvar("gxm_ps_present_rotate","1")
    
spawn_time register_cvar("gxm_ps_spawn_presents_time","30.0")
    
min_presents register_cvar("gxm_ps_min_spawn_presents","5"
    
max_presents register_cvar("gxm_ps_max_spawn_presents","10"
    
register_concmd("gxm_ps_spawn","Owner_Present_Spawn",OWNER_PRESENT_SPAWN
    
register_concmd("gxm_ps_remove","Owner_Present_Remove",OWNER_PRESENT_REMOVE
    
register_concmd("gxm_ps_stop","Owner_Present_Stop",OWNER_PRESENT_STOP
    
register_concmd("gxm_ps_start","Owner_Present_Start",OWNER_PRESENT_START
    
register_touch("info_present","player","present_touch"
    
register_think("info_present","present_think"
    
register_logevent("round_end",2,"1=Round_End")
    
register_logevent("round_start",2,"1=Round_Start")
     
    new 
mapname[32
    
get_mapname(mapname,31
    
format(file,77,"addons/amxmodx/configs/presents/%s.ini",mapname
     
    
load_presents() 


public 
plugin_precache()
{
    
precache_model(present_model)
    
precache_sound(sound_spawn)
    
precache_sound(sound_get)
}

public 
Owner_Present_Spawn(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    
if(total_presents == PRESENT_LIMIT
    { 
        
console_print(id,"[GunXP] Present limit exceeded! Maximum amount of presents is %i.",PRESENT_LIMIT
        return 
PLUGIN_HANDLED 
    

     
    new 
Float:origin[3
    
entity_get_vector(id,EV_VEC_origin,origin
     
    
origin[2] -= 30.0 
     
    save_present
(id,origin
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Remove(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
console_print(id,"[GunXP] All presents were removed for this round."
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Stop(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
total_presents 
    console_print
(id,"[GunXP] All presents were removed for this map."
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Start(id,level,cid

    if(!
cmd_access(id,level,cid,1) || total_presents 0) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
load_presents() 
    
console_print(id,"[GunXP] All presents were loaded for this map."
     
    return 
PLUGIN_HANDLED 


public 
round_end() 

    if(!
total_presents) return 
    
remove_all_presents() 


public 
round_start() 

    if(!
total_presents) return 
    
remove_task(1337
    
set_task(get_pcvar_float(spawn_time), "spawn_random_presents"1337__"b"


public 
spawn_random_presents() 

    new 
num random_num(get_pcvar_num(min_presents),get_pcvar_num(max_presents)) 
    if(
num != 0) for(new ii=0;ii<num;ii++) spawn_present(present_data[random(total_presents)]) 


public 
present_touch(ent,id)
{
    if(
g_RecievedReward[id]) return;
    
    
g_RecievedReward[id] = true
    
    give_random_present
(entid);
    return 
0;
}
        
public 
give_random_present(ent,id
{
    new 
xp 0;
    
xp random_num(1500);
    
set_user_xp(idget_user_xp(id) + xp);
    
ColorChat(id,GREEN,"^x04[^x03GunXP^x04]^x01 You Found^x04 %i^x01 XP!"xp);
    
emit_sound(ent,CHAN_AUTO,"supplyboxes/presents_get.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM);
    
remove_entity(ent
    
    
g_RecievedReward[id] = false
    
}

public 
present_think(ent

    if(
get_pcvar_num(present_light)) 
    { 
        static 
Float:origin[3
        
entity_get_vector(ent,EV_VEC_origin,origin
         
        
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYorigin0
        
write_byte(TE_DLIGHT
        
engfunc(EngFunc_WriteCoordorigin[0]) 
        
engfunc(EngFunc_WriteCoordorigin[1]) 
        
engfunc(EngFunc_WriteCoordorigin[2]) 
        
write_byte(get_pcvar_num(present_light_radius)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser1)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser2)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser3)) 
        
write_byte(2
        
write_byte(0
        
message_end() 
    } 
     
    if(
get_pcvar_num(present_rot)) 
    { 
        static 
Float:angles[3
        
entity_get_vector(ent,EV_VEC_angles,angles
         
        
angles[1]-- 
         
        
entity_set_vector(ent,EV_VEC_angles,angles
    } 
     
    
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01


public 
remove_all_presents() remove_entity_name("info_present"


public 
load_presents() 

    
total_presents 
     
    
new buffer[128], x[12],y[12],z[12
    if(
file_exists(file)) 
    { 
        new 
save fopen(file,"rt"
         
        if(!
save) return 
         
        while(!
feof(save)) 
        { 
            
fgets(save,buffer,127
             
            if(
buffer[0] == ';' || !buffer[0]) continue 
             
            
parse(bufferx,11y,11z,11
             
            
present_data[total_presents][0] = str_to_float(x
            
present_data[total_presents][1] = str_to_float(y
            
present_data[total_presents][2] = str_to_float(z
             
            
total_presents++ 
        } 
         
        
fclose(save
    }     


public 
spawn_present(Float:origin[3]) 

    new 
ent create_entity("info_target"
    if(
ent
    { 
        
entity_set_string(ent,EV_SZ_classname,"info_present"
        
entity_set_model(ent,present_model
         
        
entity_set_int(ent,EV_INT_solid,SOLID_TRIGGER
        
entity_set_int(ent,EV_INT_movetype,MOVETYPE_TOSS
         
        
entity_set_float(ent,EV_FL_gravity,1.0
         
        if(
get_pcvar_num(present_glow)) 
        { 
            
entity_set_int(ent,EV_INT_iuser1,random(255)) 
            
entity_set_int(ent,EV_INT_iuser2,random(255)) 
            
entity_set_int(ent,EV_INT_iuser3,random(255)) 
             
            
set_rendering(ent,kRenderFxGlowShell,entity_get_int(ent,EV_INT_iuser1),entity_get_int(ent,EV_INT_iuser2),entity_get_int(ent,EV_INT_iuser3),kRenderNormal,60
        } 
         
        
entity_set_origin(ent,origin
         
        
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01
         
        
emit_sound(ent,CHAN_AUTO,"supplyboxes/presents_respawn.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM
    } 


public 
save_present(id,Float:origin[3]) 

    new 
save fopen(file,"at"
    if(
save
    { 
        
fprintf(save,"%.2f %.2f %.2f^n",origin[0],origin[1],origin[2]) 
        
fclose(save
         
        
console_print(id,"[GunXP] Present Spawn: successfully added at x:y:z(%.2f : %.2f : %.2f).",origin[0],origin[1],origin[2]) 
        
load_presents() 
    } 


ColorChat(idColor:type, const msg[], {FloatSqlResult,_}:...) { 
    new 
message[256

    switch(
type) { 
        case 
NORMALmessage[0] = 0x01 
        
case GREENmessage[0] = 0x04 
        
default: message[0] = 0x03 
    


    
vformat(message[1], 251msg4

    
message[192] = '^0' 

    
new teamColorChangeindexMSG_Type 

    
if(id) { 
        
MSG_Type MSG_ONE 
        index 
id 
    
} else { 
        
index FindPlayer() 
        
MSG_Type MSG_ALL 
    


    
team get_user_team(index
    
ColorChange ColorSelection(indexMSG_Typetype

    
ShowColorMessage(indexMSG_Typemessage

    if(
ColorChange
        
Team_Info(indexMSG_TypeTeamName[team]) 


ShowColorMessage(idtypemessage[]) { 
    static 
bool:saytext_used 
    
static get_user_msgid_saytext 

    
if(!saytext_used) { 
        
get_user_msgid_saytext get_user_msgid("SayText"
        
saytext_used true 
    


    
message_begin(typeget_user_msgid_saytext_id
    
write_byte(id
    
write_string(message
    
message_end() 


Team_Info(idtypeteam[]) { 
    static 
bool:teaminfo_used 
    
static get_user_msgid_teaminfo 

    
if(!teaminfo_used) { 
        
get_user_msgid_teaminfo get_user_msgid("TeamInfo"
        
teaminfo_used true 
    


    
message_begin(typeget_user_msgid_teaminfo_id
    
write_byte(id
    
write_string(team
    
message_end() 

    return 



ColorSelection(indextypeColor:Type) { 
    switch(
Type) { 
        case 
RED: return Team_Info(indextypeTeamName[1]) 
        case 
BLUE: return Team_Info(indextypeTeamName[2]) 
        case 
GREY: return Team_Info(indextypeTeamName[0]) 
    } 

    return 



FindPlayer() { 
    new 
= -

    
while(<= get_maxplayers()) { 
        if(
is_user_connected(++i)) 
            return 

    


    return -




D3XT3R 03-22-2017 11:19

Re: SCript help, FIX Bug Please!!
 
has error
it not compile
line 149 function press ...ent toche.. should return a value
line 154 functions use return and retun value

Depresie 03-22-2017 12:40

Re: SCript help, FIX Bug Please!!
 
PHP Code:

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

#define OWNER_PRESENT_SPAWN ADMIN_RCON // Access level for gxm_ps_spawn command 
#define OWNER_PRESENT_REMOVE ADMIN_RCON // Access level for gxm_ps_remove command 
#define OWNER_PRESENT_STOP ADMIN_RCON // Access level for gxm_ps_stop command 
#define OWNER_PRESENT_START ADMIN_RCON // Access level for gxm_ps_start command 

#define PRESENT_LIMIT 100 // Maximum amount of presents 

new const present_model[] = "models/presents/usercs_present.mdl"
new const sound_spawn[] = "supplyboxes/presents_respawn.wav"
new const sound_get[] = "supplyboxes/presents_get.wav"

enum Color 
    
NORMAL 1
    
GREEN
    
TEAM_COLOR
    
GREY
    
RED
    
BLUE


new 
TeamName[][] = { 
    
""
    
"TERRORIST"
    
"CT"
    
"SPECTATOR" 


new 
file[78],total_presentsFloat:present_data[PRESENT_LIMIT 1][3], 
present_glow,present_light,present_light_radius,present_rot
spawn_time,min_presents,max_presents

new g_RecievedReward[33]

public 
plugin_init()

    
register_plugin("[GunXP] Addon: Presents Supply Boxes","1.0","DeXTeR / Alliedmodders")
    
register_cvar("gxm_supply_boxes_version","1.0",FCVAR_SERVER FCVAR_SPONLY
    
present_glow register_cvar("gxm_ps_present_glow","1")
    
present_light register_cvar("gxm_ps_present_light","1")
    
present_light_radius register_cvar("gxm_ps_present_light_radius","8")
    
present_rot register_cvar("gxm_ps_present_rotate","1")
    
spawn_time register_cvar("gxm_ps_spawn_presents_time","30.0")
    
min_presents register_cvar("gxm_ps_min_spawn_presents","5"
    
max_presents register_cvar("gxm_ps_max_spawn_presents","10"
    
register_concmd("gxm_ps_spawn","Owner_Present_Spawn",OWNER_PRESENT_SPAWN
    
register_concmd("gxm_ps_remove","Owner_Present_Remove",OWNER_PRESENT_REMOVE
    
register_concmd("gxm_ps_stop","Owner_Present_Stop",OWNER_PRESENT_STOP
    
register_concmd("gxm_ps_start","Owner_Present_Start",OWNER_PRESENT_START
    
register_touch("info_present","player","present_touch"
    
register_think("info_present","present_think"
    
register_logevent("round_end",2,"1=Round_End")
    
register_logevent("round_start",2,"1=Round_Start")
     
    new 
mapname[32
    
get_mapname(mapname,31
    
format(file,77,"addons/amxmodx/configs/presents/%s.ini",mapname
     
    
load_presents() 


public 
plugin_precache()
{
    
precache_model(present_model)
    
precache_sound(sound_spawn)
    
precache_sound(sound_get)
}

public 
Owner_Present_Spawn(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    
if(total_presents == PRESENT_LIMIT
    { 
        
console_print(id,"[GunXP] Present limit exceeded! Maximum amount of presents is %i.",PRESENT_LIMIT
        return 
PLUGIN_HANDLED 
    

     
    new 
Float:origin[3
    
entity_get_vector(id,EV_VEC_origin,origin
     
    
origin[2] -= 30.0 
     
    save_present
(id,origin
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Remove(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
console_print(id,"[GunXP] All presents were removed for this round."
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Stop(id,level,cid

    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
total_presents 
    console_print
(id,"[GunXP] All presents were removed for this map."
     
    return 
PLUGIN_HANDLED 


public 
Owner_Present_Start(id,level,cid

    if(!
cmd_access(id,level,cid,1) || total_presents 0) return PLUGIN_HANDLED 
     
    remove_all_presents
() 
    
load_presents() 
    
console_print(id,"[GunXP] All presents were loaded for this map."
     
    return 
PLUGIN_HANDLED 


public 
round_end() 

    if(!
total_presents) return 
    
remove_all_presents() 


public 
round_start() 

    if(!
total_presents) return 
    
remove_task(1337
    
set_task(get_pcvar_float(spawn_time), "spawn_random_presents"1337__"b"


public 
spawn_random_presents() 

    new 
num random_num(get_pcvar_num(min_presents),get_pcvar_num(max_presents)) 
    if(
num != 0) for(new ii=0;ii<num;ii++) spawn_present(present_data[random(total_presents)]) 


public 
present_touch(ent,id)
{
    if(
g_RecievedReward[id]) return 0;
    
    
g_RecievedReward[id] = true
    
    give_random_present
(entid);
    return 
0;
}
        
public 
give_random_present(ent,id
{
    new 
xp 0;
    
xp random_num(1500);
    
set_user_xp(idget_user_xp(id) + xp);
    
ColorChat(id,GREEN,"^x04[^x03GunXP^x04]^x01 You Found^x04 %i^x01 XP!"xp);
    
emit_sound(ent,CHAN_AUTO,"supplyboxes/presents_get.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM);
    
remove_entity(ent
    
    
g_RecievedReward[id] = false
    
}

public 
present_think(ent

    if(
get_pcvar_num(present_light)) 
    { 
        static 
Float:origin[3
        
entity_get_vector(ent,EV_VEC_origin,origin
         
        
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYorigin0
        
write_byte(TE_DLIGHT
        
engfunc(EngFunc_WriteCoordorigin[0]) 
        
engfunc(EngFunc_WriteCoordorigin[1]) 
        
engfunc(EngFunc_WriteCoordorigin[2]) 
        
write_byte(get_pcvar_num(present_light_radius)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser1)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser2)) 
        
write_byte(entity_get_int(ent,EV_INT_iuser3)) 
        
write_byte(2
        
write_byte(0
        
message_end() 
    } 
     
    if(
get_pcvar_num(present_rot)) 
    { 
        static 
Float:angles[3
        
entity_get_vector(ent,EV_VEC_angles,angles
         
        
angles[1]-- 
         
        
entity_set_vector(ent,EV_VEC_angles,angles
    } 
     
    
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01


public 
remove_all_presents() remove_entity_name("info_present"


public 
load_presents() 

    
total_presents 
     
    
new buffer[128], x[12],y[12],z[12
    if(
file_exists(file)) 
    { 
        new 
save fopen(file,"rt"
         
        if(!
save) return 
         
        while(!
feof(save)) 
        { 
            
fgets(save,buffer,127
             
            if(
buffer[0] == ';' || !buffer[0]) continue 
             
            
parse(bufferx,11y,11z,11
             
            
present_data[total_presents][0] = str_to_float(x
            
present_data[total_presents][1] = str_to_float(y
            
present_data[total_presents][2] = str_to_float(z
             
            
total_presents++ 
        } 
         
        
fclose(save
    }     


public 
spawn_present(Float:origin[3]) 

    new 
ent create_entity("info_target"
    if(
ent
    { 
        
entity_set_string(ent,EV_SZ_classname,"info_present"
        
entity_set_model(ent,present_model
         
        
entity_set_int(ent,EV_INT_solid,SOLID_TRIGGER
        
entity_set_int(ent,EV_INT_movetype,MOVETYPE_TOSS
         
        
entity_set_float(ent,EV_FL_gravity,1.0
         
        if(
get_pcvar_num(present_glow)) 
        { 
            
entity_set_int(ent,EV_INT_iuser1,random(255)) 
            
entity_set_int(ent,EV_INT_iuser2,random(255)) 
            
entity_set_int(ent,EV_INT_iuser3,random(255)) 
             
            
set_rendering(ent,kRenderFxGlowShell,entity_get_int(ent,EV_INT_iuser1),entity_get_int(ent,EV_INT_iuser2),entity_get_int(ent,EV_INT_iuser3),kRenderNormal,60
        } 
         
        
entity_set_origin(ent,origin
         
        
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01
         
        
emit_sound(ent,CHAN_AUTO,"supplyboxes/presents_respawn.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM
    } 


public 
save_present(id,Float:origin[3]) 

    new 
save fopen(file,"at"
    if(
save
    { 
        
fprintf(save,"%.2f %.2f %.2f^n",origin[0],origin[1],origin[2]) 
        
fclose(save
         
        
console_print(id,"[GunXP] Present Spawn: successfully added at x:y:z(%.2f : %.2f : %.2f).",origin[0],origin[1],origin[2]) 
        
load_presents() 
    } 


ColorChat(idColor:type, const msg[], {FloatSqlResult,_}:...) { 
    new 
message[256

    switch(
type) { 
        case 
NORMALmessage[0] = 0x01 
        
case GREENmessage[0] = 0x04 
        
default: message[0] = 0x03 
    


    
vformat(message[1], 251msg4

    
message[192] = '^0' 

    
new teamColorChangeindexMSG_Type 

    
if(id) { 
        
MSG_Type MSG_ONE 
        index 
id 
    
} else { 
        
index FindPlayer() 
        
MSG_Type MSG_ALL 
    


    
team get_user_team(index
    
ColorChange ColorSelection(indexMSG_Typetype

    
ShowColorMessage(indexMSG_Typemessage

    if(
ColorChange
        
Team_Info(indexMSG_TypeTeamName[team]) 


ShowColorMessage(idtypemessage[]) { 
    static 
bool:saytext_used 
    
static get_user_msgid_saytext 

    
if(!saytext_used) { 
        
get_user_msgid_saytext get_user_msgid("SayText"
        
saytext_used true 
    


    
message_begin(typeget_user_msgid_saytext_id
    
write_byte(id
    
write_string(message
    
message_end() 


Team_Info(idtypeteam[]) { 
    static 
bool:teaminfo_used 
    
static get_user_msgid_teaminfo 

    
if(!teaminfo_used) { 
        
get_user_msgid_teaminfo get_user_msgid("TeamInfo"
        
teaminfo_used true 
    


    
message_begin(typeget_user_msgid_teaminfo_id
    
write_byte(id
    
write_string(team
    
message_end() 

    return 



ColorSelection(indextypeColor:Type) { 
    switch(
Type) { 
        case 
RED: return Team_Info(indextypeTeamName[1]) 
        case 
BLUE: return Team_Info(indextypeTeamName[2]) 
        case 
GREY: return Team_Info(indextypeTeamName[0]) 
    } 

    return 



FindPlayer() { 
    new 
= -

    
while(<= get_maxplayers()) { 
        if(
is_user_connected(++i)) 
            return 

    


    return -





All times are GMT -4. The time now is 17:50.

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