Creating drug script
#1

Hey, I must first say that my english understanding is not always good, especially when it comes to advanced english wich I found in the pawn.pdf so I have not continued to read it.

However, I was looking at some gamemode scripts earlier where they had drugs and drug smuggling in their gamemode and I am not here to ask how to make it, I will rather find out on my own. I am here to see if I could do it a better way then what I currently have done!

Here is my script, it compiles 100% and my two commands work ingame, I can get drugs and see the drugs.

Код:
new Drugs[MAX_PLAYERS];
First of, I used the same way I saw a guy use for wanted system (if you kill a person you gain +wanted stars each kill) and I thought, Maybe use the same for my drugs script!

Код:
	if (strcmp(cmdtext, "/getdrugs", true)==0)
	{
	  new oldlevel;
 	  new newlevel;
 	  oldlevel = Drugs[playerid];
  	  newlevel = oldlevel + 1;
      Drugs[playerid] = newlevel;
      SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have been given 1G drugs!");
	  return 1;
	}
But here is my concern, script below makes my script look so messy because I repeat same script piece over and over again just to get one result.

Can I make this easier instead of constantly adding if(drugs[playerid] == X) ? How can I make a line that just lookup what value i have instead of asking if I have 1,2,3,4 and so on?

Код:
 // ============================================= //
  if (strcmp(cmdtext, "/drugs", true)==0)
	{
    if(gJob[playerid] == JOB_CIVILIAN)
    {
      if(Drugs[playerid] == 0)
      {
    	SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have no drugs on you!");
			}
			else if(Drugs[playerid] == 1)
      {
    	SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have 1g drugs on you!");
			}
			else if(Drugs[playerid] == 2)
      {
    	SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have 2g drugs on you!");
			}
		}
		return 1;
	 }
  // ============================================= //

Also I would like to know if it is stupid to use the script I am using? Should I make it diffrent,easier to understand? Could it make my gamemode lag or get bugged because I use this or that code?

I hope you understand, this is not matter of searching on the forum for help, I ask for guidance so I do not make a very very long script that maybe end up very buggy or laggy for my gamemode. Or can I continue using the codes I have been using.
Reply
#2

Hello there. Yes there are much better looking scripts out there, but that has nothing to do with the scripts abilities.

Firstly, your /getdrugs command can be made a lot better:
pawn Код:
if (strcmp(cmdtext, "/getdrugs", true)==0)
{
  Drugs[playerid] += 1; // Adds 1 to the current amount.
  return SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have been given 1G drugs!"); // Sends the message AND doesnt show 'SERVER: Unknown command.' message.
}
Now to make your /drugs command better:
pawn Код:
if (strcmp(cmdtext, "/drugs", true)==0)
{
  if(gJob[playerid] == JOB_CIVILIAN)
  {
    if(!Drugs[playerid]) // Shortcut way to write 'if(x == 0)'.
      return SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have no drugs on you!"); // Stop the command here, no need to look through the other conditionals.
    else // If he has any at all.
    {
      new string[40]; // New variable (string) with a max. length of 40 characters.
      format(string, sizeof(string), "You have %d grams of drugs on you!", Drugs[playerid]); // Formatting the string to hold his current amount of drugs.
      return SendClientMessage(playerid, COLOR_LIGHTBLUE, string); // Sends the formatted string AND doesnt show 'SERVER: Unknown command.' message.
    }
  }
}
If you need to clarify the usage of this code, check the wiki out.

Hope it helps, and I am sure you can create great scripts without bugs or causing excessive lagging.

~Cueball~
Reply
#3

Thank you, I am now remaking the script by looking at your script and I must say thank you for taking time to help me out. Good luck to you!
Reply
#4

I like this idea. But to provide realisim cant u make a certain area (like a farm) a weed field and a ship for heroin.. Then the script would go up and youd be really famour (For doing first good public drugs script)

I tried and it didnt work out so well
Im looking in GMs for a drug script to extract
Reply
#5

Look up "IsPlayerInArea" for what you need.
Reply
#6

I have erorrs
Код:
: error 017: undefined symbol "gJob"
: warning 215: expression has no effect
: error 001: expected token: ";", but found "]"
: error 029: invalid expression, assumed zero
: fatal error 107: too many error messages on one line
Reply
#7

Upload the script to Pastebin along with the errors and lines. Ill look at it.
Reply
#8

Quote:
Originally Posted by klavins21
I have erorrs
Код:
: error 017: undefined symbol "gJob"
: warning 215: expression has no effect
: error 001: expected token: ";", but found "]"
: error 029: invalid expression, assumed zero
: fatal error 107: too many error messages on one line
those are all because you don't have the function gJob
Reply
#9

Quote:
Originally Posted by [NT
SpeedDevil ]
Quote:
Originally Posted by klavins21
I have erorrs
Код:
: error 017: undefined symbol "gJob"
: warning 215: expression has no effect
: error 001: expected token: ";", but found "]"
: error 029: invalid expression, assumed zero
: fatal error 107: too many error messages on one line
those are all because you don't have the function gJob
Why would a function be marked as global by it's name (marking it with a 'g' doesn't make it global, but used commonly to specify). Function's aren't the same as variables.

He is most likely missing this:
pawn Код:
new gJob[MAX_PLAYERS];
This is just a guess though, the array may be totally different.

~Cueball~
Reply
#10

yea, I meant variable sorry, you're right cueball by bad
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)