AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Player invisibility and speed problem (https://forums.alliedmods.net/showthread.php?t=252501)

Krtola 12-04-2014 09:11

Player invisibility and speed problem
 
When edit original plugin,I make this ( and work fine ):

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <biohazard>

#define PLUGIN "VIP ivisibility"
#define VERSION "1.0.1"
#define AUTHOR "NST"

#define VipFlag ADMIN_LEVEL_H

new const vip_invisible[] = "biohazard/vip_invisibility.wav"

const Float:invisible_time 15.0
const Float:invisible_timewait 55.0
const invisible_dmg 15
const invisible_alpha 10

new g_invisible[33], g_invisible_wait[33]

new 
g_maxplayers
new g_roundend

enum 
(+= 100)
{
    
TASK_INVISIBLE 2000,
    
TASK_WAIT_INVISIBLE
}

#define ID_INVISIBLE (taskid - TASK_INVISIBLE)
#define ID_WAIT_INVISIBLE (taskid - TASK_WAIT_INVISIBLE)

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("HLTV""event_round_start""a""1=0""2=0")
    
register_event("DeathMsg""Death""a")
    
    
register_logevent("logevent_round_end"2"1=Round_End")
    
    
register_clcmd("drop""cmd_invisible")
    
    
g_maxplayers get_maxplayers()
}

public 
plugin_precache()
{
    
precache_sound(vip_invisible)
}

public 
client_putinserver(id)
{
    
reset_value_player(id)
}

public 
client_disconnect(id)
{
    
reset_value_player(id)
}

public 
event_round_start()
{
    
g_roundend 0
    
    
for (new id=1id<=g_maxplayersid++)
    {
        if (!
is_user_connected(id)) continue;
        
        
reset_value_player(id)
    }
}

public 
logevent_round_end()
{
    
g_roundend 1
}

