AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to make code shorter? (https://forums.alliedmods.net/showthread.php?t=168464)

Evaldas.Grigas 09-29-2011 12:49

How to make code shorter?
 
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");
    }



BlinkHardeR 09-29-2011 12:50

Re: How to make code shorter?
 
Why you need To Make it Shorter?

Korxu 09-29-2011 12:59

Re: How to make code shorter?
 
Use get_mapname only one time.

jimaway 09-29-2011 13:30

Re: How to make code shorter?
 
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

Blue Snake. 09-29-2011 13:38

Re: How to make code shorter?
 
PHP Code:

if( equali(mapname"awp_india") || equali(mapname"cs_deagle5") || equali(mapname"awp_dust"))
    
client_cmd(id"slot10"


Evaldas.Grigas 09-29-2011 13:58

Re: How to make code shorter?
 
Quote:

Originally Posted by jimaway (Post 1565398)
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?

MyPc 09-29-2011 14:26

Re: How to make code shorter?
 
Quote:

Originally Posted by Evaldas.Grigas (Post 1565419)
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 ).

kotinha 09-29-2011 15:02

Re: How to make code shorter?
 
Quote:

Originally Posted by Evaldas.Grigas (Post 1565419)
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.

MyPc 09-29-2011 15:08

Re: How to make code shorter?
 
Quote:

Originally Posted by kotinha (Post 1565488)

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 ?

jimaway 09-29-2011 15:53

Re: How to make code shorter?
 
yes


All times are GMT -4. The time now is 19:31.

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