[Tutorial] Adding and Removing Mapped Objects to/from your Script

Started by SA:MP, May 05, 2023, 05:48 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SA:MP

[Tutorial] Adding and Removing Mapped Objects to/from your Script



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:

  • CreateDynamicObjectEx - allows you to change the draw distance (how many objects a player can see from their distance) and show the object for various worlds, interiors or players.

  • CreateDynamicObject - has no settings to allow players to view objects from a far distance (streaming many at one time) and such objects can only be seen in one world or interior.

  • CreateObject - is default. However, it only limits you to a certain amount of objects (which can be seen here: https://sampwiki.blast.hk/wiki/Limits)

  • RemoveBuildingForPlayer - this removes the buildings and objects for players.


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!

Source: [Tutorial] Adding and Removing Mapped Objects to/from your Script