Raised This Month: $ Target: $400
 0% 

How to optimize this?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AfteR.
Veteran Member
Join Date: Dec 2008
Location: λ
Old 02-13-2010 , 00:32   How to optimize this?
Reply With Quote #1

I'm making a Speed Upgrade menu, and it works. But i would like to know how can I optimize this and also add a prize for each improve. Also, that prize higher than the last one...

Here's the code.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#define PLUGIN "Upgrade Speed"
#define VERSION "1.0"
#define AUTHOR "AfteR ;)"

const KEYSMENU = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)

new 
coins[33], speed[33], upgraded[33]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_menu("Game Menu"KEYSMENU"menu2")
    
register_clcmd("say a" "menu" )
    
register_forward(FM_PlayerPreThink"fw_PlayerPreThink")

}


// Forward Player PreThink
public fw_PlayerPreThink(id)
{
    
// Not alive
    
if (!is_user_alive(id))
        return;
    
    
set_pev(idpev_maxspeed150.0 speed[id])
}


public 
menu(idmenu1(id)


public 
menu1(id)
{
    static 
menu[300], len
    len 
0
    
    len 
+= formatex(menu[len], sizeof menu len"\yImprove Speed Menu^n^n")
    
    
len += formatex(menu[len], sizeof menu len"Coins: %d^n"coins[id])
    
len += formatex(menu[len], sizeof menu len"Upgraded Times: %d^n^n"upgraded[id])
    
    
len += formatex(menu[len], sizeof menu len"\r1. \wImprove Speed^n^n")
    
    
len += formatex(menu[len], sizeof menu len"\r0. \wExit")
    
    
show_menu(idKEYSMENUmenu, -1"Game Menu")
}

public 
menu2(idkey)
{
    switch (
key)
    {
        case 
0
        {
            if (
upgraded[id] <= 4)
            {
                
speed[id] += 30
                upgraded
[id]++
            }
            else
                
client_print(idprint_chat"Max Upgrades.")
            
        }
        
    }

Coins are the prize
AfteR. is offline
01101101
BANNED
Join Date: Nov 2009
Location: 9`su 09`n0n7e`r0f76a
Old 02-13-2010 , 03:09   Re: How to optimize this?
Reply With Quote #2

PHP Code:
public menu(idmenu1(id


public 
menu1(id

WTF
01101101 is offline
AfteR.
Veteran Member
Join Date: Dec 2008
Location: λ
Old 02-14-2010 , 20:05   Re: How to optimize this?
Reply With Quote #3

Quote:
Originally Posted by 01101101 View Post
PHP Code:
public menu(idmenu1(id


public 
menu1(id

WTF
Anybody else?
AfteR. is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 02-14-2010 , 20:37   Re: How to optimize this?
Reply With Quote #4

Quote:
Originally Posted by 01101101 View Post
PHP Code:
public menu(idmenu1(id


public 
menu1(id

WTF
WTF++

You've asked for optimizations. Removing WTFs from your code might be useful.
Seta00 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-14-2010 , 21:02   Re: How to optimize this?
Reply With Quote #5

I thought you were supposed to set speed in CurrentWeapon. I also thought you could use set_user_maxspeed() instead of using fakemeta.
__________________
fysiks is offline
AfteR.
Veteran Member
Join Date: Dec 2008
Location: λ
Old 02-14-2010 , 22:28   Re: How to optimize this?
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
I thought you were supposed to set speed in CurrentWeapon. I also thought you could use set_user_maxspeed() instead of using fakemeta.
I just asked that to know which was better, but now i i'd like to know if there would be a better method to set the speed upgrade stuff.

I mean: coins[33], speed[33], upgraded[33]
AfteR. is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 02-15-2010 , 00:11   Re: How to optimize this?
Reply With Quote #7

use curwep event and set_user_maxspeed from fun. Also use a set speed dont add speed unless some one knows how to keep curwep to only fire on weapon switch (hamdeploy?)

Example:
PHP Code:
public curwep(id)
{
      
set_user_maxspeed(idFloat:Speed);
}

Not!!!!
public 
Curwep(id)
{
       
set_user_maxspeed(idget_user_maxspeed(id) + Float:Speed)


The second example adds that speed each time the event is fired. how ever you could do

PHP Code:
set_user_maxspeed(id250 Float:Speed
Which is about the average speed
Doc-Holiday is offline
Max!
Member
Join Date: Jun 2009
Old 02-15-2010 , 01:19   Re: How to optimize this?
Reply With Quote #8

Quote:
Originally Posted by NcB_Sav View Post
unless some one knows how to keep curwep to only fire on weapon switch
PHP Code:
new g_iLastWeapon[33]

public 
curweapon(iClient)
{
    new 
iWeapon get_user_weapon(iClient)
    if(
iWeapon != g_iLastWeapon[iClient])
    {
        
g_iLastWeapon[iClient] = iWeapon
        
// do stuff
    
}

Max! is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 02-15-2010 , 01:38   Re: How to optimize this?
Reply With Quote #9

Quote:
Originally Posted by Max! View Post
PHP Code:
new g_iLastWeapon[33]

public 
curweapon(iClient)
{
    new 
iWeapon get_user_weapon(iClient)
    if(
iWeapon != g_iLastWeapon[iClient])
    {
        
g_iLastWeapon[iClient] = iWeapon
        
// do stuff
    
}

Hmm ill have to give that a shot haha.. Thanks much.
Doc-Holiday is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-15-2010 , 01:49   Re: How to optimize this?
Reply With Quote #10

Best place to set max speed : http://forums.alliedmods.net/showthr...202#post853202
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 01:49.


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