[Tutorial] Simple Ingame Mapper system [Yini|sscanf|zcmd|streamer]
#1

Ingame Mapper system
Using Yini, sscanf, zcmd & streamer plugins!


as first, We'll define the max objects.
add this in the top of your gamemode.

pawn Код:
#define MAX_OBJ 1001
Change ''1001'', with the maximum amounts of objects, that can be created ingame.

Then, We'll make some public defines, for the Editting & Duplicating of the mapper system.
Add this somewhere in the top of your gamemode.

pawn Код:
new oEdit[MAX_PLAYERS]; // checking if the player is editting an object.
new oEditID[MAX_PLAYERS]; // checking what id is getting editted.
new Float:oPos[MAX_PLAYERS][3]; // the old & new Positions from the object, ((edit mode))
new Float:oRot[MAX_PLAYERS][3]; // the old & new Rotations from the object, ((edit mode))
new oldoID; // Latest created or editted object id. for /duplicateobj!
new Float:oldodX, Float:oldodY, Float:oldodZ, Float:oldodRX, Float:oldodRY, Float:oldodRZ; // The rotations/positions from the last editted/created obj id.
Then, we'll add the obj info.

pawn Код:
enum objInfo
{
    obj, // The object id.
    Text3D:oText, // Text label.. attached to every object.
    oModel, // the Model id.
    Float:oX, // X postion from the object.
    Float:oY, // Y postion from the object.
    Float:oZ, // Z postion from the object.
    Float:oRX, // X Rotation from the object.
    Float:oRY, // Y Rotation from the object.
    Float:oRZ, // Z Rotation from the object.
}
new ObjInfo[MAX_OBJ][objInfo];
Then we will save & load the objects

The structure where we will save all objects.

pawn Код:
stock SaveObjects2()
{
    new idx = 1, File:file;
    new string[256];
    while(idx < MAX_OBJ)
    {
        format(string, sizeof(string), "%d|%f|%f|%f|%f|%f|%f\r\n",
        ObjInfo[idx][oModel],
        ObjInfo[idx][oX],
        ObjInfo[idx][oY],
        ObjInfo[idx][oZ],
        ObjInfo[idx][oRX],
        ObjInfo[idx][oRY],
        ObjInfo[idx][oRZ]);
        if(idx == 1)
        {
            file = fopen("objects22.cfg", io_write);
        }
        else
        {
            file = fopen("objects22.cfg", io_append);
        }
        fwrite(file, string);
        fclose(file);
        idx++;
    }
    print("Objects saved successfully.");
    return 1;
}

And the structure, where we will load the objects.


pawn Код:
stock LoadObjects()
{
    new dinfo[15][128];
    new string[256];
    new File:file = fopen("objects22.cfg", io_read);
    if(file)
    {
        new idx = 1;
        while(idx < MAX_OBJ)
        {
            fread(file, string);
            split(string, dinfo, '|');
            ObjInfo[idx][oModel] = strval(dinfo[0]);
            ObjInfo[idx][oX] = floatstr(dinfo[1]);
            ObjInfo[idx][oY] = floatstr(dinfo[2]);
            ObjInfo[idx][oZ] = floatstr(dinfo[3]);
            ObjInfo[idx][oRX] = floatstr(dinfo[4]);
            ObjInfo[idx][oRY] = floatstr(dinfo[5]);
            ObjInfo[idx][oRZ] = floatstr(dinfo[6]);
            if(ObjInfo[idx][oModel]) // If gate exists
            {
                ObjInfo[idx][obj] = CreateDynamicObject(ObjInfo[idx][oModel], ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], ObjInfo[idx][oRX], ObjInfo[idx][oRY], ObjInfo[idx][oRZ]);
                format(string, sizeof(string), "Object ID: %d (Model ID: %d)", idx, ObjInfo[idx][oModel]);
                ObjInfo[idx][oText] = CreateDynamic3DTextLabel(string, COLOR_GREY, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], 10);
            }
            idx++;
        }
    }
    print("Objects loaded successfully.");
    return 1;
}
We will define te ''split'' Also..

pawn Код:
stock split(const strsrc[], strdest[][], delimiter)
{
    new i, li;
    new aNum;
    new len;
    while(i <= strlen(strsrc))
    {
        if(strsrc[i] == delimiter || i == strlen(strsrc))
        {
            len = strmid(strdest[aNum], strsrc, li, i, 128);
            strdest[aNum][len] = 0;
            li = i+1;
            aNum++;
        }
        i++;
    }
    return 1;
}

