Raised This Month: $ Target: $400
 0% 

Equal and sizeof.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ex3cuTioN
Member
Join Date: May 2010
Old 08-10-2011 , 03:26   Equal and sizeof.
Reply With Quote #1

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)) { ?????

Last edited by Ex3cuTioN; 08-10-2011 at 03:35.
Ex3cuTioN is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 08-10-2011 , 03:36   Re: Equal and sizeof.
Reply With Quote #2

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;


Last edited by Doc-Holiday; 08-10-2011 at 03:44.
Doc-Holiday is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-10-2011 , 03:39   Re: Equal and sizeof.
Reply With Quote #3

  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.
__________________
fysiks is offline
Ex3cuTioN
Member
Join Date: May 2010
Old 08-10-2011 , 03:41   Re: Equal and sizeof.
Reply With Quote #4

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


PHP Code:
new x[32];
format(x31"weapon_%s"s_Args); 
Thank you D:
Ex3cuTioN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-10-2011 , 03:42   Re: Equal and sizeof.
Reply With Quote #5

Quote:
Originally Posted by Ex3cuTioN View Post
PHP Code:
new x[32];
format(x32"weapon_%s"s_Args); 


PHP Code:
new x[32];
format(x31"weapon_%s"s_Args); 
Thank you D:
Use charsmax(x) instead of 31. It will make life easier.
__________________
fysiks is offline
Ex3cuTioN
Member
Join Date: May 2010
Old 08-10-2011 , 03:43   Re: Equal and sizeof.
Reply With Quote #6

Ok, i'm using it.
Ex3cuTioN is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 08-10-2011 , 03:43   Re: Equal and sizeof.
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
  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.
Doc-Holiday is offline
Ex3cuTioN
Member
Join Date: May 2010
Old 08-10-2011 , 03:44   Re: Equal and sizeof.
Reply With Quote #8

@Doc-Holiday - Solved and it was just a fast write.
Ex3cuTioN is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-10-2011 , 09:22   Re: Equal and sizeof.
Reply With Quote #9

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;

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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:03.


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