[Ayuda] Como Hacer Esto?...
#1

Buenas a Todos, Kisiera saber como hacer para contar objetos globales creados, osea cree 10 objetos globales y los defini con variables y con su array correspondiente, y con un comando lo voy destroyando.

y lo ke kiero hacer es chekear si hay de 3 objetos para abajo creados si no lo hay retonara un return con un SendClientMessage.

he intentado esto pero no funciona:

pawn Код:
stock contarobjeto()
{
    new count=0;
    for(new x=0; x<10; x++) {
        new Float:pos[3];
                GetDynamicObjectPos(objeto[x], pos[0], pos[1], pos[2]);
        if(objeto[x] >= 0) count++;
        if(count <= 3) return 1;
    }
    return 0;
}

if(contarobjeto()) return SendClientMessage(playerid, -1, " Los Objetos Estan Creados Aun!");
Si me pueden ayudar, selos agradezco .

Desde ya muchas Gracias
Reply
#2

Es posible mediante la funcion IsValidObject

Aca te dejo una funcion generica:
pawn Код:
ContarObjetos(array[], size)
{
    new count;
    for(new i; i<size; i++)
        if(IsValidObject(array[i]))
            count++;
    return count;
}

/*---------Modo de uso (utilizando tu array):---------

ContarObjetos(objeto, 10);

----------------------------------------------------*/
Reply
#3

Quote:
Originally Posted by the_chaoz
Посмотреть сообщение
Es posible mediante la funcion IsValidObject

Aca te dejo una funcion generica:
pawn Код:
ContarObjetos(array[], size)
{
    new count;
    for(new i; i<size; i++)
        if(IsValidObject(array[i]))
            count++;
    return count;
}

/*---------Modo de uso (utilizando tu array):---------

ContarObjetos(objeto, 10);

----------------------------------------------------*/
estaba pensando en IsValidObject pero tenias mis dudas.
ahora ya entendi .

Muchas Gracias .

Saludos.

EDIT:

No me funciono , me tira el mensaje siempre.

pawn Код:
new objeto[10];

objeto[0] = CreateObject(...);
objeto[1] = CreateObject(...);
objeto[2] = CreateObject(...);
objeto[3] = CreateObject(...);
objeto[4] = CreateObject(...);
objeto[5] = CreateObject(...);
objeto[6] = CreateObject(...);
objeto[7] = CreateObject(...);
objeto[8] = CreateObject(...);
objeto[9] = CreateObject(...);

COMMAND:test(playerid, params[])
{
    for(new x=0; x<10; x++) {
        DestroyObject(objeto[x]-5);
    }
    return 1;
}

COMMAND:test2(playerid, params[])
{
    if(!ContarObjetos(objeto, 10)) return SendClientMessage(playerid, -1, " Los Objetos Estan Creados Aun!");
    //funcion
    return 1;
}

stock ContarObjetos(array[], size)
{
    new count;
    for(new i; i<size; i++)
        if(IsValidObject(array[i]))
            count++;
    return count;
}
Reply
#4

Quote:
Originally Posted by bytytus
Посмотреть сообщение
estaba pensando en IsValidObject pero tenias mis dudas.
ahora ya entendi .

Muchas Gracias .

Saludos.

EDIT:

No me funciono , me tira el mensaje siempre.

pawn Код:
new objeto[10];

objeto[0] = CreateObject(...);
objeto[1] = CreateObject(...);
objeto[2] = CreateObject(...);
objeto[3] = CreateObject(...);
objeto[4] = CreateObject(...);
objeto[5] = CreateObject(...);
objeto[6] = CreateObject(...);
objeto[7] = CreateObject(...);
objeto[8] = CreateObject(...);
objeto[9] = CreateObject(...);

COMMAND:test(playerid, params[])
{
    for(new x=0; x<10; x++) {
        DestroyObject(objeto[x]-5);
    }
    return 1;
}

COMMAND:test2(playerid, params[])
{
    if(!ContarObjetos(objeto, 10)) return SendClientMessage(playerid, -1, " Los Objetos Estan Creados Aun!");
    //funcion
    return 1;
}

stock ContarObjetos(array[], size)
{
    new count;
    for(new i; i<size; i++)
        if(IsValidObject(array[i]))
            count++;
    return count;
}
mmm array espara una strin ya que pone array[], cambialo por array solo..

stock ContarObjetos(array, size)
Reply
#5

Quote:
Originally Posted by adri1
Посмотреть сообщение
mmm array espara una strin ya que pone array[], cambialo por array solo..

stock ContarObjetos(array, size)
stock ContarObjetos(array[], size)
{
new count;
for(new i; i<size; i++)
if(IsValidObject(array[i])) //if(IsValidObject(objectid)
count++;
return count;
}

