Raised This Month: $ Target: $400
 0% 

How to make code shorter?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Evaldas.Grigas
Senior Member
Join Date: Sep 2011
Location: Lithuania
Old 09-29-2011 , 12:49   How to make code shorter?
Reply With Quote #1

Topic says it all.
PHP Code:
public Showrod(id) {
    
set_task(10.0"CancelMenu"id);
    
show_menu(idKeysrod"Choose VIP guns:^n\w1. Get M4A1 and Deagle ^n\w2. Get AK47 and Deagle ^n3. Get Galil and Deagle ^n0. Exit^n", -1"rod"// Display menu
    
new mapname[11];
         
get_mapname(mapnamecharsmax(mapname));
    if (
equali(mapname"awp_india"))
    {
             
client_cmd(id"slot10");
    }
    
get_mapname(mapnamecharsmax(mapname));
    if (
equali(mapname"awp_dust"))
    {
             
client_cmd(id"slot10");
    }
    
get_mapname(mapnamecharsmax(mapname));
    if (
equali(mapname"cs_deagle5"))
    {
             
client_cmd(id"slot10");
    }


Last edited by Evaldas.Grigas; 09-29-2011 at 14:07.
Evaldas.Grigas is offline
Send a message via Skype™ to Evaldas.Grigas
BlinkHardeR
Member
Join Date: Aug 2011
Location: Israel, Holon
Old 09-29-2011 , 12:50   Re: How to make code shorter?
Reply With Quote #2

Why you need To Make it Shorter?
BlinkHardeR is offline
Send a message via Skype™ to BlinkHardeR
Korxu
Senior Member
Join Date: Sep 2010
Old 09-29-2011 , 12:59   Re: How to make code shorter?
Reply With Quote #3

Use get_mapname only one time.
Korxu is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 09-29-2011 , 13:30   Re: How to make code shorter?
Reply With Quote #4

PHP Code:
public Showrod(id) {
    
set_task(10.0"CancelMenu"id);
    
show_menu(idKeysrod"Choose VIP guns:^n\w1. Get M4A1 and Deagle ^n\w2. Get AK47 and Deagle ^n3. Get Galil and Deagle ^n0. Exit^n", -1"rod"// Display menu
    
new mapname[11];
    
get_mapname(mapnamecharsmax(mapname));
    if (
containi("awp_india awp_dust cs_deagle5"mapname) > -1)
    {
             
client_cmd(id"slot10");
    }

dont use this when you have maps like "cs_deagle" or "awp_indi" or something else that might get found in "awp_india awp_dust cs_deagle5" string

Last edited by jimaway; 09-29-2011 at 13:32.
jimaway is offline
Blue Snake.
Member
Join Date: May 2011
Location: Romania
Old 09-29-2011 , 13:38   Re: How to make code shorter?
Reply With Quote #5

PHP Code:
if( equali(mapname"awp_india") || equali(mapname"cs_deagle5") || equali(mapname"awp_dust"))
    
client_cmd(id"slot10"
Blue Snake. is offline
Evaldas.Grigas
Senior Member
Join Date: Sep 2011
Location: Lithuania
Old 09-29-2011 , 13:58   Re: How to make code shorter?
Reply With Quote #6

Quote:
Originally Posted by jimaway View Post
PHP Code:
public Showrod(id) {
    
set_task(10.0"CancelMenu"id);
    
show_menu(idKeysrod"Choose VIP guns:^n\w1. Get M4A1 and Deagle  ^n\w2. Get AK47 and Deagle ^n3. Get Galil and Deagle ^n0. Exit^n", -1,  "rod"// Display menu
    
new mapname[11];
    
get_mapname(mapnamecharsmax(mapname));
    if (
containi("awp_india awp_dust cs_deagle5"mapname) > -1)
    {
             
client_cmd(id"slot10");
    }

dont use this when you have maps like "cs_deagle" or "awp_indi" or something else that might get found in "awp_india awp_dust cs_deagle5" string
Why > -1?

Last edited by Evaldas.Grigas; 09-29-2011 at 14:09.
Evaldas.Grigas is offline
Send a message via Skype™ to Evaldas.Grigas
MyPc
Senior Member
Join Date: Sep 2011
Old 09-29-2011 , 14:26   Re: How to make code shorter?
Reply With Quote #7

Quote:
Originally Posted by Evaldas.Grigas View Post
Why > -1?
Yeah i want to know it to ..
By the way, a shorter code isn't always a better code =D ( You should remember that ).
MyPc is offline
kotinha
Senior Member
Join Date: Jun 2009
Location: Alentejo, Portugal :)
Old 09-29-2011 , 15:02   Re: How to make code shorter?
Reply With Quote #8

Quote:
Originally Posted by Evaldas.Grigas View Post
Why > -1?
From http://www.amxmodx.org/funcwiki.php?go=func&id=46 :
Quote:
containi - Returns position of string found inside of source, or -1 on failure. Case insensitive.
__________________
"If God exists, I hope he has a good excuse." - Woody Allen
kotinha is offline
MyPc
Senior Member
Join Date: Sep 2011
Old 09-29-2011 , 15:08   Re: How to make code shorter?
Reply With Quote #9

Quote:
Originally Posted by kotinha View Post
I didn't taught about searching in their +_+
Ty =D

so
PHP Code:
if( containistringotherstring ) == -
that will be called if the string "otherstring" wont be find in the string "string" right ?
MyPc is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 09-29-2011 , 15:53   Re: How to make code shorter?
Reply With Quote #10

yes
jimaway 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 19:31.


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