Raised This Month: $ Target: $400
 0% 

VERY irksum problem -solved-


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-04-2012 , 01:56   VERY irksum problem -solved-
Reply With Quote #1

Ok....so i did a little fooling around after i knew it worked, so i could get it to work a little easier. But now it doesn't do relatively ANYTHING.

Code:
public setPowers(id) {     client_print(id, print_chat, "Set Powers has been executed. This is number 1.")     if(!is_user_connected(id) || !get_pcvar_num(toggle_pcvar) || !get_pcvar_num(frags_pcvar) )         return -1     static level, serverGravity     static Float:speed, Float:gravity     level = getLevel(id)     speed = get_user_maxspeed(id) + get_pcvar_num(speed_pcvar)             // NOTE: it is REQUIRED to use get_cvar_num() to get external CVARs; pcvar is for internal pointers only     serverGravity = get_cvar_num("sv_gravity")     gravity = (LOW_GRAVITY * 800) / serverGravity   // Calculation for proper gravity with server gravity incorperated             // Set Powerups Message on HUD     // Variables for controlling the HUD message     new pus[32]     // X location for HUD, Y location for HUD, DURATION of message     const Float:X = 0.26     const Float:Y = 0.9     const Float:duration = 10.0         set_hudmessage(181, 181, 181, X, Y, 0, 1.0, duration, 0.1, 0.2, .channel=1)     //formatex(pus, charsmax(pus), "%L:", id, "PU_STD") client_print(id, print_chat, "Set Powers has been executed. This is number 2. Your level: %d", level)     switch(level)     {         case -1:         {             client_print(id, print_chat, "Your level has been executed as -1. Level: %d", level)             return PLUGIN_HANDLED   // this is error state of client         }         case 0:         {             formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_LOW")             client_print(id, print_chat, "Set Powers has been executed. This is level 0.")         }         case 1: formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_NORMAL")         case 2:         {   // Run faster             set_user_maxspeed(id, speed)             formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_SPEED")         }         case 3:         {   // jump higher             set_user_gravity(id, gravity)             set_user_maxspeed(id, speed)             formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_GRAVITY")         }         case 4: formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_DAMAGE")         // case 5: power ups     /*#if defined INSTAKILL         case INSTAKILL:         {             formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_INSTAKILL")         }     #endif*/         default:         {             client_print(id, print_chat, "Set Powers has been executed. Default case used.")             if(level > 3)             {                   set_user_gravity(id, gravity)                 set_user_maxspeed(id, speed)             }         #if defined INSTAKILL             if(level < INSTAKILL)                 formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_DAMAGE")             else //(level > INSTAKILL                 formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_INSTAKILL")         #else             formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_DAMAGE")         #endif         }     }     ShowSyncHudMsg(id, g_PowerHud, pus) // show hud message of powers     client_print(id, print_chat, "Set Powers has been executed. This is number 3. Hud should have been displayed")             //////////// This stuff starts the forward of setPowers     new iReturn     if(!ExecuteForward(g_spForward, iReturn, id/*, g_PowerHud, X, Y, duration*/) )     {         client_print(id, print_chat, "Something done fucked up trying to trigger forward.")         log_amx("[BKF] Could not execute estPowers")     }     else         client_print(id, print_chat, "Forward has been triggered in SetPowers")     /////////// This is the end of forward functinality     return level }

In order to figure out what was going wrong i put in hella print statements as debugs. and it only prints up to "Set Powers has been executed. This is number 2. Your level: %d" I have print statements in the place where my level is (0) but it doesn't print it. Does anyone see what i'm missing? No compilation errors or warnings. And nothing in the error logs.


EDIT: Ok.....so it is confirmed that the above function does break it. Because after i went on a comment spree it worked. This is a working function. Now.....what broke it!?
Also....it doesn't show the hud message.
Code:
public setPowers(id)
{
	client_print(id, print_chat, "Set Powers has been executed. This is number 1.")
	if(!is_user_connected(id) || !get_pcvar_num(toggle_pcvar) || !get_pcvar_num(frags_pcvar) )
		return -1

	static level, serverGravity
	static Float:speed, Float:gravity
	level = getLevel(id)
	speed = get_user_maxspeed(id) + get_pcvar_num(speed_pcvar)
	
	    // NOTE: it is REQUIRED to use get_cvar_num() to get external CVARs; pcvar is for internal pointers only
	serverGravity = get_cvar_num("sv_gravity")
	gravity = (LOW_GRAVITY * 800) / serverGravity	// Calculation for proper gravity with server gravity incorperated
	
		// Set Powerups Message on HUD
	// Variables for controlling the HUD message
	//new pus[32]
	new const pus[] = "This woks, yes?"
	// X location for HUD, Y location for HUD, DURATION of message
	const Float:X = 0.26
	const Float:Y = 0.9
	const Float:duration = 10.0
	
	set_hudmessage(181, 181, 181, X, Y, 0, 1.0, duration, 0.1, 0.2, .channel=1)
	//formatex(pus, charsmax(pus), "%L:", id, "PU_STD")
client_print(id, print_chat, "Set Powers has been executed. This is number 2. Your level: %d", level)
	switch(level)
	{
		case -1: 
		{
			client_print(id, print_chat, "Your level has been executed as -1. Level: %d", level)
			//return PLUGIN_HANDLED	// this is error state of client
		}
		case 0: 
		{
		//	formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_LOW")
			client_print(id, print_chat, "Set Powers has been executed. This is level 0.")
		}
		//case 1: formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_NORMAL")
		case 2:
		{	// Run faster
			set_user_maxspeed(id, speed)
		//	formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_SPEED")
		}
		case 3:
		{	// jump higher
			set_user_gravity(id, gravity)
			set_user_maxspeed(id, speed)
	//		formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_GRAVITY")
		}
	//	case 4: formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_DAMAGE")
		// case 5: power ups
	/*#if defined INSTAKILL
		case INSTAKILL:
		{
			formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_INSTAKILL")
		}
	#endif*/
		default: 
		{
			client_print(id, print_chat, "Set Powers has been executed. Default case used.")
			if(level > 3)
			{	
				set_user_gravity(id, gravity)
				set_user_maxspeed(id, speed)
			}
	/*	#if defined INSTAKILL
			if(level < INSTAKILL)
	//			formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_DAMAGE")
			else //(level > INSTAKILL
	//			formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_INSTAKILL")
		#else
	//		formatex(pus, charsmax(pus), "%L: %L", id, "PU_STD", id, "PU_DAMAGE")
		#endif
	*/	}
	}
	ShowSyncHudMsg(id, g_PowerHud, pus)	// show hud message of powers
	client_print(id, print_chat, "Set Powers has been executed. This is number 3. Hud should have been displayed")
		
	//////////// This stuff starts the forward of setPowers
	new iReturn
	if(!ExecuteForward(g_spForward, iReturn, id/*, g_PowerHud, X, Y, duration*/) )
	{
		client_print(id, print_chat, "Something done fucked up trying to trigger forward.")
		log_amx("[BKF] Could not execute estPowers")
	}
	else
		client_print(id, print_chat, "Forward has been triggered in SetPowers")
	/////////// This is the end of forward functinality

	return level
}
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 07-04-2012 at 13:44. Reason: Added the working function
Liverwiz is offline
Old 07-04-2012, 05:16
OvidiuS
This message has been deleted by OvidiuS. Reason: mistake
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 07-04-2012 , 08:03   Re: VERY irksum problem
Reply With Quote #2

PHP Code:
level getLevel(id
can you post the getLevel() function?
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-04-2012 , 10:32   Re: VERY irksum problem
Reply With Quote #3

As you wish......but it works fine. Even by the plugin that -used- to call it. Now everything is broken, and i'm pretty sure its the above mentioned function.

Code:
stock getLevel(id)  // RETURNS: -1 if off or error {     // returns the level of of the player, based on their frags (default is 31 frags per level)     if(get_pcvar_num(frags_pcvar) == 0 || !is_user_connected(id))         return -1             static frags, Float:f_calc     frags = gi_playerFrags[id]         if(frags <= LVL0)         return 0     else if(frags <= LVL1)         return 1     else if(frags <= LVL2)         return 2     else if(frags <= LVL3)         return 3     else if(frags <= LVL4)         return 4     else if(frags <= LVL5)         return 5     else     {   //LevelOffset = LVL5 - (LEVEL_INCREMENT*5)         f_calc =  (frags + LevelOffset) / float(LEVEL_INCREMENT)         return floatround(f_calc, floatround_floor)     }     return -1 }
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 07-04-2012 at 10:33.
Liverwiz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-04-2012 , 10:43   Re: VERY irksum problem
Reply With Quote #4

Any errors? Are you sure you didn't rename your plugin or anything and maybe you're running an old copy? If you want to give me the entire plugin I will try to figure it out for you.

You should try to keep your variable types consistent, ie. when working with floats\integers you should use that type in the entire statement.
PHP Code:
const Float:LOW_GRAVITY 500.0

static Float:serverGravityFloat:gravity

//even though sv_gravity is an integer, you can still use get_cvar_float() to return it as a float.
serverGravity get_cvar_float("sv_gravity")
gravity = (LOW_GRAVITY 800.0) / serverGravity 
If you will be retrieving sv_gravity multiple times, it would be best to do use a global var to store its pointer then use pcvar to retrieve.

PHP Code:
new g_pGravity

//plugin_init()
g_pGravity get_cvar_pointer"sv_gravity" )

get_pcvar_floatg_pGravity 
Is there a reason why you declare all of your variables static?
__________________

Last edited by Bugsy; 07-04-2012 at 10:54.
Bugsy is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-04-2012 , 11:12   Re: VERY irksum problem
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
Any errors? Are you sure you didn't rename your plugin or anything and maybe you're running an old copy? If you want to give me the entire plugin I will try to figure it out for you.
No errors. Neither compile time, nor run time. It just simply doesn't work. I'd love for you to check out the code. I'll attach all 2k lines. God speed.
I'm aware of how sub-par code it is. But its pretty complex, and pawn doesn't make splitting up programs into separate classes easy. So i do what i can.
You can see old, working, code at this thread. Before i added the API
http://forums.alliedmods.net/showthread.php?t=185404
If you PM me i can also give you the IP to the test server (running the version i attached)

Quote:
Originally Posted by Bugsy View Post
You should try to keep your variable types consistent, ie. when working with floats\integers you should use that type in the entire statement.
PHP Code:
const Float:LOW_GRAVITY 500.0

static Float:serverGravityFloat:gravity

//even though sv_gravity is an integer, you can still use get_cvar_float() to return it as a float.
serverGravity get_cvar_float("sv_gravity")
gravity = (LOW_GRAVITY 800.0) / serverGravity 
If you will be retrieving sv_gravity multiple times, it would be best to do use a global var to store its pointer then use pcvar to retrieve.

PHP Code:
new g_pGravity

//plugin_init()
g_pGravity get_cvar_pointer"sv_gravity" )

