Raised This Month: $51 Target: $400
 12% 

Just out of curiosity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
1sh0t2killz
Senior Member
Join Date: Dec 2004
Old 07-12-2009 , 17:14   Just out of curiosity
Reply With Quote #1

I've read somewhere a tutorial somewhere in here that the set_task function should try to be avoided if possible. So I've taken Gohan as an example here. I've modified his loop function to use a different method that doesn't require the set_task function. Basically, my question is: Is this method better than the set_task method? By better I mean, more efficient and requires less memory for the server. They basically do the same thing in game, but still.. I want to know so I can help better my server.

Code:
// GOHAN! - from Dragon Ball Z, Goku and Chi Chi's first son.

/* CVARS - copy and paste to shconfig.cfg

//Gohan
gohan_level 10
gohan_health 150		//default 150
gohan_gravity 0.40		//default 0.40 = low gravity
gohan_speed 800		//How fast he is with all weapons
gohan_healpoints 10		//The # of HP healed per second
gohan_healmax 400		//Max # HP gohan can heal to
gohan_healcooldown 1		//Gohan heals x number of hp per this number in seconds

*/

/*
* v1.2 - vittu - 6/19/05
*      - Minor code clean up.
*
* v1.1 - vittu - 3/13/05
*      - recoded from ArtofDrowning07 cleaned up code
*      - new cvar from ArtofDrowning07, gohan_healmax, you
*         can choose how much goten will heal to now
*/

#include <amxmod>
#include <superheromod>

// GLOBAL VARIABLES
new gHeroName[]="Gohan"
new bool:ghasGohanPowers[SH_MAXSLOTS+1]
new gHealPoints, gHealAmount
//----------------------------------------------------------------------------------------------
public plugin_init()
{
	// Plugin Info
	register_plugin("SUPERHERO Gohan", "1.2", "sharky")

	// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
	register_cvar("gohan_level", "10")
	register_cvar("gohan_health", "150")
	register_cvar("gohan_gravity", "0.40")
	register_cvar("gohan_speed", "800")
	register_cvar("gohan_healpoints", "10")
	register_cvar("gohan_healmax", "400")
	register_cvar("gohan_healcooldown", "1")

	// FIRE THE EVENT TO CREATE THIS SUPERHERO!
	shCreateHero(gHeroName, "Super Power-Up", "Start with more HP, gain even more each second. Also, has Ultra Speed and Low Gravity!", false, "gohan_level")

	// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
	// INIT
	register_srvcmd("gohan_init", "gohan_init")
	shRegHeroInit(gHeroName, "gohan_init")

	// Instead of the original heal loop that uses set_task
	// we use FM_PlayerPreThink
	register_forward(FM_PlayerPreThink, "gohan_think")

	// Let Server know about Gohan's Variables
	shSetMaxHealth(gHeroName, "gohan_health")
	shSetMinGravity(gHeroName, "gohan_gravity")
	shSetMaxSpeed(gHeroName, "gohan_speed", "[0]")

	//Set Varibles when plugin loads
	gHealPoints = get_cvar_num("gohan_healpoints")
	gHealAmount = get_cvar_num("gohan_healmax")
}
//----------------------------------------------------------------------------------------------
public gohan_init()
{
	// First Argument is an id
	new temp[6]
	read_argv(1,temp,5)
	new id = str_to_num(temp)

	// 2nd Argument is 0 or 1 depending on whether the id has the hero
	read_argv(2,temp,5)
	new hasPowers = str_to_num(temp)

	//This gets run if they had the power but don't anymore
	if ( !hasPowers && ghasGohanPowers[id] && is_user_alive(id) ) {
		shRemHealthPower(id)
		shRemGravityPower(id)
		shRemSpeedPower(id)
	}

	//Sets this variable to the current status
	ghasGohanPowers[id] = (hasPowers != 0)
}
//----------------------------------------------------------------------------------------------
//Instead of using set_task
public sh_client_spawn(id)
{
	if ( ghasGohanPowers[id] ) {
		gPlayerInCooldown[id] = false
	}
}
public gohan_think(id)
{
	if ( !shModActive() || !hasRoundStarted() ) return

	if ( ghasGohanPowers[id] && is_user_alive(id) ) {
		new Float:healcooldown = get_cvar_float("gohan_healcooldown")
		if (!gPlayerInCooldown[id])
		{
			shAddHPs(id, gHealPoints, gHealAmount)

			if ( healcooldown > 0.0 ) sh_set_cooldown(id, healcooldown)
		}
	}
}
//----------------------------------------------------------------------------------------------
__________________
I ♥ ⌂ ♫
1sh0t2killz is offline
DarkGod
SourceMod DarkCrab
Join Date: Jul 2007
Location: Sweden
Old 07-12-2009 , 17:33   Re: Just out of curiosity
Reply With Quote #2

Code:
#include <amxmod> #include <superheromod>

lol

I think that prethink is worse to use than set_task.
__________________
DarkGod is offline
Send a message via AIM to DarkGod Send a message via MSN to DarkGod
1sh0t2killz
Senior Member
Join Date: Dec 2004
Old 07-12-2009 , 18:03   Re: Just out of curiosity
Reply With Quote #3

Quote:
Originally Posted by DarkGod View Post
Code:
#include <amxmod> #include <superheromod>

lol

I think that prethink is worse to use than set_task.
Oh I forgot to mention, before you guys start flaming about how theres stupid and unimportant things such as that.. I only changed the method of healing. everything else is UNCHANGED, meaning its not my fault that amxmod is included... nor is it relevant to anything.

EDIT: Also, a logical reason why which method is better than the other would be good to hear.
__________________
I ♥ ⌂ ♫

Last edited by 1sh0t2killz; 07-12-2009 at 18:14.
1sh0t2killz is offline
yang
Veteran Member
Join Date: May 2005
Location: galoreservers.net
Old 07-12-2009 , 20:00   Re: Just out of curiosity
Reply With Quote #4

set_task to loop say 0.1 sec client_print something

then use prethink but for prethink client_print something else. You will see why o.O
__________________
yang is offline
Send a message via AIM to yang
1sh0t2killz
Senior Member
Join Date: Dec 2004
Old 07-12-2009 , 22:33   Re: Just out of curiosity
Reply With Quote #5

nice! I got my answer. I'll just stick to using the set_task function haha, thanks. =)
__________________
I ♥ ⌂ ♫
1sh0t2killz is offline
Supervoodoo
Member
Join Date: Jul 2009
Location: Bulgaria
Old 07-17-2009 , 17:27   Re: Just out of curiosity
Reply With Quote #6

set_task Is Much More Easier Than Prethink If You ask me
Supervoodoo is offline
Send a message via Skype™ to Supervoodoo
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 16:18.


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