AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   VERY irksum problem -solved- (https://forums.alliedmods.net/showthread.php?t=189159)

Liverwiz 07-04-2012 01:56

VERY irksum problem -solved-
 
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
}


pokemonmaster 07-04-2012 08:03

Re: VERY irksum problem
 
PHP Code:

level getLevel(id

can you post the getLevel() function?

Liverwiz 07-04-2012 10:32

Re: VERY irksum problem
 
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 }

Bugsy 07-04-2012 10:43

Re: VERY irksum problem
 
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?

Liverwiz 07-04-2012 11:12

Re: VERY irksum problem
 
3 Attachment(s)
Quote:

Originally Posted by Bugsy (Post 1743210)
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 (Post 1743210)
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 (Post 1743210)
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?

Bugsy 07-04-2012 11:22

Re: VERY irksum problem
 
Quote:

Originally Posted by Liverwiz (Post 1743226)
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 (Post 1743226)
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 (Post 1743226)
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.

fysiks 07-04-2012 11:35

Re: VERY irksum problem
 
"Zeroing" is not a performance hit, the memory allocation and de-allocation is the memory hit :).

What was the value of level?

Liverwiz 07-04-2012 12:40

Re: VERY irksum problem
 
Quote:

Originally Posted by Bugsy (Post 1743236)
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 (Post 1743251)
"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


fysiks 07-04-2012 13:11

Re: VERY irksum problem
 
Quote:

Originally Posted by Liverwiz (Post 1743292)
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.

Liverwiz 07-04-2012 13:23

Re: VERY irksum problem
 
Quote:

Originally Posted by fysiks (Post 1743309)
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.


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

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