This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

rebuy on spawn


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
timecard
Member
Join Date: Oct 2005
Old 07-05-2016 , 09:56   rebuy on spawn
Reply With Quote #1

Is it possible to execute CS internal commands such as rebuy, autobuy, m4a1, ak47 using client_cmd()?

I tried registering the round restart event with
register_event("HLTV", "chk_autorebuy", "a", "1=0", "2=0")
then eventually calling client_cmd(entityid, "rebuy") if the user wants to have rebuy called automatically for them but it does nothing. However when I use a command like "rate ####", it works.

Is this because i'm registering the wrong event or is it not possible to call these commands?

Also to note I don't have any weapon restrictions plugin enabled I have admin, admincmd, adminhelp enabled.

Last edited by timecard; 07-05-2016 at 10:04.
timecard is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 07-05-2016 , 10:22   Re: rebuy on spawn
Reply With Quote #2

This is slowhacking.. not a good way to do it lol
KaLoIaN is offline
timecard
Member
Join Date: Oct 2005
Old 07-05-2016 , 10:31   Re: rebuy on spawn
Reply With Quote #3

I believe it's only considered slowhacking without users consent, I have a menu that asks them if they want auto rebuy enabled. The point of the plugin is to make things easier for new players on our public servers.

Last edited by timecard; 07-05-2016 at 10:37.
timecard is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 07-05-2016 , 11:53   Re: rebuy on spawn
Reply With Quote #4

Try saving the weapons he has in a variable and set these weapons again when he agrees to rzbuy them. I have no clue why "rebuy" isn't working. Maybe it's not the right command?
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
timecard
Member
Join Date: Oct 2005
Old 07-05-2016 , 12:32   Re: rebuy on spawn
Reply With Quote #5

Yeah I agree Napoleon that will probably be the next solution to this problem if no one can explain why it's not working, "rebuy" works when called by the client but not by client_cmd.

I thinking it has to do with timing of the hook like its called just before the user can buy so maybe there's another event I can register with that would work.

Hopefully someone can provide a little more insight into this.
timecard is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 07-05-2016 , 14:42   Re: rebuy on spawn
Reply With Quote #6

Quote:
Originally Posted by timecard View Post
Is it possible to execute CS internal commands such as rebuy, autobuy, m4a1, ak47 using client_cmd()?

I tried registering the round restart event with
register_event("HLTV", "chk_autorebuy", "a", "1=0", "2=0")
then eventually calling client_cmd(entityid, "rebuy") if the user wants to have rebuy called automatically for them but it does nothing. However when I use a command like "rate ####", it works.

Is this because i'm registering the wrong event or is it not possible to call these commands?

Also to note I don't have any weapon restrictions plugin enabled I have admin, admincmd, adminhelp enabled.
It's not considered slowhacking because it doesnt affect users cvars.

The problem is that you calling it too early because player wasn't spawned yet.
You need to add a delay (by using set_task) on newround and after that you execute client_cmd on players.

Try using this :

say in chat /rebuy and activate/deactivate autorebuy.

delay can be changed here :
#define DELAY_TIME 2.0

Dont put it too low or rebuy wont work.

PHP Code:
#include <amxmodx>

#define DELAY_TIME 2.0

new g_rebuy[33]

public 
plugin_init()
{
    
register_plugin("Auto Rebuy""1.0""siriusmd99");
    
    
register_event("HLTV""hook_NewRound""a""1=0""2=0");    
    
register_clcmd("say /rebuy""switch_autorebuy");
    
}

public 
client_disconnect(id)
    
g_rebuy[id] = false;

public 
client_connect(id)
    
g_rebuy[id] = false;    

public 
switch_autorebuy(id)
{
    
    
g_rebuy[id] = !g_rebuy[id]
    
client_print(idprint_chat"[AMXX] You have %s auto-rebuy."g_rebuy[id] ? "enabled" "disabled" )
    
}

public 
hook_NewRound()
{
    if(
task_exists())
        
remove_task()
    
set_task(DELAY_TIME"set_rebuy")    
}    

public 
set_rebuy()
{
    new 
players[32], numid;
    
get_players(playersnum"ac");
    for(new 
inumi++)
    {
        
id players[i];
        if(
g_rebuy[id])
            
client_cmd(id"rebuy")
    }  


Last edited by siriusmd99; 07-06-2016 at 14:43.
siriusmd99 is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 07-05-2016 , 16:44   Re: rebuy on spawn
Reply With Quote #7

Just try using Ham_Spawn on this one, i think that should do the trick...
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 07-05-2016 , 16:49   Re: rebuy on spawn
Reply With Quote #8

Quote:
Originally Posted by Napoleon_be View Post
Just try using Ham_Spawn on this one, i think that should do the trick...
He wants only on round start, but ham spawn is called in others cases.
For example when player has connected after 5 seconds round started.

I think it's more efficient to call one time function and loop all players than hooking every player spawn.
And you should test if you can execute rebuy right after ham spawn. I think here should be a delay too. So it will be more than 1 task in this case.
siriusmd99 is offline
timecard
Member
Join Date: Oct 2005
Old 07-05-2016 , 23:19   Re: rebuy on spawn
Reply With Quote #9

Thanks everyone, a delay after spawn fixed the issue. I'll upload the script in a bit, going to test it on our public server.

I went with
register_event("ResetHUD", "chk_autorebuy", "be")
and
delay of 0.5 for the task

Last edited by timecard; 07-05-2016 at 23:20.
timecard is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 07-06-2016 , 03:22   Re: rebuy on spawn
Reply With Quote #10

resethud is not called on spawn only, it can be called in other cases too.For example a player wants to record a demo and resethud is called but you need to call it only on round start.
Use round start and loop all players because you need to force this command only at round start.
There is no sense to set tasks for every single player if you can set just one task at round start and loo players. Loop into the code I provided above.

Last edited by siriusmd99; 07-06-2016 at 03:25.
siriusmd99 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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