Raised This Month: $ Target: $400
 0% 

[HELP] how optimize/change this code?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LudaGe
Senior Member
Join Date: May 2010
Location: World so cold
Old 12-02-2010 , 22:39   [HELP] how optimize/change this code?
Reply With Quote #1

Hi guys
I m using this code for set hp, speed, grav. in Gun XP Mod
but i dont like this form...

PHP Code:
// Set HP, Speed and Gravity
public Sethpspdgr(id)
{
    if (
g_PlayerLevel[id] >= 1)
    {
    
set_user_health(id120)
    
set_pev(idpev_maxspeed245.0)
    
set_user_gravity(id0.95)
    }
    if (
g_PlayerLevel[id] >= 2)
    {
    
set_user_health(id140)
    
set_pev(idpev_maxspeed250.0)
    
set_user_gravity(id0.9)
    }
    if (
g_PlayerLevel[id] >= 3)
    {
    
//Etc
}

Someone have other method ??

ps:
PHP Code:
public FwPlayerSpawn(id)
{
// Other code
    
Sethpspdgr(id)
// Other code

ps2: sorry my bad english

Last edited by LudaGe; 12-03-2010 at 00:21.
LudaGe is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-02-2010 , 22:50   Re: [HELP] how optimize/change this code?
Reply With Quote #2

I don't don't think setting maxspeed will work like that. Does your code work?

Also, your second and third case will never happen.
__________________
fysiks is offline
LudaGe
Senior Member
Join Date: May 2010
Location: World so cold
Old 12-02-2010 , 22:58   Re: [HELP] how optimize/change this code?
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
I don't don't think setting maxspeed will work like that. Does your code work?

Also, your second and third case will never happen.
yes, all code work
LudaGe is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-03-2010 , 00:19   Re: [HELP] how optimize/change this code?
Reply With Quote #4

. . . Of all the threads I've read concerning maxspeed, that shouldn't work.

Also,

Quote:
Originally Posted by fysiks View Post
your second and third case will never happen.
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-03-2010 , 00:20   Re: [HELP] how optimize/change this code?
Reply With Quote #5

Make an array(s) containing the values for each item at each level. Then access using array[ g_PlayerLevel[ id ] ]
__________________

Last edited by Bugsy; 12-03-2010 at 00:22.
Bugsy is offline
LudaGe
Senior Member
Join Date: May 2010
Location: World so cold
Old 12-03-2010 , 00:25   Re: [HELP] how optimize/change this code?
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
. . . Of all the threads I've read concerning maxspeed, that shouldn't work.

Also,
PHP Code:
else if (g_PlayerLevel[id] >= 2
=>
PHP Code:
if (g_PlayerLevel[id] >= 2
now works., and the Maxspeed set well

Quote:
Originally Posted by Bugsy View Post
Make 3 arrays or a 'struct' containing the values for each item at each level. Then access using array[ g_PlayerLevel[ id ] ]
You can give me an example?
plz
LudaGe is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-03-2010 , 09:01   Re: [HELP] how optimize/change this code?
Reply With Quote #7

Doing it this way will reduce the amount of code because you will not need any if-statements and each native function is only used once. Just make sure that the g_PlayerLevel[] for any given player is greater than 0 and NOT greater than NumLevels. If players do have a level 0, just replace the first element (with 0 , 0.0 , 0.0 values ) in the the below g_lpLevelPowers array with level 0 values. Let me know if you have any questions.

PHP Code:
enum LevelPowers
{
    
LP_Health,
    
Float:LP_MaxSpeed,
    
Float:LP_Gravity
}

//Set this variable to the number of levels you have
const NumLevels 3;

/*Add each level powers exactly as they are below. The
order is { health , maxspeed , gravity }. Make sure you always 
have the number of powers equal to NumLevels variable; the 
plugin will not compile if NumLevels is not equal to the levels
defined in this array. I assumed there is no level 0 so I left all
powers at 0.*/
new const g_lpLevelPowersNumLevels ][ LevelPowers ] = 
{
    {   
,    0.0 0.00 },  //Level 0 (add powers if needed)
    
120 245.0 0.95 }, //Level 1
    
140 250.0 0.90 }, //Level 2
    
160 255.0 0.85 }  //Level 3
}

public 
Sethpspdgr(id)
{
    
set_user_healthid g_lpLevelPowersg_PlayerLevelid ] ][ LP_Health ] )
    
set_pevid pev_maxspeedg_lpLevelPowersg_PlayerLevelid ] ][ LP_MaxSpeed ] )
    
set_user_gravityid g_lpLevelPowersg_PlayerLevelid ] ][ LP_Gravity ] )

__________________
Bugsy is offline
LudaGe
Senior Member
Join Date: May 2010
Location: World so cold
Old 12-03-2010 , 09:24   Re: [HELP] how optimize/change this code?
Reply With Quote #8

Big thanks Bugsy
I like very much this form
but, how i can set:
PHP Code:
{   ,    0.0 0.00 },  //Level 0 (add powers if needed)
    
120 245.0 0.95 }, //Level 1
    
200 270.0 0.75 }, //Level 4
    
260 300.0 0.6 }  //Level 10 

Last edited by LudaGe; 12-03-2010 at 09:29.
LudaGe is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-03-2010 , 09:44   Re: [HELP] how optimize/change this code?
Reply With Quote #9

Show all level numbers that you need to use.
__________________
Bugsy is offline
LudaGe
Senior Member
Join Date: May 2010
Location: World so cold
Old 12-03-2010 , 14:02   Re: [HELP] how optimize/change this code?
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
Show all level numbers that you need to use.
i dont know, 1, 4, 10¿?

Anyway, thanks you help me enough with what i needed

Last edited by LudaGe; 12-03-2010 at 14:08.
LudaGe 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 11:24.


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