Author Topic: [TUTORIAL] How to script? (For beginner)  (Read 290 times)

xian

  • Administrator
  • Newbie
  • **********
  • Posts: 8
  • Reputation: 0
    • View Profile
[TUTORIAL] How to script? (For beginner)
« on: April 21, 2013, 09:44:50 pm »
So, this is my first attempt to make a tutorial. :3

First, you need to download the package here if you're using Windows or here if you're using Linux 32 bit.

After installed, extract it to a folder.

And open pawno > pawno.exe.
*Note: If you're using Windows Vista or higher, you must right click > Run as administrator. If not, you will get a warning: "Couldn't be executed" or w/e...

After open it, press the new button. After open it, this is your first script. :3

Code: [Select]
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Blank Filterscript by your name here");
print("--------------------------------------\n");
return 1;
}

public OnFilterScriptExit()
{
return 1;
}

#else

main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}

#endif

public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}

public OnGameModeExit()
{
return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}

public OnPlayerConnect(playerid)
{
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
return 1;
}

public OnPlayerSpawn(playerid)
{
return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}

public OnVehicleSpawn(vehicleid)
{
return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}

public OnPlayerText(playerid, text[])
{
return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}

public OnRconCommand(cmd[])
{
return 1;
}

public OnPlayerRequestSpawn(playerid)
{
return 1;
}

public OnObjectMoved(objectid)
{
return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}

public OnPlayerExitedMenu(playerid)
{
return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}

public OnPlayerUpdate(playerid)
{
return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}

So, as you see this is your first script... Let's start making your first own gamemode!
So, let's change this thing.
Code: [Select]
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
to
Code: [Select]
main()
{
print("\n----------------------------------");
print(" Tutorial by xian");
print("----------------------------------\n");
}

Alright, after change it, we'll start to make commands!
Find public OnPlayerCommandText...
Code: [Select]
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}

Now, let's do something with it!
Code: [Select]
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/help", cmdtext, true, 10) == 0)
{
SendClientMessage(playerid, 0xFFFF00AA, "This is help from the server.");
return 1;
}
return 0;
}

Of course, you can add anything you like in it!
But if you want to make another command... You need to be pay more attention now.
Code: [Select]
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/help", cmdtext, true, 10) == 0)
{
SendClientMessage(playerid, 0xFFFF00AA, "This is help from the server.");
return 1;
}

if (strcmp("/test", cmdtext, true, 10) == 0)
{
    SendClientMessage(playerid, 0xFFFFFFAA, "This is a test message");
    return 1;
}
return 0;
}

After make it (You can make any numbers of commands in your gamemode!)

Now, let's add something to OnPlayerConnect!
Code: [Select]
public OnPlayerConnect(playerid)
{
return 1;
}

Alright, let's start!
Code: [Select]
public OnPlayerConnect(playerid)
{
SendClientMessage(playerid, 0x00FFFFAA, "Welcome to My Tutorial Server!");
return 1;
}

Alright, but if you want to add string, let's start with it.
We'll create two new's, these are: name and string.
Code: [Select]
new name[25], string[100];
Why do I put 25 strings on name but not a higher string? Reason: "The SAMP name character has only 24 characters, so don't put them higher than 25, but if you unsure with this, put name[MAX_PLAYER_NAME]"

Now, let's do something on name and string!
Code: [Select]
GetPlayerName(playerid, name,sizeof(name));
format(string,sizeof(string), "Player %s has joined the server.", name);

Alright, it's done, but we haven't give it a callback, add SendClientMessageToAll.
Code: [Select]
GetPlayerName(playerid,name,sizeof(name));
format(string,sizeof(string), "Player %s has joined the server!", name);
SendClientMessageToAll(-1, string);

The entire code should be like this.
Code: [Select]
public OnPlayerConnect(playerid)
{
new name[MAX_PLAYER_NAME], string[100];
SendClientMessage(playerid, 0x00FFFFAA, "Welcome to My Tutorial Server!");
GetPlayerName(playerid,name,sizeof(name));
format(string,sizeof(string), "Player %s has joined the server!", name);
SendClientMessageToAll(-1, string);
return 1;
}

So, do the same to the OnPlayerDisconnect, just remove the "SendClientMessage(playerid, 0x00FFFFAA, "Welcome to My Tutorial Server!");" and replace "joined" to "leave".

So, the code should be like this.
Code: [Select]
public OnPlayerDisconnect(playerid, reason)
{
new name[MAX_PLAYER_NAME], string[100];
GetPlayerName(playerid,name,sizeof(name));
format(string,sizeof(string), "Player %s has left the server!", name);
SendClientMessageToAll(-1, string);
return 1;
}

So, I think I'm done here. If you've any suggestion or problem, please reply here.
« Last Edit: April 21, 2013, 10:05:06 pm by xian »

Share on Bluesky Share on Facebook


Zero Nub Scripter

  • Newbie
  • *
  • Posts: 3
  • Reputation: 0
    • View Profile
Re: [TUTORIAL] How to script? (For beginner)
« Reply #1 on: April 21, 2013, 09:50:04 pm »
LOL -.- , I Am Full Of Spirit To Learn When i See "To be continue....." ._.

KiNG3

  • Global Moderator
  • Newbie
  • ********
  • Posts: 10
  • Reputation: 0
    • View Profile
Re: [TUTORIAL] How to script? (For beginner)
« Reply #2 on: April 25, 2013, 06:49:59 am »
Sorry, but this is the worst tutorial...

All your doing is

OKAY GUYS, STEP 1 DO THIS, THEN DO THIS.... Their are a lot of newbies out there that don't understand some things, could at least explain some stuff to them. Like what a public is, what SendClientMessage is