Then we will set the variables on 0, for every player if they connect to the server.
add this to ''OnPlayerConnect''.

pawn Код:
oEdit[playerid] = 0;
    oEditID[playerid] = 0;
Here we will define some colors.. add this in the top of your script..

pawn Код:
#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COLOR_RED 0xAA3333AA
#define COLOR_BLUE 0x0000BBAA
#define COL_LIGHTBLUE "{00CED1}"
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_YELLOW 0xFFFF00FF
#define COLOR_PURPLE 0x800080FF
Then ofcourse, we have to save all objects, when the server will disconnect.
Add this under ''OngamemodeExit''.
pawn Код:
SaveObjects2();
   SaveObjects();
Then we will use the 0.3e dynamic obj system to edit objects.

Add this somewhere in your gamemode.

pawn Код:
public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
    new string[128], idx;
    idx = oEditID[playerid];
    if(response == EDIT_RESPONSE_UPDATE)
    {
        SetDynamicObjectPos(objectid, x, y, z);
        SetDynamicObjectRot(objectid, rx, ry, rz);
    }
    else if(response == EDIT_RESPONSE_CANCEL)
    {
        SetDynamicObjectPos(objectid, oPos[playerid][0], oPos[playerid][1], oPos[playerid][2]);
        SetDynamicObjectRot(objectid, oRot[playerid][0], oRot[playerid][1], oRot[playerid][2]);
        oPos[playerid][0] = 0; oPos[playerid][1] = 0; oPos[playerid][2] = 0;
        oRot[playerid][0] = 0; oRot[playerid][1] = 0; oRot[playerid][2] = 0;
        format(string, sizeof(string), " You have canceled editing object ID %d.", idx);
        SendClientMessage(playerid, COLOR_GREY, string);
    }
    else if(response == EDIT_RESPONSE_FINAL)
    {
        SetDynamicObjectPos(objectid, x, y, z);
        SetDynamicObjectRot(objectid, rx, ry, rz);
        if(oEdit[playerid] == 1)
        {
            oldoID = ObjInfo[idx][oModel];
            ObjInfo[idx][oX] = x;
            ObjInfo[idx][oY] = y;
            ObjInfo[idx][oZ] = z;
            ObjInfo[idx][oRX] = rx;
            ObjInfo[idx][oRY] = ry;
            ObjInfo[idx][oRZ] = rz;
            oldodX = ObjInfo[idx][oX];
            oldodY = ObjInfo[idx][oY];
            oldodZ = ObjInfo[idx][oZ];
            oldodRX = ObjInfo[idx][oRX];
            oldodRY = ObjInfo[idx][oRY];
            oldodRZ = ObjInfo[idx][oRZ];
            if(IsValidDynamic3DTextLabel(ObjInfo[idx][oText])) DestroyDynamic3DTextLabel(ObjInfo[idx][oText]);
            format(string, sizeof(string), "Object ID: %d (Model ID: %d)", idx, ObjInfo[idx][oModel]);
            ObjInfo[idx][oText] = CreateDynamic3DTextLabel(string, COLOR_GREY, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], 10);
            oEdit[playerid] = 0;
            oEditID[playerid] = 0;
            format(string, sizeof(string), " You have finished editing object ID %d's position.", idx);
            SendClientMessage(playerid, COLOR_GREY, string);
        }
    }
    return 1;
}
Also, We need commands, to use it.

add this to your commands.

pawn Код:
CMD:maptool(playerid, params[])
{
    SendClientMessage(playerid, COLOR_PURPLE, "_____________________________________________________");
    SendClientMessage(playerid, COLOR_RED, "*Mapper Commands: {FFFFFF}/createobj /editobj /deleteobj");
    SendClientMessage(playerid, COLOR_RED, "*Mapper Commands: {FFFFFF}/nearobj /duplicateobj /gotoobj /saveobjects");
    SendClientMessage(playerid, COLOR_PURPLE, "_____________________________________________________");
    return 1;
}

