Remove user created objects
#1

Hi, i have a script /campfire then it makes an campfire, but if more people do it, it creates multiple objects, thats ok, but how can i make it when a player does /removecamp then only HIS campfire removes and not all of the campfires
Reply
#2

Create an array of size MAX_PLAYERS or the maximum players of your server. Store the object ID on those and you can then use it as per-player campfire control or remove them for a player only.
Reply
#3

hmm example? so i can use it for all the parts like the /tent
Reply
#4

Sure, here you go:
pawn Код:
new pObject[MAX_PLAYERS] = {INVALID_OBJECT_ID, ...};

public OnPlayerConnect(playerid)
{
    pObject[playerid] = INVALID_OBJECT_ID; //Resetting the variable so that there won't be further confusion.
    return 1;
}

//While creating object.
pObject[playerid] = CreateObject(....);

//While destroying the object:
DestroyObject(pObject[playerid]);
pObject[playerid] = INVALID_OBJECT_ID; //Also assign that array then to it's default value so later collission could be avoided.

//For checking if player has already created that stuff.
if(pObject[playerid] != INVALID_OBJECT_ID) //If the objectid array isn't at the invalid value, it means the object is created.
Reply
#5

aaaaaaaaaaaaah thats difficult haha but i will try it thankyou!
Reply
#6

it doesnt do anything, my script;

Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>

new pObject[MAX_PLAYERS] = {INVALID_OBJECT_ID, ...};

#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)
{
	pObject[playerid] = INVALID_OBJECT_ID;
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/campfire", cmdtext, true, 10) == 0)
	{
 	new Float:x, Float:y, Float:z;
  	new Float:a;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, a);
    if(pObject[playerid] != INVALID_OBJECT_ID) return SendClientMessage(playerid, -1, "You already have an campfire!");
	pObject[playerid] = CreateObject(841, x+5,y,12.5000000,0,0,a); // change the object id
	pObject[playerid] = CreateObject(841, x+5,y,12.5000000,0,0,a); // change the object id
	pObject[playerid] = CreateObject(841, x+5,y,12.5000000,0,0,a); // change the object id
	pObject[playerid] =  CreateObject(3461, x+5,y,11.0000000,0,0,a); // change the object id
	pObject[playerid] =  SendClientMessage(playerid, -1, "You made an campfire!");
	return 1;
	}
	if (strcmp("/removecamp", cmdtext, true, 10) == 0)
	{
		DestroyObject(pObject[playerid]);
		pObject[playerid] = INVALID_OBJECT_ID;
		return 1;
	}
	return 0;
}
Reply
#7

....
Reply
#8

....
Reply
#9

pawn Код:
#include <a_samp>

new pObject[4][MAX_PLAYERS] = {
    {INVALID_OBJECT_ID, ...},
    {INVALID_OBJECT_ID, ...},
    {INVALID_OBJECT_ID, ...},
    {INVALID_OBJECT_ID, ...}
};

DestroyCampFire(playerid)
{
    for(new i=0; i != sizeof(pObject); i++)
        if(pObject[i][playerid] != INVALID_OBJECT_ID)
        {
            DestroyObject(pObject[i][playerid]);
            pObject[i][playerid] = INVALID_OBJECT_ID;
        }
}

public OnPlayerDisconnect(playerid,reason)
{

    DestroyCampFire(playerid);

    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp("/campfire", cmdtext, true) == 0)
    {
        if(pObject[0][playerid] != INVALID_OBJECT_ID) SendClientMessage(playerid, -1, "You already have an campfire!");
        else{
            new Float:x, Float:y, Float:z, Float:a;
            GetPlayerPos(playerid, x, y, z);
            GetPlayerFacingAngle(playerid, a);
            pObject[0][playerid] = CreateObject(841, x+5,y,12.5000000,0,0,a); // change the object id
            pObject[1][playerid] = CreateObject(841, x+5,y,12.5000000,0,0,a); // change the object id
            pObject[2][playerid] = CreateObject(841, x+5,y,12.5000000,0,0,a); // change the object id
            pObject[3][playerid] = CreateObject(3461, x+5,y,11.0000000,0,0,a); // change the object id
            SendClientMessage(playerid, -1, "You made an campfire!");
        }
        return 1;
    }
    if(strcmp("/removecamp", cmdtext, true) == 0)
    {

        if(pObject[0][playerid] == INVALID_OBJECT_ID) SendClientMessage(playerid, -1, "You don't have an campfire!");
        else DestroyCampFire(playerid);

        return 1;
    }
    return 0;
}
Reply
#10

1 Error:

Код:
C:\Users\Luc\Desktop\Nieuwe map\filterscripts\Camp.pwn(83) : error 033: array must be indexed (variable "pObject")
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)