public 
Death()
{
    new 
victim read_data(2
    
reset_value_player(victim)
}

public 
event_infect(id)
{
        
reset_value_player(id)
}

public 
cmd_invisible(id)
{
    if (
g_roundend) return PLUGIN_CONTINUE
    
    
if (!is_user_alive(id) || is_user_zombie(id) || !(get_user_flags(id) & VipFlag)) return PLUGIN_CONTINUE

    
new health get_user_health(id) - invisible_dmg
    
if ((get_user_flags(id) & VipFlag) && health>&& !g_invisible[id] && !g_invisible_wait[id])
    {
        
g_invisible[id] = 1
        
        set_user_health
(idhealth)

        
set_user_rendering(id,kRenderFxGlowShell,20,20,20,kRenderTransAlphainvisible_alpha)

        
set_user_footsteps(id1)

                
client_cmd(id"spk %s"vip_invisible)
                            
        
set_task(invisible_time"RemoveInvisible"id+TASK_INVISIBLE)
        
        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_CONTINUE
}

public 
RemoveInvisible(taskid)
{
    new 
id ID_INVISIBLE
    
    g_invisible
[id] = 0
    
    set_user_rendering
(id)
    
set_user_footsteps(id0)
    
    
g_invisible_wait[id] = 1
    
    set_task
(invisible_timewait"RemoveWaitInvisible"id+TASK_WAIT_INVISIBLE)

        
client_print(idprint_center"Your invisibility is over.")
}

public 
RemoveWaitInvisible(taskid)
{
    new 
id ID_WAIT_INVISIBLE
    
    g_invisible_wait
[id] = 0

        client_print
(idprint_center"Your invisibility is ready. Press G to use it.")
}

reset_value_player(id)
{
    
g_invisible[id] = 0
    g_invisible_wait
[id] = 0
    
    remove_task
(id+TASK_INVISIBLE)
    
remove_task(id+TASK_WAIT_INVISIBLE)


This gives you a VIP player ( only humans ) invisibility ( when press G )
In the original this is zombie class,and also when is in invisibility that class have speed boost.
In my VIP version I delete that speed boost option because I do not know how to get back player normal speed when invisibility time pass.
How to Restore the player speed when the invisibility is over??
This is the original plugin:

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <zombieplague>

#define PLUGIN "NST Zombie Class Speed"
#define VERSION "1.0.1"
#define AUTHOR "NST"

new const zclass_name[] = "Light"
new const zclass_info[] = "Press G To Stealth"
new const zclass_model[] = "speed_zombi_origin"
new const zclass_clawmodel[] = "v_knife_speed_zombi.mdl"
new const zclass_clawmodel_invi[] = "models/zombie_plague/v_knife_speed_zombi_invisible.mdl"
const zclass_health 1000
const zclass_speed 295
const Float:zclass_gravity 0.7
const Float:zclass_knockback 6.0

new const zombie_sound_invisible[] = "zombie_plague/zombi_pressure_female.wav"

new idclass
const Float:invisible_time 10.0
const Float:invisible_timewait 10.0
const invisible_dmg 200
const Float:invisible_speed 215.0
const Float:invisible_gravity 0.9
const invisible_alpha 10

new g_invisible[33], g_invisible_wait[33]

new 
g_msgSayText
new g_maxplayers
new g_roundend

enum 
(+= 100)
{
    
TASK_INVISIBLE 2000,
    
TASK_WAIT_INVISIBLE,
    
TASK_INVISIBLE_SOUND,
    
TASK_BOT_USE_SKILL
}

#define ID_INVISIBLE (taskid - TASK_INVISIBLE)
#define ID_WAIT_INVISIBLE (taskid - TASK_WAIT_INVISIBLE)
#define ID_INVISIBLE_SOUND (taskid - TASK_INVISIBLE_SOUND)
#define ID_BOT_USE_SKILL (taskid - TASK_BOT_USE_SKILL)

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("HLTV""event_round_start""a""1=0""2=0")
    
register_event("DeathMsg""Death""a")
    
register_event("CurWeapon""EventCurWeapon""be""1=1")
    
register_logevent("logevent_round_end"2"1=Round_End")
    
    
register_clcmd("drop""cmd_invisible")
    
    
g_msgSayText get_user_msgid("SayText")
    
g_maxplayers get_maxplayers()
}

public 
plugin_precache()
{
    
precache_model(zclass_clawmodel_invi)
    
precache_sound(zombie_sound_invisible)
    
    
idclass zp_register_zombie_class(zclass_namezclass_infozclass_modelzclass_clawmodelzclass_healthzclass_speedzclass_gravityzclass_knockback)
}

public 
client_putinserver(id)
{
    
reset_value_player(id)
}

public 
client_disconnect(id)
{
    
reset_value_player(id)
}

public 
event_round_start()
{
    
g_roundend 0
    
    
for (new id=1id<=g_maxplayersid++)
    {
        if (!
is_user_connected(id)) continue;
        
        
reset_value_player(id)
    }
}

public 
logevent_round_end()
{
    
g_roundend 1
}

public 
Death()
{
    new 
victim read_data(2
    
reset_value_player(victim)
}

public 
EventCurWeapon(id)
{
    if(!
is_user_alive(id)) return PLUGIN_CONTINUE;
    
    if(
g_invisible[id]) set_user_maxspeed(idinvisible_speed);
    
    return 
PLUGIN_CONTINUE;
}

public 
zp_user_infected_post(id)
{
    
reset_value_player(id)
    
    if(
zp_get_user_nemesis(id)) return;
    
    if(
zp_get_user_zombie_class(id) == idclass)
    {
        if(
is_user_bot(id))
        {
            
set_task(random_float(5.0,15.0), "bot_use_skill"id+TASK_BOT_USE_SKILL)
            return
        }
        
        
zp_colored_print(id"^x04[ZP]^x01 Your skill is^x04 Stealth^x01. Cooldown^x04 %.1f ^x01seconds."invisible_timewait)
    }
}

public 
zp_user_humanized_post(id)
{
    
reset_value_player(id)
}

public 
zp_user_unfrozen(id)
{
    if(
g_invisible[id])
    {
        
set_user_rendering(id,kRenderFxGlowShell,20,20,20,kRenderTransAlphainvisible_alpha)
        
set_user_maxspeed(idinvisible_speed)
        
set_user_gravity(idinvisible_gravity)
    }
}

public 
cmd_invisible(id)
{
    if (
g_roundend) return PLUGIN_CONTINUE
    
    
if (!is_user_alive(id) || !zp_get_user_zombie(id) || zp_get_user_nemesis(id)) return PLUGIN_CONTINUE

    
new health get_user_health(id) - invisible_dmg
    
if (zp_get_user_zombie_class(id) == idclass && health>&& !g_invisible[id] && !g_invisible_wait[id])
    {
        
g_invisible[id] = 1
        
        set_wpnmodel
(id)
        
set_user_health(idhealth)
        
set_user_rendering(id,kRenderFxGlowShell,20,20,20,kRenderTransAlphainvisible_alpha)
        
set_user_footsteps(id1)
        
set_user_maxspeed(idinvisible_speed)
        
set_user_gravity(idinvisible_gravity)
        
PlayEmitSound(idzombie_sound_invisible)
        
        
set_task(invisible_time"RemoveInvisible"id+TASK_INVISIBLE)
        
set_task(2.0"InvisibleSound"id+TASK_INVISIBLE_SOUND__"b")

        
zp_colored_print(id"^x04[ZP]^x01 You will^x04 Stealth^x01 for^x04 %.1f ^x01seconds."invisible_time)
        
        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_CONTINUE
}

public 
bot_use_skill(taskid)
{
    new 
id ID_BOT_USE_SKILL
    
    
if (!is_user_alive(id)) return;

    
cmd_invisible(id)
    
    
set_task(random_float(5.0,15.0), "bot_use_skill"id+TASK_BOT_USE_SKILL)
}

public 
InvisibleSound(taskid)
{
    new 
id ID_INVISIBLE_SOUND
    
    
if (g_invisible[id]) PlayEmitSound(idzombie_sound_invisible)
    else 
remove_task(taskid)
}

public 
RemoveInvisible(taskid)
{
    new 
id ID_INVISIBLE
    
    g_invisible
[id] = 0
    
    set_wpnmodel
(id)
    
set_user_rendering(id)
    
set_user_footsteps(id0)
    
set_user_maxspeed(idfloat(zclass_speed))
    
set_user_gravity(idzclass_gravity)
    
zp_colored_print(id"^x04[ZP]^x01 Your^x04 Stealth^x01 skill is over.")
    
    
g_invisible_wait[id] = 1
    
    set_task
(invisible_timewait"RemoveWaitInvisible"id+TASK_WAIT_INVISIBLE)
}

public 
RemoveWaitInvisible(taskid)
{
    new 
id ID_WAIT_INVISIBLE
    
    g_invisible_wait
[id] = 0
    
    zp_colored_print
(id"^x04[ZP]^x01 Your skill^x04 Stealth^x01 is ready.")
}

set_wpnmodel(id)
{
    if (!
is_user_alive(id)) return;
    
    if (
get_user_weapon(id) == CSW_KNIFE)
    {
        if (
g_invisible[id])
        {
            
set_pev(idpev_viewmodel2zclass_clawmodel_invi)
        }
        else
        {
            static 
temp[100]
            
format(tempcharsmax(temp), "models/zombie_plague/%s"zclass_clawmodel)
            
set_pev(idpev_viewmodel2temp)
        }
    }    
}

PlayEmitSound(id, const sound[])
{
    
emit_sound(idCHAN_VOICEsound1.0ATTN_NORM0PITCH_NORM)
}

reset_value_player(id)
{
    
g_invisible[id] = 0
    g_invisible_wait
[id] = 0
    
    remove_task
(id+TASK_INVISIBLE)
    
remove_task(id+TASK_WAIT_INVISIBLE)
    
remove_task(id+TASK_BOT_USE_SKILL)
}

zp_colored_print(target, const message[], any:...)
{
    static 
buffer[512], iargscount
    argscount 
numargs()
    
    if (!
target)
    {
        static 
player
        
for (player 1player <= g_maxplayersplayer++)
        {
            if (!
is_user_connected(player))
                continue;
            
            static 
changed[5], changedcount
            changedcount 
0
            
            
for (2argscounti++)
            {
                if (
getarg(i) == LANG_PLAYER)
                {
                    
setarg(i0player)
                    
changed[changedcount] = i
                    changedcount
++
                }
            }
            
            
vformat(buffercharsmax(buffer), message3)
            
            
message_begin(MSG_ONE_UNRELIABLEg_msgSayText_player)
            
write_byte(player)
            
write_string(buffer)
            
message_end()
            
            for (
0changedcounti++)
                
setarg(changed[i], 0LANG_PLAYER)
        }
    }
    else
    {
        
vformat(buffercharsmax(buffer), message3)
        
        
message_begin(MSG_ONEg_msgSayText_target)
        
write_byte(target)
        
write_string(buffer)
        
message_end()
    }
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/ 

You should look on:
PHP Code:

public RemoveInvisible(taskid)
{
    new 
id ID_INVISIBLE
    
    g_invisible
[id] = 0
    
    set_wpnmodel
(id)
    
set_user_rendering(id)
    
set_user_footsteps(id0)
    
set_user_maxspeed(idfloat(zclass_speed))
    
set_user_gravity(idzclass_gravity)
    
zp_colored_print(id"^x04[ZP]^x01 Your^x04 Stealth^x01 skill is over.")
    
    
g_invisible_wait[id] = 1
    
    set_task
(invisible_timewait"RemoveWaitInvisible"id+TASK_WAIT_INVISIBLE)


Here we see that the zombie speed returned to normal.
PHP Code:

set_user_maxspeed(idfloat(zclass_speed)) 

I do not know how to do it for VIP ( human ) players?

Shiina.Mashiro 12-04-2014 10:41

Re: Player invisibility and speed problem
 
Did you try to create a variable for get_user_maxspeed?
PHP Code:

new Floatg_oldspeed 

PHP Code:

public cmd_invisible(id)
{
g_oldspeed get_user_maxspeed(id)
...


PHP Code:

public RemoveInvisible(taskid)
{
...
set_user_maxspeed(idg_oldspeed)
...



Krtola 12-05-2014 08:21

Re: Player invisibility and speed problem
 
Quote:

Originally Posted by Shiina.Mashiro (Post 2231124)
Did you try to create a variable for get_user_maxspeed?
PHP Code:

new Floatg_oldspeed 

PHP Code:

public cmd_invisible(id)
{
g_oldspeed get_user_maxspeed(id)
...


PHP Code:

public RemoveInvisible(taskid)
{
...
set_user_maxspeed(idg_oldspeed)
...



Ok,I try now,but during the ivisibility when change weapon I lose my speed immediately.
And I need that lasts throughout the all invisibility time.
I forgot to add
PHP Code:

register_event("CurWeapon""EventCurWeapon""be""1=1"

Now works fine. Thank you.

RateX 12-06-2014 06:05

Re: Player invisibility and speed problem
 
CurWeapon is still called more times than Ham_CS_Player_ResetMaxSpeed, literally after every shots and weapon changes, so use Ham_CS_Player_ResetMaxSpeed is recommended. Also, use ExecuteHamB when you want to change speed immediately.

Krtola 12-06-2014 12:14

Re: Player invisibility and speed problem
 
Quote:

Originally Posted by RateX (Post 2231709)
CurWeapon is still called more times than Ham_CS_Player_ResetMaxSpeed, literally after every shots and weapon changes, so use Ham_CS_Player_ResetMaxSpeed is recommended. Also, use ExecuteHamB when you want to change speed immediately.

Can you please do that for me,in this case (plugin). Then,I could teach with this example????

HamletEagle 12-06-2014 12:30

Re: Player invisibility and speed problem
 
Quote:

Originally Posted by RateX (Post 2231709)
CurWeapon is still called more times than Ham_CS_Player_ResetMaxSpeed, literally after every shots and weapon changes, so use Ham_CS_Player_ResetMaxSpeed is recommended. Also, use ExecuteHamB when you want to change speed immediately.

Do you know the difference between ExecuteHam and ExecuteHamB ? ExecuteHamB let other plugins to receive that call, but you may get into an infinite loop.

zmd94 12-06-2014 12:48

Re: Player invisibility and speed problem
 
It can be done easily by using Reward API. ;)

By the way, just read this: https://forums.alliedmods.net/showpo...2&postcount=11

Krtola 12-06-2014 13:14

Re: Player invisibility and speed problem
 
How does that affect on server (infinite loop)? What are the consequences?
@]zmd94,I will take a look

HamletEagle 12-06-2014 13:15

Re: Player invisibility and speed problem
 
Quote:

Originally Posted by Krtola (Post 2231883)
How does that affect on server (infinite loop)? What are the consequences?
@]zmd94,I will take a look

I said it's possible happen, not that it will. An infinite loop will crash the server, but it's unlikely to happen.

Krtola 12-06-2014 13:22

Re: Player invisibility and speed problem
 
Quote:

Originally Posted by HamletEagle (Post 2231885)
I said it's possible happen, not that it will. An infinite loop will crash the server, but it's unlikely to happen.

Does this mean that you're no recommending to be used (ExecuteHamB) ?
Is there some other function that has the same purpose as ExecuteHamB,but which can't cause infinite loop?


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

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