Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - stormeus

Pages: 1 ... 59 60 [61] 62 63
901
mIRC/pawn Scripting / Re: !wep buy
« on: April 24, 2011, 11:27:42 pm »
Quote
   }
   else if (strcmp(cmd, "!wep", true) == 0) {
   new wep,pmon;
        pmon = GetPlayerMoney(playerid);
   tmp = strtok(cmdtext, idx);
   if(PlayerInfo[playerid][Logged] != 1) SendClientMessage(playerid, COLOR_RED, "You need to login first!");
   else if (!strlen(tmp)) SendClientMessage(playerid, COLOR_GREEN, "USAGE: !wep [WeaponName/ID]");
   else {
      wep = FindWepIDFromString(tmp);
      SetPlayerMoney(playerid,pmon - 1000);
        if(wep != 33) SetPlayerWeapon(playerid,wep,9999999);
      else SendClientMessage(playerid,COLOR_RED,"You can't get this weapon, sorry.");
   }
        if(pmon == 0) {
           SendClientMessage(playerid,COLOR_RED,"Sorry, you can't get this weapon, weapon costs: 1000$ !");
         }

I fix this...
Quote
if(pmon == 0) {
but when player money is 0 he can still get weapons..

That's because it doesn't check if the player's money is 0 first, but checks after it tries to give the player the weapon. By the way, if a weapon costs $1,000, you should check if the player has at least $1,000, and not if they have $0.

Under else if(!strlen(tmp)), use this:
Code: [Select]
else if(pmon < 1000) SendClientMessage(playerid, COLOR_RED, "Sorry, you can't get this weapon. Weapons cost $1,000!");

And then get rid of this:
Code: [Select]
if(pmon == 0){
    SendClientMessage(playerid,COLOR_RED,"Sorry, you can't get this weapon, weapon costs: 1000$ !");
}

902
Support / Re: How to kick
« on: April 24, 2011, 10:45:35 pm »
Delete where it says:
Code: [Select]
                return 1;
}

903
Support / Re: Internet Connect takes me to Single Player
« on: April 24, 2011, 10:43:40 pm »
That's solved, but now when I join a Server, My game crashes half-way through the Loading.

Do you have another Vice City or VC:MP window open?

904
Tutorials / The Absolute Beginner's Guide to Pawn, Part II
« on: April 24, 2011, 12:07:10 pm »
Part II
Control Structures

Introduction
Control flow is the order that Pawn (and any programming language) runs instructions and functions in. The use of loops and switch blocks can change the flow of a program, and repeat a piece of code or execute code specific to an expression.

If, Else If, Else
Toward the end of Part I, we learned about boolean algebra and comparison operators. Here's how such expressions would be used in Pawn. If, Else If, and Else are control statements, which "control" which pieces of code are run. For example, we might want a piece of code to run only if certain conditions are met.

Going back to our previous example with Alice, let's say we want to see how much a department should be paid based on the department ID. If we say new department is equal to 5, employees should be paid at least $25,000. If they're in department 3, they get paid more than $50,000. Otherwise, they should be paid exactly $40,000. In our main function, we have this so far:

Code: [Select]
main()
{
new department = 5;
}

This still doesn't tell us how much an employee should be paid in department 5, so we'll come back to this example.

The standard syntax for an if/else statement is:
Code: [Select]
if(expression)
{
// Expression is true.
// <code to run>
}
else if(expression)
{
// Other expression is true.
// <code to run>
}
else
{
// Neither are true.
// <code to run>
}

Keep in mind that you can have multiple else if statements in one conditional block and that else if statements are optional. Using this and our comparison operators, we can now make a conditional block to see how much a department gets paid, like so:

Code: [Select]
main()
{
new department = 5;
if(department == 5)
{
print("Employees get paid at least $25,000.");
}
else if(department == 3)
{
print("Employees get paid more than $50,000.");
}
else
{
print("Employees get paid exactly $40,000.");
}
}

For/While Loops and Switch
As well as conditional blocks of code, we can also run a piece of code as long as a given condition is true. For example, let's say we have a list of departments and we want to see how much each department is paid:

  • Department 1 - $10,000
  • Department 2 - $20,000
  • Department 3 - $30,000
  • Department 4 - $40,000
  • Department 5 - $50,000

If we wanted to go through each department, we could use a for or while loop. Let's start with the for loop.

The for loop looks a little something like this:
Code: [Select]
for(variable = counter; condition; counter++)
{
// <code>
}

Let's break this down.
variable is the variable we want to use as our counter. You can also declare a new variable inline like this:
Code: [Select]
for(new i = [...]

counter is the number we want to start counting from. Usually this is 0. In our case, it's 1.
condition is a condition we want to fulfill. As long as it's true, the for loop will run.
counter++ increments the counter by one. This can also be counter-- to reduce the counter by one.

In the end we get something like this:
Code: [Select]
for(new i = 1; i < 5; i++)
{
// <code>
}

With 1 being the first department and 5 being the last. Here's where we're also going to introduce switch blocks. Switch blocks consist of a variable and multiple "cases," which are one line long each. Each case is a possible value for the variable, and a default case can be used if none match.

Syntax for switch blocks
Code: [Select]
switch(variable)
{
case <case>:
// <one line of code>
case <case>:
// <one line of code>
default:
// <one line of code>
}

With each case being a possible value for variable. Now, let's say we want to get the payroll of a department, between 1 and 5. Here's how our switch block would look:

Code: [Select]
switch(i)
{
case 1:
print("Department 1 gets paid $10,000");
case 2:
print("Department 2 gets paid $20,000");
case 3:
print("Department 3 gets paid $30,000");
case 4:
print("Department 4 gets paid $40,000");
case 5:
print("Department 5 gets paid $50,000");
default:
print("Unknown department.");
}

After placing this in our for block, we get this:
Code: [Select]
for(new i = 1; i < 5; i++)
{
switch(i)
{
case 1:
print("Department 1 gets paid $10,000");
case 2:
print("Department 2 gets paid $20,000");
case 3:
print("Department 3 gets paid $30,000");
case 4:
print("Department 4 gets paid $40,000");
case 5:
print("Department 5 gets paid $50,000");
default:
print("Unknown department.");
}
}

Which will go through each department and print their payroll in the console, or "Unknown department." if the department does not exist. This same result can be achieved with a while loop, which executes a piece of code while a certain expression is true.

Syntax of a while loop
Code: [Select]
while(condition)
{
// <code here>
}

If we declare a variable named i and set it to 1, a while loop could be used like so:

Code: [Select]
new i = 1;
while(i < 5)
{
switch(i)
{
case 1:
print("Department 1 gets paid $10,000");
case 2:
print("Department 2 gets paid $20,000");
case 3:
print("Department 3 gets paid $30,000");
case 4:
print("Department 4 gets paid $40,000");
case 5:
print("Department 5 gets paid $50,000");
default:
print("Unknown department.");
}
i++;
}

With the i++; placed at the end to add 1 to the variable i so we don't have an endless loop, which can lead to memory leaks or crashes.

905
Support / Re: How to kick
« on: April 24, 2011, 11:09:18 am »
is this admin login like VC-MP

No, use /c kick instead of /kick
/c kick [player] [reason]

906
Support / Re: How to kick
« on: April 24, 2011, 10:49:22 am »
WHere is that script tell me

GUPS is a good starter script you can use to kick with reasons.
http://forum.vicecitymultiplayer.com/index.php?topic=1666.0

907
Support / Re: How to kick
« on: April 24, 2011, 10:48:06 am »
Thanx but how to kick withreason

You need to get or write a script that can do that.

908
Support / Re: How to kick
« on: April 24, 2011, 10:43:44 am »
hey problem !

What is the pass of admin and what is rcon and What is that Commadns Strike how to do

RCON is for server administration. The password is in server.cfg where it says "rcon_password"
When you get the password, type /admin password and then /kick playerid

EDIT: Strike beat me to it

909
Tutorials / The Absolute Beginner's Guide to Pawn, Part I
« on: April 24, 2011, 08:45:53 am »
Part I
Concepts of Pawn

Welcome to the absolute beginner's guide to Pawn! Before you can get into the nooks and crannies of Pawn, first we have to learn about the concepts of Pawn and programming in General.

Introduction
Pawn is an embeddable programming language and has a C-like syntax. Pawn was designed as an embeddable programming language, and is now used by projects like AMX Mod X, SA:MP, and, of course, VC:MP. Pawn scripts need to be compiled, or translate source code into computer-readable instructions. Pawn scripts have a structured flow, which means instructions are run one after another, but control statements can change what instructions come next.

The Compiler
The compiler translates source code into computer-readable code which will get run by the server. To use the compiler, you can download Pawno from the SA:MP server package, then go to Build > Compile. I recommend you use Pawno for this tutorial series so you can compile your test scripts and get compiler feedback if anything's wrong with the code.

Basic Program Structure
A very basic "Hello World" Pawn script would look like this:
Code: [Select]
main()
{
    print("Hello World!");
}

The main() function is the entry-point for the script, or where the program starts. The print() function writes a line of text in the console. The main() function doesn't concern us much in VC:MP scripting, but is good for printing script copyrights.

Note how the end of the Hello World line ends with a semicolon (;), but the rest of the code does not. That is because semicolons define where commands end, whereas control flow contains commands.

Variables
Variables are placeholders for information that a script can use, and can be changed at any time by the script. Variables are given names so we can not only get the variable's value, but so that we can also change it later if we need to. Variables can be assigned types so that their values can only be of a given type. Some common types are:

  • Integer: Sometimes represented as int, this is any integer or "whole" number.
  • Float: Stores decimals and any real number
  • Character: Or char, stores a letter, number, or punctuation. Arrays of characters create strings.

The only type that needs to be explicitly declared is a float. Otherwise, Pawn will assume that a variable is an integer, and that arrays are either strings or arrays of integers. However, variables still need to be declared at some point in the script. A variable declaration consists of the word new, followed by the name of the variable, and a semicolon. For example:

  • new myInt; defines a new integral variable named "myInt"
  • new Float:myFloat; defines a new floating point number named "myFloat" -- note the Type: prefix.

Boolean
Boolean algebra is when a mathematical expression is evaluated as either true or false. Therefore, a boolean value can only have one of two values: true or false. However, it evaluates entire expressions. Let's take a few expressions into consideration.

If I were to say 3 < (is less than) 6, obviously the statement is true.
If I were to say I am 5' 9" tall, this statement is also true.

However, if I were to say I am 5' 9" tall AND I am President of the United States, boolean logic states that the ENTIRE expression is false. While it may be true that I am 5' 9", I am not the President. Therefore, the entire expression is false.

A similar sentence: I am 5' 9" tall OR I am President of the United States.
Since only one part of the sentence has to be true, the entire sentence is considered true.

Note
0 is considered false, and 1 is considered true.

Boolean Operators
There are three boolean operators: AND, OR, and NOT. In Pawn:

  • AND is written as &&
  • OR is written as ||
  • NOT is written as !

Boolean operators are evaluated like so. For AND, the combination of two "True" values results in "True" while two "False" values results in "True." Any other combinations returns False. For example:

True AND True is true.
True AND False is false.
False AND True is false.
False AND False is true.

For OR, as long as one value is true, the entire statement is true.

True OR True is true.
True OR False is true.
False OR False is false.
False OR True is true.

The AND operator negates the value of an expression.
NOT True is false.
NOT False is true.

Comparison Operators
Boolean expressions most often involve comparison operators to see if they are true or false. These operators are equal to, greater than (or equal to), less than (or equal to), and not equal. In Pawn:

  • Equal to is written as ==
  • Less than is written as <
  • Greater than is written as >
  • Less than or equal to is written as <=
  • Greater than or equal to is written as >=
  • Inequality is written as !=

Comparison operators form expressions that can be evaluated as true or false. For example, Number_of_Students > 30. IF there are more than 30 students in the class, the entire expression is true. Otherwise, it is false.

Combining Boolean and Comparison Operators
We've looked at how boolean and comparison operators work to form expressions. Now, we'll look at how we can combine them to form more complex expressions.

If we wanted to know if there were more than 30 students in a class and if there were more than 30 seats, we could express this as:
Number_of_Students > 30 && Number_of_Seats > 30

Pawn has to determine the boolean (true/false) value of each expression, then use those values to evaluate the expression as a whole. Let's say we declare two new variables:
Code: [Select]
new Number_of_Students = 35;
new Number_of_Seats = 38;

Pawn will break this down into 35 > 30 && 38 > 30, which then evaluates to TRUE && TRUE. Therefore, the entire expression is true. The following example uses the following assumptions:

  • All employees work in a department.
  • All employees in department 5 have salaries greater than $25,000
  • Alice is an employee in department 5

Consider the truth of these few expressions:

Alice_salary < 25000 && Alice_department == 5
Alice_salary < 25000 is False. Alice_department == 5 is true. False && True is false.

!Alice_salary < 25000
Alice_salary < 25000 is false. NOT FALSE is true.

Appendix I: Mathematical Operators
Pawn offers mathematical operators as well if you wish to do math with scripts, which will come in handy a lot.
Note that "var" is shorthand for variable.

var + var - Addition
var - var - Subtraction
var * var - Multiplication
var / var - Division
var ^ power - Exponentiation
dividend % divisor - Modulus

variable += number - Adds number to variable and saves in variable
variable *= number - Multiplies number to variable and saves in variable
variable -= number - Subtracts number from variable and saves in variable
variable /= number - Divides number into variable and saves in variable

Appendix II: Comments
Comments allow you to make notes in your code to explain to people who might view it, including yourself, what a piece of code does. Comments can be one line long: one-line comments start with // and continue until the line ends. Multi-line comments begin with /* and end with */ and last between the two markers. Anything that is commented is NOT run or compiled.

Examples:
// One-line long comment
/* Multi
 * line
 * comment
 */

910
Tutorials / The Absolute Beginner's Guide to Pawn (w/ examples)
« on: April 24, 2011, 08:45:28 am »
NOTE
This topic is locked to prevent people from ruining the succession of posts while the guide is being written. PM any errors or suggestions to stormeus.

The Absolute Beginner's
Guide to Pawn


911
mIRC/pawn Scripting / Re: Drift Point = Money ?
« on: April 24, 2011, 08:17:21 am »
Thijin i lov Sql But the prop is it dont have a compiler! can u make 1?

Squirrel isn't a compilable language, so it's impossible to write a compiler for it.

912
Support / Re: Runs Singleplayer VC when I try to connect...
« on: April 24, 2011, 02:07:16 am »
Ehhh, no, in the mss folder there are 10 files, the only .flt in that folder is Reverb3.flt. The other names are Mp3dec.asi, Mssa3d.m3d, Mssa3d2.m3d, Mssds3dh.m3d, etc. I can copy the rest of those other names if that helps. And yes, i'll go look around the forums.

You probably didn't install VC:MP correctly. It should be installed in the same folder as Vice City. Usually that's C:\Program Files\Rockstar Games\Grand Theft Auto Vice City.

If it was installed correctly, there would be a vc-mp.flt in that folder.

913
mIRC/pawn Scripting / Re: MY Scripts!!!!
« on: April 22, 2011, 12:35:24 pm »
After doing some research, the problem comes from when you have a function which comes from a plugin, but you don't have the plugin library (a DLL). It could also happen when using a function in VCMP that isn't implemented.

Sources:
http://forum.sa-mp.com/showthread.php?t=121744
http://forum.sa-mp.com/showthread.php?t=95044
http://www.compuphase.com/bitboard/index.php?DATEIN=tpc_gbrdqxggg_1198248592
http://forum.vicecitymultiplayer.com/index.php?topic=2022.0

914
mIRC/pawn Scripting / Re: MY Scripts!!!!
« on: April 22, 2011, 10:25:48 am »
You You mean making a new scripts What about my commands!

No, don't get rid of your scripts. Just reinstall the server in a different folder and copy your scripts to the new folder.

915
Support / Re: Helppp
« on: April 22, 2011, 10:24:55 am »
Come on guys, it's a new player. No need to be mean. He can't ask another player if he can't talk to them, so be glad he even bothered to register an account here just to ask instead of giving up on the mod altogether like most would have done.

If that's referring to NC's post, it's probably referring to four people posting the same answer in the same thread even though the question's been answered.

Pages: 1 ... 59 60 [61] 62 63