Part I: Concepts (http://forum.vicecitymultiplayer.com/index.php?topic=2708.msg20176#msg20176) | Part II: Control Structures (http://forum.vicecitymultiplayer.com/index.php?topic=2708.msg20194#msg20194) | Part III: Arrays and Strings (http://forum.vicecitymultiplayer.com/index.php?topic=2708.msg20255#msg20255) |
Part IV: Basic Functions/Constructs (http://forum.vicecitymultiplayer.com/index.php?topic=2708.msg24354#msg24354) | Part V: Introduction to VC:MP Functions (http://forum.vicecitymultiplayer.com/index.php?topic=2708.msg28110#msg28110) | Part VI: Introduction to VC:MP Callbacks (http://forum.vicecitymultiplayer.com/index.php?topic=2708.msg28111#msg28111) |
main()
{
print("Hello World!");
}
new Number_of_Students = 35;
new Number_of_Seats = 38;
main()
{
new department = 5;
}
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>
}
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(variable = counter; condition; counter++)
{
// <code>
}
for(new i = [...]
for(new i = 1; i < 5; i++)
{
// <code>
}
switch(variable)
{
case <case>:
// <one line of code>
case <case>:
// <one line of code>
default:
// <one line of code>
}
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.");
}
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.");
}
}
while(condition)
{
// <code here>
}
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++;
}
// Declare our new array
new payrollArray[5];
// Iterate through each department.
for(new i = 1; i < 5; i++)
{
// <code here>
}
// Declare our new array.
new payrollArray[5];
// Iterate through each department.
for(new i = 1; i < 5; i++)
{
// i - 1 = DepartmentID - 1, for our zero-indexed array
payrollArray[i - 1] = i * 10000; // Department ID * 10000
}
new a = 1;
new b = a;
new c = b;
new d = a;
print(d + c + b + a);
Callback Name | What it's used for | Syntax |
OnGameModeInit | The script is loaded. | forward OnGameModeInit() |
OnGameModeExit | The script exits/server stops. | forward OnGameModeExit() |
OnFilterScriptInit | A filterscript (to be discussed later) is loaded. | forward OnFilterScriptInit() |
OnFilterScriptExit | A filterscript unloads/server stops. | forward OnFilterScriptExit() |
OnPlayerConnect | A player joins the server. | forward OnPlayerConnect( playerid ); |
OnPlayerDisconnect | A player leaves, crashes, or times out. | forward OnPlayerDisconnect( playerid, reason ); |
OnPlayerSpawn | A player spawns. | forward OnPlayerSpawn( playerid, classid ); |
OnPlayerDeath | A player dies or is killed. | forward OnPlayerDeath( playerid, killerid, reason, bodypart ); |
OnPlayerText | A player talks in chat. | forward OnPlayerText( playerid, message[] ); |
OnPlayerCommandText | A player uses a /c command. | forward OnPlayerCommandText( playerid, text[] ); |
OnPlayerRequestClass | A player requests a class. | forward OnPlayerRequestClass( playerid, classid ); |
OnPlayerEnterVehicle | A player gets in a vehicle. | forward OnPlayerEnterVehicle( playerid, vehicleid, isPassenger ); |
OnPlayerExitVehicle | A player leaves a vehicle. | forward OnPlayerExitVehicle( playerid, vehicleid ); |
OnPickedUp | A pickup is picked up. | forward OnPickedUp( playerid, pickupid ); |
OnRconCommand | An RCON command is used. | forward OnRconCommand( cmdtext[] ); |