[Help] DeleteObject
#1

Код:
    if(sscanf(params, "s", pstatus)) return SendClientMessage(playerid, 0xFFFFFF00, "USAGE: /pizza [out/in]");
    if(!strcmp(pstatus, "out", true, 3))
    {
   		GetPlayerPos(playerid, x, y, z);
   		cobjectid = CreateObject(1582, x, y, z, 0, 0, 0);
		AttachObjectToPlayer(cobjectid, playerid, OffsetX-0.1, OffsetY+0.18, OffsetZ-0.05, -90, 0, 0);
    }
    else if(!strcmp(pstatus, "in", true, 2))
    {
		DestroyObject(cobjectid);
    }
The problem is my object doesn't delete, any suggestions?
Reply
#2

Is cobjectid global, or do you create it in that command?

It should be global - move it on top of the script and it should work.
Reply
#3

cobjectid = CreateObject(1582, x, y, z, 0, 0, 0);

I added new cobjectid; on the top of the command yeah.
Reply
#4

but where do you define: new cobjectid? under oncommandtext or at the top coz it need to be global (at the top) or it is recreated when oncommandtext runs and efectly deleted

try printing cobjectid b4 you destroy it see what its value is
Reply
#5

Here's the full command, I changed the names a little though :P

Код:
CMD:penis(playerid, params[])
{
    new pstatus[32];
   	new cobjectid;
	new Float:x, Float:y, Float:z;
	new Float:OffsetX, Float:OffsetY, Float:OffsetZ;
	new message[128];
    if(sscanf(params, "s", pstatus)) return SendClientMessage(playerid, 0xFFFFFF00, "USAGE: /penis [Out/In]");
    if(!strcmp(pstatus, "out", true, 3))
    {
   		GetPlayerPos(playerid, x, y, z);
   		cobjectid = CreateObject(322, x, y, z, 0, 0, 0);
		AttachObjectToPlayer(cobjectid, playerid, OffsetX-0.1, OffsetY+0.18, OffsetZ-0.05, -90, 0, 0);
		format(message, sizeof(message), "AdmCmd: %s has put his penis out.", ReturnPlayerName(playerid));
		SendClientMessageToAll(COLOR_LIGHTRED, message);
    }
    else if(!strcmp(pstatus, "in", true, 2))
    {
		DestroyObject(cobjectid);
		format(message, sizeof(message), "AdmCmd: %s has put his penis in.", ReturnPlayerName(playerid));
		SendClientMessageToAll(COLOR_LIGHTRED, message);
    }
    return 1;
}
Reply
#6

yeah take new cobjectid;
out of the command and make it global by putting at the top of the script outside of all function most likely there will be some there allready and that should fix

soory you will need to make it
new cobjectid[MAX_PLAYERS];

and then call: cobjectid[playerid]

else you will del the objectid when another player uses it

*edit *edit *edit
Reply
#7

Quote:
Originally Posted by (SF)Noobanatior
Посмотреть сообщение
yeah take new cobjectid;
out of the command and make it global by putting at the top of the script outside of all function most likely there will be some there allready and that should fix

soory you will need to make it
new cobjectid[MAX_PLAYERS];

and then call: cobjectid[playerid]

else you will del the objectid when another player uses it

*edit *edit *edit
I don't really get it, wanna edit the command and paste it?
Reply
#8

pawn Код:
new cobjectid[MAX_PLAYERS];//move this to top of script
CMD:penis(playerid, params[])
{
    new pstatus[32];
    new Float:x, Float:y, Float:z;
    new Float:OffsetX, Float:OffsetY, Float:OffsetZ;
    new message[128];
    if(sscanf(params, "s", pstatus)) return SendClientMessage(playerid, 0xFFFFFF00, "USAGE: /penis [Out/In]");
    if(!strcmp(pstatus, "out", true, 3))
    {
                if(cobjectid[playerid] > 0) {
                     DestroyObject(cobjectid[playerid]);
                     cobjectid[playerid]=0;
                }
        GetPlayerPos(playerid, x, y, z);
        cobjectid[playerid] = CreateObject(322, x, y, z, 0, 0, 0);
        AttachObjectToPlayer(cobjectid[playerid], playerid, OffsetX-0.1, OffsetY+0.18, OffsetZ-0.05, -90, 0, 0);
        format(message, sizeof(message), "AdmCmd: %s has put his penis out.", ReturnPlayerName(playerid));
        SendClientMessageToAll(COLOR_LIGHTRED, message);
    }
    else if(!strcmp(pstatus, "in", true, 2))
    {
                cobjectid[playerid]=0;
        DestroyObject(cobjectid[playerid]);
        format(message, sizeof(message), "AdmCmd: %s has put his penis in.", ReturnPlayerName(playerid));
        SendClientMessageToAll(COLOR_LIGHTRED, message);
    }
    return 1;
}
there ya go have a look what i did
define the varable out side the function makes it global and not recreated when the function runs


there ya go
Reply
#9

Yup that works, time to compare it with my old command :P thanks.
Reply
#10

not a worrie try making two objects before you del one
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)