09.01.2013, 16:41
Buenas, querнa saber como hacer para que un comando solo funcione en un virtual world, por ejemplo en el 0, alguien podrнa ponerme un ejemplo con cualquier comando?

CMD:prueba(playerid, params[])
{
if(GetPlayerVirtualWorld(playerid) == 0)
{
// Codigo a ejecutarse si el usuario esta en el VirtualWorld 0.
}
else SendClientMessage(playerid, -1, "No esta en el VirtualWorld 0.");
return 1;
}
#include <a_samp>
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
if(GetPlayerVirtualWorld(playerid) == TU VIRTUAL WORD)
{
//TU FUNCIONES
//TU FUNCIONES
//TU FUNCIONES
}
else
{
SendClientMessage(playerid, -1, "no estas en el VirtualWorld correspondiente!");
}
return 1;
}
return 0;
}
forward oxigeno(); public oxigeno() { new respirar; new Float:salud__; for(new i=0,j=GetMaxPlayers(); i < j; i++) if(IsPlayerConnected(i) && !IsPlayerNPC(i)) { respirar = GetPlayerAltitude(i); if(respirar > 700) { if(GetPlayerSkin(i) == 277) { SendClientMessage(i, COLOR_GREEN, "Respirando..."); } else { GetPlayerHealth(i,salud__); if(salud__ < 5) { SetPlayerHealth(i,0.00); } else { SetPlayerHealth(i, -5.00); } SendClientMessage(i, COLOR_RED, "Te has ahogado!"); } } } }
forward oxigeno();
public oxigeno()
{
new respirar;
new Float:salud__;
for(new i=0,j=GetMaxPlayers(); i < j; i++) if(IsPlayerConnected(i) && !IsPlayerNPC(i))
{
if(GetPlayerVirtualWorld(playerid) != 0) return 1; //_<---
respirar = GetPlayerAltitude(i);
if(respirar > 700)
{
if(GetPlayerSkin(i) == 277)
{
SendClientMessage(i, COLOR_GREEN, "Respirando...");
}
else
{
GetPlayerHealth(i,salud__);
if(salud__ < 5) {
SetPlayerHealth(i,0.00);
}
else {
SetPlayerHealth(i, -5.00);
}
SendClientMessage(i, COLOR_RED, "Te has ahogado!");
}
}
}
}
forward oxigeno();
public oxigeno()
{
new respirar;
new Float:salud__;
for(new i=0,j=GetMaxPlayers(); i < j; i++) if(IsPlayerConnected(i) && !IsPlayerNPC(i) && GetPlayerVirtualWorld(playerid) == 0) //<-------
{
respirar = GetPlayerAltitude(i);
if(respirar > 700)
{
if(GetPlayerSkin(i) == 277)
{
SendClientMessage(i, COLOR_GREEN, "Respirando...");
}
else
{
GetPlayerHealth(i,salud__);
if(salud__ < 5) {
SetPlayerHealth(i,0.00);
}
else {
SetPlayerHealth(i, -5.00);
}
SendClientMessage(i, COLOR_RED, "Te has ahogado!");
}
}
}
}
forward oxigeno();
public oxigeno()
{
new respirar;
new Float:salud__;
for(new i=0,j=GetMaxPlayers(); i < j; i++) if(IsPlayerConnected(i) && !IsPlayerNPC(i)) {
respirar = GetPlayerAltitude(i);
if(GetPlayerVirtualWorld(i) == 0)
{
if(respirar > 700)
{
if(GetPlayerSkin(i) == 277)
{
SendClientMessage(i, COLOR_GREEN, "Respirando...");
}
else
{
GetPlayerHealth(i,salud__);
if(salud__ < 5) {
SetPlayerHealth(i,0.00);
}
else {
SetPlayerHealth(i, -5.00);
}
SendClientMessage(i, COLOR_RED, "Te has ahogado!");
}
}
}
}
}
error 017: undefined symbol "playerid" function "oxigeno" should return a value |
Disculpa no me di cuenta a tiempo de que no tenias definido playerid en el Callback, el codigo ya esta arreglado.
Un saludo. EDIT: Recomiendo que uses MAX_PLAYERS en vez de GetMaxPlayers, ya que MAX_PLAYERS ejecuta mucho mas rбpido que GetMaxPlayers. |
new total = GetMaxPlayers(); //Es cierto que ocupa memoria la variable, y llamo GetMaxPlayers fuera, si lo pusiera en el bucle serнa llamado tantas veces como el valor que devuelve.
for (new x; x < total; x++) //Ya que aquн tenemos un valor fijo (total) ya no se llama la funciуn tantas veces, y es exacto el nъmero de slots, no serнa 500.
#include <a_samp>
//---
#undef MAX_PLAYERS
#define MAX_PLAYERS (50) //Nъmero de slots que usas.
//---
//Los otros includes.
//---Bucle for.
for (new x; x < MAX_PLAYERS; x++)
//Tenemos el valor exacto en MAX_PLAYERS, no se llama GetMaxPlayers, y no usamos variable.
No sй si esta resuelto el tema, pero comento especialmente por este comentario que hiciste.
Y estбs equivocado, es un tema que lo he consultado hasta con ******, y la MEJOR forma de hacer un bucle for es usando GetMaxPlayers, a no ser que se use el undef y vuelvas a definir MAX_PLAYERS. Si no se usa el undef la mejor forma serнa esta: pawn Код:
pawn Код:
Quiero decir que si usбramos 500 slots se puede dejar tal como estб por defecto. OFF: Mi perro es guay, el tuyo es un lobo loco. ![]() |