get_pcvar_floatg_pGravity 
That's a great idea. Could you show me how to retrieve the CVAR, then store its pointer? I've never heard of doing that.

Quote:
Originally Posted by Bugsy View Post
Is there a reason why you declare all of your variables static?
I do because its faster. Check out Exolent's tut on data types. static declarations just reserve memory space, and aren't zero'd when they come into scope. Because zeroing is the biggest performance hit, i avoid it when i can.


EDIT: i edited the first post to include the -fixedish- function. Also added some notes above it. wtf?
Attached Files
File Type: sma Get Plugin or Get Source (frags_brass.sma - 537 views - 66.3 KB)
File Type: inc colorchat.inc (5.9 KB, 85 views)
File Type: zip bkf.zip (413.8 KB, 61 views)
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 07-04-2012 at 12:43.
Liverwiz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-04-2012 , 11:22   Re: VERY irksum problem
Reply With Quote #6

Quote:
Originally Posted by Liverwiz View Post
No errors. Neither compile time, nor run time. It just simply doesn't work. I'd love for you to check out the code. I'll attach all 2k lines. God speed.
I'm aware of how sub-par code it is. But its pretty complex, and pawn doesn't make splitting up programs into separate classes easy. So i do what i can.
You can see old, working, code at this thread. Before i added the API
http://forums.alliedmods.net/showthread.php?t=185404
If you PM me i can also give you the IP to the test server (running the version i attached)
Can you include all files I need to compile?

