PDA

View Full Version : [HELP] Class script


dudejohn12
01/03/2018, 05:47 PM
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.

AroseKhanNiazi
01/03/2018, 09:56 PM
Look for 'GivePlayerWeapon' anywhere else in your script other than the one you posted above.

dudejohn12
01/03/2018, 11:11 PM
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.

AroseKhanNiazi
01/03/2018, 11:23 PM
This is your complete script? No other script used?

AdamsLT
01/03/2018, 11:24 PM
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.


public OnPlayerCommandText(playerid, cmdtext[]) // if a player writes a command
{ // callback starts.

//< ... other commands ... >

if (strcmp("/terrorist", cmdtext, true, 10) == 0) //if the command is /terrorist then do this:
{ //bracket starts above code, after check
GivePlayerWeapon(playerid, 35, 10000);
GivePlayerWeapon(playerid, 8, 1);
GivePlayerWeapon(playerid, 30, 10000);
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.

AroseKhanNiazi
01/03/2018, 11:33 PM
Though this is all you need

#include <a_samp>

public OnPlayerCommandText(playerid, cmdtext[]) // if a player writes command
{
if (strcmp("/police", cmdtext, true, 7) == 0) // if a player writes /police
{
GivePlayerWeapon(playerid, 22, 10000);
GivePlayerWeapon(playerid, 3, 1);
GivePlayerWeapon(playerid, 22, 10000);
GivePlayerWeapon(playerid, 41, 10000);
return 1;
}
if (strcmp("/swat", cmdtext, true, 5) == 0) // if a player writes /swat
{
GivePlayerWeapon(playerid, 31, 10000);
GivePlayerWeapon(playerid, 27, 10000);
GivePlayerWeapon(playerid, 24, 10000);
GivePlayerWeapon(playerid, 17, 10000);
return 1;
}
if (strcmp("/ff", cmdtext, true, 3) == 0) // if a player writes /ff
{
GivePlayerWeapon(playerid, 42, 10000);
return 1;
}
if (strcmp("/whore", cmdtext, true, 6) == 0) // if a player writes /whore
{
GivePlayerWeapon(playerid, 10, 1);
GivePlayerWeapon(playerid, 11, 1);
GivePlayerWeapon(playerid, 12, 1);
GivePlayerWeapon(playerid, 13, 1);
return 1;
}
if (strcmp("/hitman", cmdtext, true, 7) == 0) // if a player writes /hitman
{
GivePlayerWeapon(playerid, 34, 10000);
return 1;
}
if (strcmp("/terrorist", cmdtext, true, 10) == 0) // if a player writes /terrorist
{
GivePlayerWeapon(playerid, 35, 10000);
GivePlayerWeapon(playerid, 8, 1);
GivePlayerWeapon(playerid, 30, 10000);
return 1;
}
if (strcmp("/maniac", cmdtext, true, 7) == 0) // if a player writes /maniac
{
GivePlayerWeapon(playerid, 9, 10000);
return 1;
}
if (strcmp("/photographer", cmdtext, true, 13) == 0) // if a player writes /photographer
{
GivePlayerWeapon(playerid, 43, 10000);
return 1;
}
return 0;
} // we ended this callback's functions.

dudejohn12
01/03/2018, 11:38 PM
Thanks both of you it works now :D