https://sampwiki.blast.hk/wiki/IsValidObject
Reply
#6

No veo el error, pero bueno, te pongo cуmo lo harнa yo, a ver si asн funciona. Veo que tienes ZCMD, o sea que lo utilizarй.

pawn Код:
COMMAND:contarobjetos(playerid, params[])
{
    new objetos,objetosinvalidos,id;
    if(IsAdmin(playerid))
    {
        loop_start:
        if(IsValidObject(id))
        {
            objetos++;
            id++;
            objetosinvalidos = 0;
            goto loop_start;
        }
        else
        {
            if(objetosinvalidos < 500)
            {
                objetosinvalidos++;
                goto loop_start;
            }
            else
            {
                objetosinvalidos = 0;
                new msg[144];
                format(msg,sizeof(msg),"SERVIDOR: Se han contado %i objetos",objetos);
                SendClientMessage(playerid,-1,msg);
                objetos = 0;
                id = 0;
            }
        }
    }
    return 1;
}
Como ves, sуlo tiene una posibilidad de fallar: en caso de que 500 objetos con IDs seguidas hayan sido destruidos, y despuйs haya mбs objetos (estos objetos no serбn aсadidos a la cuenta). Eso no suele pasar en un servidor, o sea que yo creo que es la soluciуn mбs sencilla y casi infalible.

Saludos.
Reply
#7

Quote:
Originally Posted by PHudson
Посмотреть сообщение
No veo el error, pero bueno, te pongo cуmo lo harнa yo, a ver si asн funciona. Veo que tienes ZCMD, o sea que lo utilizarй.

pawn Код:
COMMAND:contarobjetos(playerid, params[])
{
    new objetos,objetosinvalidos,id;
    if(IsAdmin(playerid))
    {
        loop_start:
        if(IsValidObject(id))
        {
            objetos++;
            id++;
            goto loop_start;
        }
        else
        {
            if(objetosinvalidos < 500)
            {
                objetosinvalidos++;
                goto loop_start;
            }
            else
            {
                objetosinvalidos = 0;
                new msg[144];
                format(msg,sizeof(msg),"SERVIDOR: Se han contado %i objetos",objetos);
                SendClientMessage(playerid,-1,msg);
                objetos = 0;
            }
        }
    }
    return 1;
}
Como ves, sуlo tiene una posibilidad de fallar: en caso de que 500 objetos con IDs seguidas hayan sido destruidos, y despuйs haya mбs objetos (estos objetos no serбn aсadidos a la cuenta). Eso no suele pasar en un servidor, o sea que yo creo que es la soluciуn mбs sencilla y casi infalible.

Saludos.
Gracias, intentare con este, .
Reply
#8

La funcion que te di funciona perfectamente, aqui un test realizado antes de colocar el codigo:
pawn Код:
#include <a_samp>

public OnFilterScriptInit()
{
    new objeto[10];
   
    objeto[0] = CreateObject(3082, 3017.6000976563, -206.89999389648, 0, 0, 0, 0);
    objeto[1] = CreateObject(8172, 3202.5, -348.70001220703, 1.2999999523163, 0, 0, 0);
    objeto[2] = CreateObject(8344, 3240.6000976563, -225.30000305176, 3.7999999523163, 0, 0, 270);
    objeto[3] = CreateObject(8172, 3385.6999511719, -201.19999694824, 3.7999999523163, 0, 0, 90);
    objeto[4] = CreateObject(8344, 3511.3999023438, -236.19999694824, 2.9000000953674, 0, 0, 180);
    objeto[5] = CreateObject(8172, 3535.8000488281, -379.60000610352, 2.0999999046326, 0, 0, 0);
    objeto[6] = CreateObject(8343, 3511.6999511719, -507.89999389648, 1.7999999523163, 0, 0, 179.99993896484);
    objeto[7] = CreateObject(8171, 3400.3999023438, -522.79998779297, 1.7999999523163, 0, 0, 86);
//  objeto[8] = CreateObject(8344, 3226.6999511719, -494.20001220703, 1.2999999523163, 0, 0, 0);
    objeto[9] = CreateObject(1655, 3333.5, -532, 2.5999999046326, 0, 0, 87.999938964844);

    printf("Objetos: %i", ContarObjetos(objeto, 10));

    return 1;
}

stock ContarObjetos(array[], size)
{
    new count;
    for(new i; i<size; i++)
        if(IsValidObject(array[i]))
            count++;
    return count;
}
Reply
#9

Quote:
Originally Posted by the_chaoz
Посмотреть сообщение
La funcion que te di funciona perfectamente, aqui un test realizado antes de colocar el codigo:
pawn Код:
#include <a_samp>