Quote:
Originally Posted by Liverwiz View Post
That's a great idea. Could you show me how to retrieve the CVAR, then store its pointer? I've never heard of doing that.
I included code in my post to do this.

Quote:
Originally Posted by Liverwiz View Post
I do because its faster. Check out Exolent's tut on data types. static declarations just reserve memory space, and aren't zero'd when they come into scope. Because zeroing is the biggest performance hit, i avoid it when i can.
It's better in some situations, not all. If you are using a variable that would be initialized very frequently (like in prethink or cmdstart) or you're declaring a large array then it is better to use static so the memory will only need to be allocated once and then can be re-used with each instance of the function call. For declaring a single cell of data (or small array) that is not called frequently then just declare it as new.
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-04-2012 , 11:35   Re: VERY irksum problem
Reply With Quote #7

"Zeroing" is not a performance hit, the memory allocation and de-allocation is the memory hit .

What was the value of level?
__________________
fysiks is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-04-2012 , 12:40   Re: VERY irksum problem
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
Can you include all files I need to compile?


I included code in my post to do this.


It's better in some situations, not all. If you are using a variable that would be initialized very frequently (like in prethink or cmdstart) or you're declaring a large array then it is better to use static so the memory will only need to be allocated once and then can be re-used with each instance of the function call. For declaring a single cell of data (or small array) that is not called frequently then just declare it as new.
All files included that you'll need to compile and install.
Oh...so you did. Sorry, a bit flustered.

