AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Equal and sizeof. (https://forums.alliedmods.net/showthread.php?t=164316)

Ex3cuTioN 08-10-2011 03:26

Equal and sizeof.
 
PHP Code:

#include <amxmodx>
#include <fun>

//WPN
new weapon_list[9][] = {
    
"scout",
    
"sg550",
    
"famas",
    
"usp",
    
"awp",
    
"m249",
    
"m4a1",
    
"deagle",
    
"p90"
};

public 
plugin_init() {
    
register_plugin("WPN""0.01""Ex3cuTioN");
    
register_clcmd("say","cmdWPN");
}

public 
cmdWPN(id) {
    static 
s_Args[32];
    
read_args(s_Argssizeof(s_Args) - 1);
    
    if(!
s_Args[0])
        return 
PLUGIN_CONTINUE;
        
    
remove_quotes(s_Args);
    
    for(new 
09i++) {
        
replace(s_Argssizeof(s_Args) - 1"/""");
        if(
equal(s_Argsweapon_list[i], sizeof(weapon_list[i]) - 1)) {
            new 
x[8];
            
format(x7"weapon_%s"s_Args);
            
            
give_item(idx);
            
client_print(idprint_chat"You received %s"s_Args);
        }
    }
    
    return 
PLUGIN_CONTINUE;


What the heck is wrong at if(equal(s_Args, weapon_list[i], sizeof(weapon_list[i]) - 1)) { ?????

Doc-Holiday 08-10-2011 03:36

Re: Equal and sizeof.
 
Ight so here is the edited one... DK why you had the sizeof there... but here ya go

When player types m4a1 he recieves one (tested scout, m4a1, p90)
PHP Code:

#include <amxmodx>
#include <fun>

//WPN
new weapon_list[9][] = {
    
"scout",
    
"sg550",
    
"famas",
    
"usp",
    
"awp",
    
"m249",
    
"m4a1",
    
"deagle",
    
"p90"
};

public 
plugin_init() {
    
register_plugin("WPN""0.01""Ex3cuTioN");
    
register_clcmd("say","cmdWPN");
}

public 
cmdWPN(id) {
    static 
s_Args[32];
    
read_args(s_Argscharsmax(s_Args));
    
    if(!
s_Args[0])
        return 
PLUGIN_CONTINUE;
        
    
remove_quotes(s_Args);
    
    for(new 
09i++) 
    {
        if(
equal(s_Args weapon_list[i]))
        {
            
//Dont need to replace beacsue you use Equal.. It wont take /m4a1

            
new weaponName[32];
            
format(weaponNamecharsmax(weaponName), "weapon_%s"s_Args);
            
            
give_item(idweaponName);
            
client_print(idprint_chat"You received %s"weaponName);
        }
    }
    
    return 
PLUGIN_CONTINUE;



fysiks 08-10-2011 03:39

Re: Equal and sizeof.
 
  1. For the error in question: Look at the line below it where you use it correctly.
  2. You have too many parentheses on that line.
  3. You shouldn't use sizeof() for that parameter anyways. You should use strlen() if you insist on using anything at all there.
  4. If you ever need sizeof(string)-1 you should use charsmax(string) instead to make it less confusing for you since charsmax is defined as sizeof minus 1.

Ex3cuTioN 08-10-2011 03:41

Re: Equal and sizeof.
 
PHP Code:

new x[32];
format(x32"weapon_%s"s_Args); 

:arrow:

PHP Code:

new x[32];
format(x31"weapon_%s"s_Args); 

Thank you D:D:D:

fysiks 08-10-2011 03:42

Re: Equal and sizeof.
 
Quote:

Originally Posted by Ex3cuTioN (Post 1529384)
PHP Code:

new x[32];
format(x32"weapon_%s"s_Args); 

:arrow:

PHP Code:

new x[32];
format(x31"weapon_%s"s_Args); 

Thank you D:D:D:

Use charsmax(x) instead of 31. It will make life easier.

Ex3cuTioN 08-10-2011 03:43

Re: Equal and sizeof.
 
Ok, i'm using it.

Doc-Holiday 08-10-2011 03:43

Re: Equal and sizeof.
 
Quote:

Originally Posted by fysiks (Post 1529382)
  1. For the error in question: Look at the line below it where you use it correctly.
  2. You have too many parentheses on that line.
  3. You shouldn't use sizeof() for that parameter anyways. You should use strlen() if you insist on using anything at all there.
  4. If you ever need sizeof(string)-1 you should use charsmax(string) instead to make it less confusing for you since charsmax is defined as sizeof minus 1.

also if you didnt notice in the code the format needs a higher length because it has to hold weapon_m4a1 and so forth... 7 only holds weapon_.

As for your variable 'x' i would use something like weaponName it helps with readability.

My code has been updated with the suggestion.

Ex3cuTioN 08-10-2011 03:44

Re: Equal and sizeof.
 
@Doc-Holiday - Solved and it was just a fast write.

Exolent[jNr] 08-10-2011 09:22

Re: Equal and sizeof.
 
Another way without looping for string matches:
PHP Code:

#include <amxmodx>
#include <fun>

//WPN
new weapon_list 
    (
1<<CSW_SCOUT) |
    (
1<<CSW_SG550) |
    (
1<<CSW_FAMAS) |
    (
1<<CSW_USP) |
    (
1<<CSW_AWP) |
    (
1<<CSW_M249) |
    (
1<<CSW_M4A1) |
    (
1<<CSW_DEAGLE) |
    (
1<<CSW_P90)
;

public 
plugin_init() {
    
register_plugin("WPN""0.01""Ex3cuTioN");
    
register_clcmd("say","cmdWPN");
}

public 
cmdWPN(id) {
    static 
s_Args[32];
    
read_args(s_Argscharsmax(s_Args));
    
    if(!
s_Args[0])
        return 
PLUGIN_CONTINUE;
        
    
remove_quotes(s_Args);
    
strtolower(s_Args);
    
format(s_Argscharsmax(s_Args), "weapon_%s"s_Args);
    
    new 
weaponID get_weaponid(s_Args);
    
    if(
weaponID && (weapon_list & (1<<weaponID)))
    {
        
give_item(ids_Args);
        
client_print(idprint_chat"You received %s"s_Args);
    }
    
    return 
PLUGIN_CONTINUE;




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

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