SA-MP Forums Archive
[Tutorial] Adding and Removing Mapped Objects to/from your Script - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Adding and Removing Mapped Objects to/from your Script (/showthread.php?tid=666713)



Adding and Removing Mapped Objects to/from your Script - KevTheJoker - 22.05.2019


Dual Gaming - Tutorial #1


Introduction
I've noticed that some tutorials are hard for persons who are opening pawno for the first time or those who are a bit or completely new to how scripting on SA-MP works. This is my first tutorial, and I hope it helps and aids those who are adding objects to their server or gamemode for the first time.

Mapping your objects
Mapping in SA-MP is quite easy, in my point of view. It simply needs patience, dedication and time. Some persons tend to become annoyed when they're mapping, and when things aren't going their way, they flip off. Trust me, it happens to me sometimes. You may map an object in a map editor, but after adding it to the gamemode or filterscript and testing it on the server, it doesn't give the output you expected. What I want you to do is take a deep breath, and aim towards fixing it, as if you've never had difficulties while mapping it.

I personally recommend two map editor softwares. They are: The SA-MP Map Editor is a software which is based on the default map of San Andreas. It covers the entire map, and it's used for adding, deleting, and editing objects of all kinds, sorts and models. It's easy to use, and after mapping a specific part of the map, you can click on "Show Code" to give you the codes of the Objects Created and Objects Deleted. On the other hand, the MTA map editor is mainly used for mapping MTA servers (no intentions in drawing your attention away from SA-MP and its Map Editor) but we're luckily able to convert the MTA Object Codes to SA-MP objects. Are you wondering where and how to do that? Simple, head over to https://convertffs.com/. After visiting this website, open your MTA map file (the file with the .map extension, e.g. TutorialMaps.map) which you saved via the MTA Map editor and copy its code. Paste the copied code into the dialog box on the convertffs website, and choose an OutPut mode. It's highly recommend to use CreateDynamicObjectEx when compiling object codes, because it caters for lags and avoids the objects limit. In some cases, you may find or see persons using CreateDynamicObject in their codes, but you'll get to know more about that (in-depth info) in the future.

Differences:
Differentiation and Specific Usages
If you're adding the mapped object codes to your .pwn gamemode file, found in the gamemode folder, place the codes under:
PHP Code:
public OnGameModeInit()
{
    
// Place the Codes here
    
return 1;

For adding the object codes to a filterscript's .pwn file, which can be found in the filterscripts folder, place them under:
PHP Code:
public OnFilterScriptInit()
{
    
// Place the Codes here
    
return 1;

For removing objects from the San Andreas Map, place the codes under:
PHP Code:
public OnPlayerRequestClass(playeridclassid)
{
    
// Codes
    
return 1;

OR

PHP Code:
public OnPlayerConnect(playerid)
{
        
// Codes
    
return 1;

For some persons, the objects may not be removed if you place them under public OnPlayerConnect(playerid), so public OnPlayerRequestClass(playerid, classid) is an alternative method.

Tip: You must add the streamer include to your pawno/includes folder (which can be found here: GitHub Releases).

How to add it to your .pwn gamemode file after placing it in the include folder? Look below (add it below #include <a_samp>[At the top of the script])
PHP Code:
#include <streamer> 
Good luck, and if you have comments/remarks, feel free to share them below. I might make tutorials of how to create certain stuff, like faction-related scripts, attaching items/objects to players/vehicles, creating login/register dialogs, how to built master-account scripts (which allows you to create a main account, and create characters afterwards in-game (step-by-step), and some other stuff!



Re: Adding and Removing Mapped Objects to/from your Script - GTLS - 02.07.2019

Decent tutorial, but you should also mention that only Dynamic Objects need streamer. Means, CreateObject function can be called without streamer. It is based on SAMP's default streamer. Also, Streamer requires plugin to be set up too. Its not your job to tell people that after you linked with Github but you mentioned how to add include in the GM, So I said you should mention about plugin too. Good job though.