CMD:createobj(playerid, params[])
{
    new string[128], object;
    if(sscanf(params, "i", object)) return SendClientMessage(playerid, COLOR_GREY, "[Usage]: /createobj [objectid]");

    for(new idx=1; idx<MAX_OBJ; idx++)
    {
        if(!ObjInfo[idx][oModel])
        {
            GetPlayerPos(playerid, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ]);
            ObjInfo[idx][oModel] = object;
            oldoID = ObjInfo[idx][oModel];
            oldodX = ObjInfo[idx][oX];
            oldodY = ObjInfo[idx][oY];
            oldodZ = ObjInfo[idx][oZ];
            oldodRX = ObjInfo[idx][oRX];
            oldodRY = ObjInfo[idx][oRY];
            oldodRZ = ObjInfo[idx][oRZ];
            ObjInfo[idx][oX] = ObjInfo[idx][oX] + 2;
            ObjInfo[idx][oY] = ObjInfo[idx][oY] + 2;
            ObjInfo[idx][oRX] = 0;
            ObjInfo[idx][oRY] = 0;
            ObjInfo[idx][oRZ] = 0;
            // Creating
            format(string, sizeof(string), "Object ID: %d (Model ID: %d)", idx, ObjInfo[idx][oModel]);
            ObjInfo[idx][obj] = CreateDynamicObject(ObjInfo[idx][oModel], ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], ObjInfo[idx][oRX], ObjInfo[idx][oRY], ObjInfo[idx][oRZ]);
            ObjInfo[idx][oText] = CreateDynamic3DTextLabel(string, COLOR_GREY, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], 10);
            // Text
            idx = MAX_OBJ;
        }
    }
    return 1;
}

CMD:duplicateobj(playerid, params[])
{
        new string[128] ,idx;
        for(idx=1; idx<MAX_OBJ; idx++)
        {
            if(!ObjInfo[idx][oModel])
            {
                ObjInfo[idx][oModel] = oldoID;
                ObjInfo[idx][oX] = oldodX;
                ObjInfo[idx][oY] = oldodY;
                ObjInfo[idx][oZ] = oldodZ;
                ObjInfo[idx][oRX] = oldodRX;
                ObjInfo[idx][oRY] = oldodRY;
                ObjInfo[idx][oRZ] = oldodRZ;
                // Creating
                ObjInfo[idx][obj] = CreateDynamicObject(oldoID, oldodX, oldodY, oldodZ, oldodRX, oldodRY, oldodRZ);
                ObjInfo[idx][oText] = CreateDynamic3DTextLabel(string, COLOR_GREY, oldodX, oldodY, oldodZ, 10);
                // Text
                idx = MAX_OBJ;
            }
        }
        return 1;
}



CMD:nearobj(playerid, params[])
{
    new string[128];
    for(new idx=1; idx<MAX_OBJ; idx++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 5, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ]))
        {
            format(string, sizeof(string), "Nearest Object ID: %d", idx);
            SendClientMessage(playerid, COLOR_PURPLE, string);
            return 1;
        }
    }
    SendClientMessage(playerid, COLOR_GREY, "You are not near a object!");
    return 1;
}

CMD:editobj(playerid, params[])
{
    new string[128], idx;
    if(sscanf(params, "i", idx)) return SendClientMessage(playerid, COLOR_GREY, "[Usage]: /editobj [objectid]");
    if(!ObjInfo[idx][oModel]) return SendClientMessage(playerid, COLOR_GREY, "Invalid object id.");
    oEdit[playerid] = 1;
    oEditID[playerid] = idx;
    GetDynamicObjectPos(ObjInfo[idx][obj], oPos[playerid][0], oPos[playerid][1], oPos[playerid][2]);
    GetDynamicObjectRot(ObjInfo[idx][obj], oRot[playerid][0], oRot[playerid][1], oRot[playerid][2]);
    EditDynamicObject(playerid, ObjInfo[idx][obj]);
    format(string, sizeof(string), " You are now editing object ID %d's position.", idx);
    SendClientMessage(playerid, COLOR_GREY, string);
    return 1;
}

CMD:deleteobj(playerid, params[])
{
    new idx, string[128];
    if(sscanf(params, "i", idx)) return SendClientMessage(playerid, COLOR_GREY, "[Usage]: /deleteobj [objid]");
    if(!ObjInfo[idx][oModel]) return SendClientMessage(playerid, COLOR_GREY, "Invalid object id.");
    ObjInfo[idx][oModel] = 0;
    ObjInfo[idx][oX] = 0;
    ObjInfo[idx][oY] = 0;
    ObjInfo[idx][oZ] = 0;
    ObjInfo[idx][oRX] = 0;
    ObjInfo[idx][oRY] = 0;
    ObjInfo[idx][oRZ] = 0;
    DestroyDynamicObject(ObjInfo[idx][obj]);
    DestroyDynamic3DTextLabel(ObjInfo[idx][oText]);
    return 1;
}

