Raised This Month: $ Target: $400
 0% 

two basic questions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-23-2013 , 13:31   two basic questions
Reply With Quote #1

1st Q. What is the most efficient way of seting the first set_task?

Example 1.
PHP Code:
public plugin_init() 
{    
   
set_task 20.0"Taskworker"50""0);
}
public 
firsTtask(id)
{

     
// code here..
}
public 
Taskworker () 
{
   new 
players[32], numplayersid;
   
get_players playersnumplayers );
   for ( new 
i=0i<numplayersi++ ) {
   
id=players[i];
   
firsTtaskid );
 }

or

Example 2.
PHP Code:
public client_putinserver(id
{
          
set_task(15.0,"firsTtask",id)
}
public 
firsTtask(id)
{

     
// code here..

2nd Q. what is an less resource hungry method to flip an switch?
using an bool variable per client or introducing an new client cvar?

Last edited by vamppa; 07-23-2013 at 13:37.
vamppa is offline
EpicMonkey
buttmonkey
Join Date: Feb 2012
Old 07-23-2013 , 16:35   Re: two basic questions
Reply With Quote #2

Depends on what you're trying to do / the situation
EpicMonkey is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-23-2013 , 19:24   Re: two basic questions
Reply With Quote #3

Those two codes do not do the same thing and therefore cannot be compared. You cannot create client variables (other than setinfo if you are still able to access it but it is limited and should be avoided).
__________________
fysiks is offline
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-23-2013 , 20:42   Re: two basic questions
Reply With Quote #4

why should setinfo be avoided?
and I can not create an client cvar or client variable?

PHP Code:
register_cvar("spec_auto","0"
PHP Code:
#define SCREENSHOT_PER_DEATHS random_num( 1, 35) 

new bool:g_bDeathScreenShotTaken[33] <----

public 
plugin_init() 

    
register_event("DeathMsg" "xDeathMsg" "a"); 


public 
client_putinserver(id

    
g_bDeathScreenShotTaken[id] = false 


public 
xDeathMsg()  
{  
    new 
id read_data(2)  
    if ( !
g_bDeathScreenShotTaken[id] && ! (++gDeaths[id] % SCREENSHOT_PER_DEATHS) )  
    {  
          
client_cmd(id"snapshot")  
          
g_bDeathScreenShotTaken[id] = true 
    
}  

In what ways are the first two code examples different?
the first: setting an global timed task from the server then cycling through the users to get an ID?
the 2nd: setting an user timed task directly on id? (does the set_task in this example use the clients CPU for calculating when to fire off the task aswell?

Last edited by vamppa; 07-23-2013 at 20:49.
vamppa is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-23-2013 , 23:08   Re: two basic questions
Reply With Quote #5

Quote:
Originally Posted by vamppa View Post
why should setinfo be avoided?
and I can not create an client cvar or client variable?

PHP Code:
register_cvar("spec_auto","0"
That has absolutely nothing to do with the client. It is server-side only only.


Quote:
Originally Posted by vamppa View Post
In what ways are the first two code examples different?
the first: setting an global timed task from the server then cycling through the users to get an ID?
the 2nd: setting an user timed task directly on id? (does the set_task in this example use the clients CPU for calculating when to fire off the task aswell?
You will need to think about when the functions are actually going to be called. More specifically, as an example, think about if everybody has to download a big map and a bunch of sound files and takes more than 20 seconds. If using the first code, nothing will happen to anyone but in the second one, the task will execute for each player 15 seconds after they are put in the server regardless of when they get in the server.
__________________
fysiks is offline
Old 07-24-2013, 01:07
LordOfNothing
This message has been deleted by ConnorMcLeod. Reason: troll, or posting random confusing code, or posting for posts count
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-24-2013 , 13:16   Re: two basic questions
Reply With Quote #6

thanks lordofnothing
ok so there is no such an thing as registering an client cvar?
and for client put in server I can easily add this to that right?

PHP Code:
public plugin_init() 
{    
   
set_task 20.0"Taskworker"50""0);
}
public 
client_putinserver(id)
{
    
firsTtask(id)
}
public 
firsTtask(id)
{

     
// code here..
}
public 
Taskworker () 
{
   new 
players[32], numplayersid;
   
get_players playersnumplayers );
   for ( new 
i=0i<numplayersi++ ) {
   
id=players[i];
   
firsTtaskid );
 }

</span></span>
vamppa is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2013 , 14:17   Re: two basic questions
Reply With Quote #7

Quote:
Originally Posted by LordOfNothing View Post
Situation One si more efficently in more more situation
This answer is WRONG. You cannot compare them.

Quote:
Originally Posted by vamppa View Post
ok so there is no such an thing as registering an client cvar?
No. You need to explain what you are trying to do if you want help.


Quote:
Originally Posted by vamppa View Post
for client put in server I can easily add this to that right?

PHP Code:
public plugin_init() 
{    
   
set_task 20.0"Taskworker"50""0);
}
public 
client_putinserver(id)
{
    
firsTtask(id)
}
public 
firsTtask(id)
{

     
// code here..
}
public 
Taskworker () 
{
   new 
players[32], numplayersid;
   
get_players playersnumplayers );
   for ( new 
i=0i<numplayersi++ ) {
   
id=players[i];
   
firsTtaskid );
 }

</span></span>
Probably not. It will depend on what you are trying to do. In most situations, that will not work correctly.
__________________
fysiks is offline
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-24-2013 , 15:17   Re: two basic questions
Reply With Quote #8

ok for the cvar
PHP Code:
public plugin_init() 

    
register_clcmd("notready","specc"
    
register_clcmd("spectate","readyy")
    
register_cvar("spec_auto","0")
    
set_task(15.0,"Taskworker"50""0);
}
public 
Taskworker () 
{
   new 
players[32], numplayersid;
   
get_players playersnumplayers );
   for ( new 
i=0i<numplayersi++ ) {
   
id=players[i];
   
first_taskid );
 }
}
public 
first_task(id) {
    
    switch(
get_cvar_num("spec_auto")){
    case 
1specc(id)
    case 
0client_cmd(id"echo Ehll - Type notready into console when you want to stay in spectate mode, note: on mapchange this will automatically set you into spectate mode!")  
    }
}
public 
specc(id
{  
    
//if(get_cvar_num("spec_auto") == 1)
    
if (!Isspectate(id) ){
    
client_cmd(id"spectate");
    }
    
client_cmd(id"spec_auto 1");

public 
readyy(id
{  
    
//if(get_cvar_num("spec_auto") == 1)
    
if (Isspectate(id) ){
    
client_cmd(id"spec_auto 0");
    }

basically it is this plugin request: https://forums.alliedmods.net/showthread.php?t=220676
had an feeling register_cvar("spec_auto","0") would be an server only cvar, but ofcourse testing this locally it works.
how can I handle it so it will actually work on an hosted server?
ive tried with an bool variable instead of the cvar but didn't work.
maybe I forgot something that makes it worth to try it again but its time consuming.
considering the other couple of things I got left to do : )

Last edited by vamppa; 07-24-2013 at 15:17.
vamppa is offline
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-24-2013 , 15:20   Re: two basic questions
Reply With Quote #9

ps. sometimes it is difficult for me to give out examples due to two reasons.
a) theres wanker in our community stealing my ideas and code then releasing as if it was his own, without leaving any credits.
b) cheaters that create specific hax I dont want to help out neither with any possibility so as easy thumb rule I keep on changing some things after I posted code.
vamppa is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2013 , 18:57   Re: two basic questions
Reply With Quote #10

Quote:
Originally Posted by vamppa View Post
ok for the cvar
PHP Code:
public plugin_init() 

    
register_clcmd("notready","specc"
    
register_clcmd("spectate","readyy")
    
register_cvar("spec_auto","0")
    
set_task(15.0,"Taskworker"50""0);
}
public 
Taskworker () 
{
   new 
players[32], numplayersid;
   
get_players playersnumplayers );
   for ( new 
i=0i<numplayersi++ ) {
   
id=players[i];
   
first_taskid );
 }
}
public 
first_task(id) {
    
    switch(
get_cvar_num("spec_auto")){
    case 
1specc(id)
    case 
0client_cmd(id"echo Ehll - Type notready into console when you want to stay in spectate mode, note: on mapchange this will automatically set you into spectate mode!")  
    }
}
public 
specc(id
{  
    
//if(get_cvar_num("spec_auto") == 1)
    
if (!Isspectate(id) ){
    
client_cmd(id"spectate");
    }
    
client_cmd(id"spec_auto 1");

public 
readyy(id
{  
    
//if(get_cvar_num("spec_auto") == 1)
    
if (Isspectate(id) ){
    
client_cmd(id"spec_auto 0");
    }

had an feeling register_cvar("spec_auto","0") would be an server only cvar, but ofcourse testing this locally it works.
how can I handle it so it will actually work on an hosted server?
ive tried with an bool variable instead of the cvar but didn't work.
maybe I forgot something that makes it worth to try it again but its time consuming.
considering the other couple of things I got left to do : )
You don't understand what a cvar actually is. It works when you test it on at listen server (when you click "New Game") because you are the server. You should be testing your code on a dedicated server (preferably a standalone dedicated server installed using SteamCMD). You can easily install it on your computer and then join it to test your plugin.


Quote:
Originally Posted by vamppa View Post
basically it is this plugin request: https://forums.alliedmods.net/showthread.php?t=220676
IMO, that request doesn't make any sense.


Quote:
Originally Posted by vamppa View Post
ps. sometimes it is difficult for me to give out examples due to two reasons.
a) theres wanker in our community stealing my ideas and code then releasing as if it was his own, without leaving any credits.
b) cheaters that create specific hax I dont want to help out neither with any possibility
a) Cry about it? Nobody who has common sense will want to steal this plugin.
b) Cheaters can't make hacks based on your plugins unless you have coded it to be able to be hacked.

Quote:
Originally Posted by vamppa View Post
so as easy thumb rule I keep on changing some things after I posted code.
So, we should just stop helping you then . . . ?
__________________
fysiks 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 06:24.


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