How to CreateDynamicObject on player death?
#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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)