[HELP] Class script
#1

Ok so this is my code when I do a command like "/hitman" it gives me the weapons before it too any way to stop this?




Код:
#include <core>
#include <float>
#include <string>
#include <file>
#include <time>
#include <datagram>
#include <a_players>
#include <a_vehicles>
#include <a_objects>
#include <a_sampdb>
public OnPlayerCommandText(playerid, cmdtext[]) // if a player writes command
{ // callback starts.
	//LAW
        if (strcmp("/police", cmdtext, true, 10) == 0) // if a player writes /police
	{ // if he writes, start these functions:
		GivePlayerWeapon(playerid, 22, 10000);
		GivePlayerWeapon(playerid, 3, 1);
		GivePlayerWeapon(playerid, 22, 10000);
		GivePlayerWeapon(playerid, 41, 10000);
  }
  {
		if (strcmp("/swat", cmdtext, true, 10) == 0) // if a player writes /swat
        GivePlayerWeapon(playerid, 31, 10000);
        GivePlayerWeapon(playerid, 27, 10000);
        GivePlayerWeapon(playerid, 24, 10000);
        GivePlayerWeapon(playerid, 17, 10000);
        }
        {
        if (strcmp("/ff", cmdtext, true, 10) == 0) // if a player writes /ff
		GivePlayerWeapon(playerid, 42, 10000);
		}
		{
		if (strcmp("/whore", cmdtext, true, 10) == 0) // if a player writes /whore
		GivePlayerWeapon(playerid, 10, 1);
		GivePlayerWeapon(playerid, 11, 1);
		GivePlayerWeapon(playerid, 12, 1);
		GivePlayerWeapon(playerid, 13, 1);
		}
		{
		if (strcmp("/hitman", cmdtext, true, 10) == 0) // if a player writes /hitman
		GivePlayerWeapon(playerid, 34, 10000);
		}
		{
        if (strcmp("/terrorist", cmdtext, true, 10) == 0) // if a player writes /terrorist
        GivePlayerWeapon(playerid, 35, 10000);
        GivePlayerWeapon(playerid, 8, 1);
        GivePlayerWeapon(playerid, 30, 10000);
        }
        {
        if (strcmp("/maniac", cmdtext, true, 10) == 0) // if a player writes /maniac
        GivePlayerWeapon(playerid, 9, 10000);
        }
        {
        if (strcmp("/photographer", cmdtext, true, 10) == 0) // if a player writes /photographer
        GivePlayerWeapon(playerid, 43, 10000);
        		 // If he writes, Give player police weapon's
		return 1; // return true.
	} // we ended this command's functions.
	return 0; // return false because there is a true above.
} // we ended this callback's functions.
Reply
#2

Look for 'GivePlayerWeapon' anywhere else in your script other than the one you posted above.
Reply
#3

Quote:
Originally Posted by AroseKhanNiazi
Посмотреть сообщение
Look for 'GivePlayerWeapon' anywhere else in your script other than the one you posted above.
What do you mean? and no thats all my script.
Reply
#4

This is your complete script? No other script used?
Reply
#5

Your brackets are all messed up. Make sure your { and } brackets are around the correct code after checking the commands.
Also, don't forget to return 1; inside all of the successful commands so that the script can end right there and doesn't have to continue.

PHP код:
public OnPlayerCommandText(playeridcmdtext[]) // if a player writes a command
// callback starts.
        //< ... other commands ... >
        
if (strcmp("/terrorist"cmdtexttrue10) == 0//if the command is /terrorist then do this:
        
//bracket starts above code, after check
                
GivePlayerWeapon(playerid3510000);
                
GivePlayerWeapon(playerid81);
                
GivePlayerWeapon(playerid3010000);
                return 
1;  //command was successful and your script can end here
        
//bracket ends after the code, command /terrorist ends here
        //< ... other commands ... >
        
return 0//search for commands ends, no command found
//callback ends. 
Do this for the rest of the commands.
Reply
#6

Though this is all you need
PHP код:
#include <a_samp>
public OnPlayerCommandText(playeridcmdtext[]) // if a player writes command
{
    if (
strcmp("/police"cmdtexttrue7) == 0// if a player writes /police
    
{
        
GivePlayerWeapon(playerid2210000);
        
GivePlayerWeapon(playerid31);
        
GivePlayerWeapon(playerid2210000);
        
GivePlayerWeapon(playerid4110000);
        return 
1;
    }
    if (
strcmp("/swat"cmdtexttrue5) == 0// if a player writes /swat
    
{
        
GivePlayerWeapon(playerid3110000);
        
GivePlayerWeapon(playerid2710000);
        
GivePlayerWeapon(playerid2410000);
        
GivePlayerWeapon(playerid1710000);
        return 
1;
    }
    if (
strcmp("/ff"cmdtexttrue3) == 0// if a player writes /ff
    
{
        
GivePlayerWeapon(playerid4210000);
        return 
1;
    }
    if (
strcmp("/whore"cmdtexttrue6) == 0// if a player writes /whore
    
{
        
GivePlayerWeapon(playerid101);
        
GivePlayerWeapon(playerid111);
        
GivePlayerWeapon(playerid121);
        
GivePlayerWeapon(playerid131);
        return 
1;
    }
    if (
strcmp("/hitman"cmdtexttrue7) == 0// if a player writes /hitman
    
{
        
GivePlayerWeapon(playerid3410000);
        return 
1;
    }
    if (
strcmp("/terrorist"cmdtexttrue10) == 0// if a player writes /terrorist
    
{
        
GivePlayerWeapon(playerid3510000);
        
GivePlayerWeapon(playerid81);
        
GivePlayerWeapon(playerid3010000);
        return 
1;
    }
    if (
strcmp("/maniac"cmdtexttrue7) == 0// if a player writes /maniac
    
{
        
GivePlayerWeapon(playerid910000);
        return 
1;
    }
    if (
strcmp("/photographer"cmdtexttrue13) == 0// if a player writes /photographer
    
{
        
GivePlayerWeapon(playerid4310000);
        return 
1;
    }    
    return 
0;
// we ended this callback's functions. 
Reply
#7

Thanks both of you it works now
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)