AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] how optimize/change this code? (https://forums.alliedmods.net/showthread.php?t=144377)

LudaGe 12-02-2010 22:39

[HELP] how optimize/change this code?
 
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

fysiks 12-02-2010 22:50

Re: [HELP] how optimize/change this code?
 
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.

LudaGe 12-02-2010 22:58

Re: [HELP] how optimize/change this code?
 
Quote:

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

fysiks 12-03-2010 00:19

Re: [HELP] how optimize/change this code?
 
. . . Of all the threads I've read concerning maxspeed, that shouldn't work.

Also,

Quote:

Originally Posted by fysiks (Post 1361830)
your second and third case will never happen.


Bugsy 12-03-2010 00:20

Re: [HELP] how optimize/change this code?
 
Make an array(s) containing the values for each item at each level. Then access using array[ g_PlayerLevel[ id ] ]

LudaGe 12-03-2010 00:25

Re: [HELP] how optimize/change this code?
 
Quote:

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

Bugsy 12-03-2010 09:01

Re: [HELP] how optimize/change this code?
 
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 ] )



LudaGe 12-03-2010 09:24

Re: [HELP] how optimize/change this code?
 
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 


Bugsy 12-03-2010 09:44

Re: [HELP] how optimize/change this code?
 
Show all level numbers that you need to use.

LudaGe 12-03-2010 14:02

Re: [HELP] how optimize/change this code?
 
Quote:

Originally Posted by Bugsy (Post 1362016)
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 :)


All times are GMT -4. The time now is 11:24.

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