Quote:
Originally Posted by fysiks View Post
"Zeroing" is not a performance hit, the memory allocation and de-allocation is the memory hit .

What was the value of level?
i tested level at 0, 1, 8, 31

and now for whatever fucking reason it decides to work. I think my computer just needs to be bombed. Anyone have a can of thermite they're willing to donate to the next YouTube video?

Completely unrelated.....Latest irk....it won't fucking divide. It seems calc = 0.000 while shooting through a glock. (printing proper values for ammo and clip. it just divides into 0.

Code:
static weapon, clip, ammo, Float:calc
weapon = get_user_weapon(id, ammo)
clip = weaponClip[weapon]
calc = (--ammo / clip) * 100.0
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 07-04-2012 at 12:46.
Liverwiz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-04-2012 , 13:11   Re: VERY irksum problem
Reply With Quote #9

Quote:
Originally Posted by Liverwiz View Post
Code:
static weapon, clip, ammo, Float:calc
weapon = get_user_weapon(id, ammo)
clip = weaponClip[weapon]
calc = (--ammo / clip) * 100.0
You are performing integer division. It does not work like normal division. You must convert both numerator and denominator to floats.
__________________
fysiks is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-04-2012 , 13:23   Re: VERY irksum problem
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
You are performing integer division. It does not work like normal division. You must convert both numerator and denominator to floats.
pawn is stupid.
What happens when you 3 / 4? does it truncate to 0? or does it properly round?
It truncates.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 07-04-2012 at 13:38.
Liverwiz is offline
Reply


Thread Tools
Display Modes

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 15:03.


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