public OnFilterScriptInit()
{
    new objeto[10];
   
    objeto[0] = CreateObject(3082, 3017.6000976563, -206.89999389648, 0, 0, 0, 0);
    objeto[1] = CreateObject(8172, 3202.5, -348.70001220703, 1.2999999523163, 0, 0, 0);
    objeto[2] = CreateObject(8344, 3240.6000976563, -225.30000305176, 3.7999999523163, 0, 0, 270);
    objeto[3] = CreateObject(8172, 3385.6999511719, -201.19999694824, 3.7999999523163, 0, 0, 90);
    objeto[4] = CreateObject(8344, 3511.3999023438, -236.19999694824, 2.9000000953674, 0, 0, 180);
    objeto[5] = CreateObject(8172, 3535.8000488281, -379.60000610352, 2.0999999046326, 0, 0, 0);
    objeto[6] = CreateObject(8343, 3511.6999511719, -507.89999389648, 1.7999999523163, 0, 0, 179.99993896484);
    objeto[7] = CreateObject(8171, 3400.3999023438, -522.79998779297, 1.7999999523163, 0, 0, 86);
//  objeto[8] = CreateObject(8344, 3226.6999511719, -494.20001220703, 1.2999999523163, 0, 0, 0);
    objeto[9] = CreateObject(1655, 3333.5, -532, 2.5999999046326, 0, 0, 87.999938964844);

    printf("Objetos: %i", ContarObjetos(objeto, 10));

    return 1;
}

stock ContarObjetos(array[], size)
{
    new count;
    for(new i; i<size; i++)
        if(IsValidObject(array[i]))
            count++;
    return count;
}
si , la funcion anda perfecto, lo acabo de comprobar con un printf y destroyo los objetos y me dice la cantidad correcta ke hay.

entonce el problema esta en el if .

Cuando coloco asi, con el ! retona siempre el return con o sin destroyar los objetos.
if(!ContarObjetos(objeto, 10)) return SendClientMessage(playerid, -1, " Los Objetos Estan Creados Aun!");

y si coloco asi, sin el ! no retona el return y me deja acceder a la funcion
if(ContarObjetos(objeto, 10)) return SendClientMessage(playerid, -1, " Los Objetos Estan Creados Aun!");

:S

EDIT:

le faltaba el ! a IsValidObject

Gracias, Solucionado .
Reply
#10

1є La palabra destroyar no existe, Destroy significa destruir, entonces deberias decir "... cuando destruyo ...".

2є El caracter ! al iniciar la sentencia de un if es lo mismo que comparar contra 0. Ej: "if(!algo)" es igual "if(algo == 0)" por lo cual el error no esta allн, si no en el momento en el que creas los objetos.

Prueba:
pawn Код:
#include <a_samp>

public OnFilterScriptInit()
{
    new objeto[10];
   
    objeto[0] = CreateObject(3082, 3017.6000976563, -206.89999389648, 0, 0, 0, 0);
    objeto[1] = CreateObject(8172, 3202.5, -348.70001220703, 1.2999999523163, 0, 0, 0);
    objeto[2] = CreateObject(8344, 3240.6000976563, -225.30000305176, 3.7999999523163, 0, 0, 270);
    objeto[3] = CreateObject(8172, 3385.6999511719, -201.19999694824, 3.7999999523163, 0, 0, 90);
    objeto[4] = CreateObject(8344, 3511.3999023438, -236.19999694824, 2.9000000953674, 0, 0, 180);
    objeto[5] = CreateObject(8172, 3535.8000488281, -379.60000610352, 2.0999999046326, 0, 0, 0);
    objeto[6] = CreateObject(8343, 3511.6999511719, -507.89999389648, 1.7999999523163, 0, 0, 179.99993896484);
    objeto[7] = CreateObject(8171, 3400.3999023438, -522.79998779297, 1.7999999523163, 0, 0, 86);
//  objeto[8] = CreateObject(8344, 3226.6999511719, -494.20001220703, 1.2999999523163, 0, 0, 0);
    objeto[9] = CreateObject(1655, 3333.5, -532, 2.5999999046326, 0, 0, 87.999938964844);

    printf("Objetos: %i", ContarObjetos(objeto, 10));
   
    for(new i; i<10; i++)
        if(IsValidObject(objeto[i]))
            DestroyObject(objeto[i]);
   
    if(!ContarObjetos(objeto, 10))
        print("No hay objetos");

    return 1;
}

stock ContarObjetos(array[], size)
{
    new count;
    for(new i; i<size; i++)
        if(IsValidObject(array[i]))
            count++;
    return count;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)