CMD:gotoobj(playerid, params[])
{
    new idx, string[128], string2[128];
    if(sscanf(params, "i", idx)) return SendClientMessage(playerid, COLOR_GREY, "[Usage]: /gotoobj [objectid]");
    if(!ObjInfo[idx][oModel]) return SendClientMessage(playerid, COLOR_GREY, "Invalid object id.");
    SetPlayerPos(playerid, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ]);
    format(string, sizeof(string), " You have teleported to object ID %d.", idx);
    SendClientMessage(playerid, COLOR_GREY, string);
    return 1;
}

CMD:saveobjects(playerid, params[])
{
    new string[128];
    SendClientMessage(playerid, COLOR_RED, "Objects have been saved!");
    SaveObjects();
    SaveObjects2();
    return 1;
}
We dont need to get the player name everytime.. So i used ''rpn''.
Add this in your gamemode.

pawn Код:
stock RPN(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if(name[i] == '_') name[i] = ' ';
    }
    return name;
}
Then ofcourse, those Textlabers are stupid.
Then we will make an extra save option.
That will save all objects in a file in the ''CreateDynamicObject'' Structure.

Add this..

pawn Код:
stock SaveObjects()
{
    new idx = 1, File:file;
    new string[256];
    while(idx < MAX_OBJ)
    {
        format(string, sizeof(string), "    CreateDynamicObject(%d,%f,%f,%f,%f,%f,%f);\r\n",
        ObjInfo[idx][oModel],
        ObjInfo[idx][oX],
        ObjInfo[idx][oY],
        ObjInfo[idx][oZ],
        ObjInfo[idx][oRX],
        ObjInfo[idx][oRY],
        ObjInfo[idx][oRZ]);
        if(idx == 1)
        {
            file = fopen("objects.cfg", io_write);
        }
        else
        {
            file = fopen("objects.cfg", io_append);
        }
        fwrite(file, string);
        fclose(file);
        idx++;
    }
    print("Objects saved successfully.");
    return 1;
}
You have to create a empty ''objects.cfg'' & ''objects22.cfg'' file in your scriptfiles folder.

To save all your objects in the the gamemode.
Paste all codes from objects.cfg and paste them under ''ongamemodeinit''.
then make your Two .cfg files empty.
& save them.


Thanks for reading this tutorial, sorry for my bad english.
rep+ is always welcome.


Reply
#2

Wow!
Nice Faff.
REP for you!
Reply
#3

This is not a tutorial.
Just Copy + Paste
Reply
#4

Everytime I add the loadobject stock into my script it bugs it and it stops compiling..
Reply
#5

This system is copied from the International Roleplay gamemode,that you stole you didn't invent this,Mike did
The cmds are the same,everything is the same...don't take credit for someone else's work.
Oh and also there's not a single y_ini function in this code...learn the basics before you post...(facepalm)
Oh and since you stole the bugged version of i-rp you don't know that the duplicate cmd will NEVER work like this...Mike fixed it after you stole the buggy version
This cmd will just duplicate the last object created,not any object you wish.That's why smart people use sscanf to select the object id they want to duplicate,but how should you know that,you're not a scripter,just a thief
Reply
#6

1) "Put this somewhere in your GM"
2) "Put that somewhere"
3) It's buggy, and lastly
4) https://sampforum.blast.hk/showthread.php?tid=65567
Why ****** wrote a tutorial on how to write a tutorial makes sense.
Reply
#7

Good attempt.
Reply
#8

Just adding some steps and codes won't just make it like a tutorial. Explain it well, including the codes so that it will be regarded as a tutorial and everyone will be understanding. Better luck next time.
Reply
#9

Quote:
Originally Posted by Lordz™
Посмотреть сообщение
Just adding some steps and codes won't just make it like a tutorial. Explain it well, including the codes so that it will be regarded as a tutorial and everyone will be understanding. Better luck next time.
He doesn't know that,as he just stole a GM and copy-pasted the codes...He doesn't even understand what the functions are actually doing and the proper syntax,in which they should be used.
Reply
#10

Penki4a, I-RP had a whole another system.
They aint havin all those commands.
I made this, The Fact that it's looking like the one from IRP, Is becuz it's in the same structure. (Both Zgaming).
Thanks


Edit;
to the others, Thanks for the comments, I will work on this for my next tutorial.
Reply
#11

lolwtf is this shit?
where's the explanaaaation?
Reply
#12

.......
Reply
#13

Awesome!

One question, what is split used for?
Reply
#14

Good Tutorial
+Rep
Reply
#15

Stolen. Not a good tutorial anyways.
Reply
#16

Copy + Paste o.o
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)