How to CreateDynamicObject on player death?
#1

Someone know how to do so, when the player die, i CreateDynamicObject... then other player can come to /command and then DestroyDynamicObject?


thank you, i m new in this sorry i don't want to disturb,maybe one day i can give advices to other noobs like me
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=657226


stick to 1 thread.
Reply
#3

Quote:
Originally Posted by DBZdabIt3Bro7
Посмотреть сообщение
But no one tells me.. only i want to know how to do it propely.. array? Enum? ..
Reply
#4

Woo, way to spend my evening.

pawn Код:
#define DEATH_OBJ_MODEL       1313
#define MAX_DEATH_OBJECTS     500

new Float:dPos[MAX_PLAYERS][3];
enum e_deathObjects {
    OBJ_CODE,
    Float:OBJ_POS[3]
};
new objData[MAX_DEATH_OBJECTS][e_deathObjects];

public OnPlayerDeath(playerid, killerid, reason) {
    GetPlayerPos(playerid, dPos[playerid][0], dPos[playerid][1], dPos[playerid][2]); //Get the player's position upon death.
   
    for(new i = 0; i < _:e_deathObjects; i++) { // Loop through the enum.
        if(objData[i][OBJ_CODE] == EOS) { //If the OBJ_CODE is inexistent in index "i", proceed:
            //Set the objects' coordinates to the player's death position.
            objData[i][OBJ_POS][0] = dPos[playerid][0];
            objData[i][OBJ_POS][1] = dPos[playerid][1];
            objData[i][OBJ_POS][2] = dPos[playerid][2];

            //Create the object and give it an ID so that we can run checks on it later.
            objData[i][OBJ_CODE] = CreateDynamicObject(DEATH_OBJ_MODEL, objData[i][OBJ_POS][0], objData[i][OBJ_POS][1], objData[i][OBJ_POS][2], 0.0, 0.0, 0.0);
           
            //Debugging, you can remove this,
            new str[144];
            format(str, sizeof str, "Created obj %i at index %i", objData[i][OBJ_CODE], i);
            SendClientMessage(playerid, -1, str);

            break;
        }
    }

    return 1;
}

cmd:near(playerid, params[]) {
    for(new i = 0; i < _:e_deathObjects; i++) {
        if(IsPlayerInRangeOfPoint(playerid, 2.0, objData[i][OBJ_POS][0], objData[i][OBJ_POS][1], objData[i][OBJ_POS][2])) { //If the player is in range of an object...
           
            new infoMessage[144];
            format(infoMessage, sizeof infoMessage, "Info: You are near object ID %i", objData[i][OBJ_CODE]);
            SendClientMessage(playerid, -1, infoMessage);
           
            DestroyDynamicObject(objData[i][OBJ_CODE]); //Destroy tge object.
           
           
            objData[i][OBJ_CODE] = EOS; //Reset OBJ_CODE so that we can re-use the object ID and the enum's index.
            for(new j = 0; j < _:e_deathObjects; j++) {
                objData[i][OBJ_POS][j] = EOS;
            }

            return 1;
        }
    }

    SendClientMessage(playerid, -1, "Info: You are not near any object.");

    return 1;
}
Here's a video of this feature put to use:


I tried to comment the code as much as I could so that you could understand what's going on. If you have any doubts, feel free to ask.
Reply
#5

Quote:
Originally Posted by GRiMMREAPER
Посмотреть сообщение
Woo, way to spend my evening.

pawn Код:
#define DEATH_OBJ_MODEL       1313
#define MAX_DEATH_OBJECTS     500

new Float:dPos[MAX_PLAYERS][3];
enum e_deathObjects {
    OBJ_CODE,
    Float:OBJ_POS[3]
};
new objData[MAX_DEATH_OBJECTS][e_deathObjects];

public OnPlayerDeath(playerid, killerid, reason) {
    GetPlayerPos(playerid, dPos[playerid][0], dPos[playerid][1], dPos[playerid][2]); //Get the player's position upon death.
   
    for(new i = 0; i < _:e_deathObjects; i++) { // Loop through the enum.
        if(objData[i][OBJ_CODE] == EOS) { //If the OBJ_CODE is inexistent in index "i", proceed:
            //Set the objects' coordinates to the player's death position.
            objData[i][OBJ_POS][0] = dPos[playerid][0];
            objData[i][OBJ_POS][1] = dPos[playerid][1];
            objData[i][OBJ_POS][2] = dPos[playerid][2];

            //Create the object and give it an ID so that we can run checks it it later.
            objData[i][OBJ_CODE] = CreateDynamicObject(DEATH_OBJ_MODEL, objData[i][OBJ_POS][0], objData[i][OBJ_POS][1], objData[i][OBJ_POS][2], 0.0, 0.0, 0.0);
           
            //Debugging, you can remove this,
            new str[144];
            format(str, sizeof str, "Created obj %i at index %i", objData[i][OBJ_CODE], i);
            SendClientMessage(playerid, -1, str);

            break;
        }
    }

    return 1;
}

cmd:near(playerid, params[]) {
    for(new i = 0; i < _:e_deathObjects; i++) {
        if(IsPlayerInRangeOfPoint(playerid, 2.0, objData[i][OBJ_POS][0], objData[i][OBJ_POS][1], objData[i][OBJ_POS][2])) { //If the player is in range of an object...
           
            new infoMessage[144];
            format(infoMessage, sizeof infoMessage, "Info: You are near object ID %i", objData[i][OBJ_CODE]);
            SendClientMessage(playerid, -1, infoMessage);
           
            DestroyDynamicObject(objData[i][OBJ_CODE]); //Destroy tge object.
           
           
            objData[i][OBJ_CODE] = EOS; //Reset OBJ_CODE so that we can re-use the object ID and the enum's index.
            for(new j = 0; j < _:e_deathObjects; j++) {
                objData[i][OBJ_POS][j] = EOS; // Reset the object's position.
            }

            return 1;
        }
    }

    SendClientMessage(playerid, -1, "Info: You are not near any object.");

    return 1;
}
Here's a video of this feature put to use:


I tried to comment the code as much as I could so that you could understand what's going on. If you have any doubts, feel free to ask.
You are very good man, you saved my life shiet <3 good vibes !!!
Reply
#6

I must add that you don't need to type /kill for the object to be dropped — it will drop automatically upon death, but you might've figured that out by looking at the code.
Reply
#7

Quote:
Originally Posted by GRiMMREAPER
Посмотреть сообщение
I must add that you don't need to type /kill for the object to be dropped — it will drop automatically upon death, but you might've figured that out by looking at the code.
Yes man ,it's very nice skill, i knew my fail was not using [MAX_PLAYERS] and the for loop (that i m learning in C tutorials now xD) thank you a lot bro <3
Reply
#8

Quote:
Originally Posted by GRiMMREAPER
Посмотреть сообщение
Woo, way to spend my evening.

pawn Код:
#define DEATH_OBJ_MODEL       1313
#define MAX_DEATH_OBJECTS     500

new Float:dPos[MAX_PLAYERS][3];
enum e_deathObjects {
    OBJ_CODE,
    Float:OBJ_POS[3]
};
new objData[MAX_DEATH_OBJECTS][e_deathObjects];

public OnPlayerDeath(playerid, killerid, reason) {
    GetPlayerPos(playerid, dPos[playerid][0], dPos[playerid][1], dPos[playerid][2]); //Get the player's position upon death.
   
    for(new i = 0; i < _:e_deathObjects; i++) { // Loop through the enum.
        if(objData[i][OBJ_CODE] == EOS) { //If the OBJ_CODE is inexistent in index "i", proceed:
            //Set the objects' coordinates to the player's death position.
            objData[i][OBJ_POS][0] = dPos[playerid][0];
            objData[i][OBJ_POS][1] = dPos[playerid][1];
            objData[i][OBJ_POS][2] = dPos[playerid][2];

            //Create the object and give it an ID so that we can run checks it it later.
            objData[i][OBJ_CODE] = CreateDynamicObject(DEATH_OBJ_MODEL, objData[i][OBJ_POS][0], objData[i][OBJ_POS][1], objData[i][OBJ_POS][2], 0.0, 0.0, 0.0);
           
            //Debugging, you can remove this,
            new str[144];
            format(str, sizeof str, "Created obj %i at index %i", objData[i][OBJ_CODE], i);
            SendClientMessage(playerid, -1, str);

            break;
        }
    }

    return 1;
}

cmd:near(playerid, params[]) {
    for(new i = 0; i < _:e_deathObjects; i++) {
        if(IsPlayerInRangeOfPoint(playerid, 2.0, objData[i][OBJ_POS][0], objData[i][OBJ_POS][1], objData[i][OBJ_POS][2])) { //If the player is in range of an object...
           
            new infoMessage[144];
            format(infoMessage, sizeof infoMessage, "Info: You are near object ID %i", objData[i][OBJ_CODE]);
            SendClientMessage(playerid, -1, infoMessage);
           
            DestroyDynamicObject(objData[i][OBJ_CODE]); //Destroy tge object.
           
           
            objData[i][OBJ_CODE] = EOS; //Reset OBJ_CODE so that we can re-use the object ID and the enum's index.
            for(new j = 0; j < _:e_deathObjects; j++) {
                objData[i][OBJ_POS][j] = EOS; // Reset the object's position.
            }

            return 1;
        }
    }

    SendClientMessage(playerid, -1, "Info: You are not near any object.");

    return 1;
}
Here's a video of this feature put to use:


I tried to comment the code as much as I could so that you could understand what's going on. If you have any doubts, feel free to ask.
But man, why

objData[i][OBJ_POS][j] = EOS ?

this is causing

Код:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at index 3 past array upper bound 2
[debug] AMX backtrace:
[debug] #0 001d85e4 in public cmd_proba (playerid=0, params[]=@0x00899184 "") at C:\Reality Roleplay\gamemodes\roleplay.pwn:28323
[debug] #1 native CallLocalFunction () [004743b0] from samp-server.exe
[debug] #2 0001e45c in public OnPlayerCommandText (playerid=0, cmdtext[]=@0x00899168 "/proba") at C:\Reality Roleplay\pawno\include\zcmd.inc:104
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at index 3 past array upper bound 2
[debug] AMX backtrace:
[debug] #0 001d85e4 in public cmd_proba (playerid=0, params[]=@0x00899184 "") at C:\Reality Roleplay\gamemodes\roleplay.pwn:28323
[debug] #1 native CallLocalFunction () [004743b0] from samp-server.exe
[debug] #2 0001e45c in public OnPlayerCommandText (playerid=0, cmdtext[]=@0x00899168 "/proba") at C:\Reality Roleplay\pawno\include\zcmd.inc:104
to reset object is not better "-1" (no exist) ?
Reply
#9

How can I reproduce that bug? I didn't face that error while testing.
Reply
#10

Quote:
Originally Posted by GRiMMREAPER
Посмотреть сообщение
How can I reproduce that bug? I didn't face that error while testing.
Im using crashdetect.dll plugin, with extra information configuration, to do that you have to:

1. go folder pawno
2.create new text document and write -d3
3. save it as pawn.cfg

then start the server and if its bug he will say the line too (only if its -d3)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)