Hospital -
BuDweiSeR - 15.12.2017
new bool: sHospital[MAX_PLAYERS][8];
public OnPlayerSpawn(playerid):
Код:
if(sHospital[playerid][0])
{
SetPlayerPos(playerid,-2652.4170,633.1534,14.4531);
sHospital[playerid][0] = 0;
}
else if(sHospital[playerid][1])
{
SetPlayerPos(playerid,-2207.6372,-2285.8066,30.6250);
sHospital[playerid][1] = 0;
}
else if(sHospital[playerid][2])
{
SetPlayerPos(playerid,1173.3130,-1323.3795,15.3935);
sHospital[playerid][2] = 0;
}
else if(sHospital[playerid][3])
{
SetPlayerPos(playerid,2029.2570,-1419.2135,16.9922);
sHospital[playerid][3] = 0;
}
else if(sHospital[playerid][4])
{
SetPlayerPos(playerid,1244.6365,332.0834,19.5547);
sHospital[playerid][4] = 0;
}
else if(sHospital[playerid][5])
{
SetPlayerPos(playerid,-319.9589,1050.6843,20.3403);
sHospital[playerid][5] = 0;
}
else if(sHospital[playerid][6])
{
SetPlayerPos(playerid,607.0730,1819.1471,10.8280);
sHospital[playerid][6] = 0;
}
else if(sHospital[playerid][7])
{
SetPlayerPos(playerid,-1514.7872,2523.3406,55.8154);
sHospital[playerid][7] = 0;
}
public OnPlayerDeath(playerid, killerid, reason)
Код:
272: sHospital[playerid][8] = 1;
Код:
(272) : error 032: array index out of bounds (variable "sHospital")
Nгo sei se estб correto o modo que estou fazendo, Mas o que eu gostaria de fazer й o seguinte : Quando player morrer nascer no hospital mais prуximo, estou fazendo no modo correto? Alguem poderia ajudar?
Re: Hospital -
Cidiei - 15.12.2017
Pelo que vi o indнce 8 de seu vetor nгo existe, pois ele deve ter limitado o vetor para 7 posiзхes e tu esta tentando acessar uma posiзгo nгo existente.
Re: Hospital -
IlanZ - 15.12.2017
http://forum.sa-mp.com/showpost.php?...10&postcount=9
Re: Hospital -
JeffSantos2 - 15.12.2017
Primeiramente a public OnPlayerDeath..
Код:
public OnPlayerDeath(playerid, killerid, reason)
{
GetProxHosp(playerid);
}
Agora a public OnPlayerSpawn
Код:
public OnPlayerSpawn(playerid)
{
if(GetPVarType(playerid, "HospPosA") == PLAYER_VARTYPE_FLOAT)
{
SetPlayerPos(playerid, GetPVarFloat(playerid, "HospPosX"), GetPVarFloat(playerid, "HospPosY"), GetPVarFloat(playerid, "HospPosZ"));
SetPlayerFacingAngle(playerid, GetPVarFloat(playerid, "HospPosA"));
DeletePVar(playerid, "HospPosX");
DeletePVar(playerid, "HospPosY");
DeletePVar(playerid, "HospPosZ"));
DeletePVar(playerid, "HospPosA");
}
}
Criei esse stock caso queira adicionar em mais locais
Код:
stock GetProxHosp(playerid)
{
if(!IsPlayerConnected(playerid)) return 0;
new Float:Hospital[][4] =
{
{-2651.6501, 634.451000, 14.4531, 180.0},
{1173.58420, -1324.5615, 15.1953, 270.0},
{2031.94150, -1404.3578, 17.2614, 165.0},
{1582.56150, 1768.79210, 10.8203, 90.00},
{-318.81500, 1050.88900, 20.3403, 360.0},
{-1514.7959, 2522.85060, 55.8246, 0.000},
{-2200.2214, -2306.5452, 30.6250, 320.0},
{1242.37130, 328.452000, 19.7555, 335.0}
};
new hospitalproximo;
for(new hospid = 0, Float:prevdist, Float:dist; hospid < sizeof(Hospital); hospid++)
{
dist = GetPlayerDistanceToPoint(playerid, Hospital[hospid][0], Hospital[hospid][1], Hospital[hospid][2]);
if(hospid == 0 || dist < prevdist) prevdist = dist, hospitalproximo = hospid;
}
SetPVarFloat(playerid, "HospPosX", Hospital[hospitalproximo][0]);
SetPVarFloat(playerid, "HospPosY", Hospital[hospitalproximo][1]);
SetPVarFloat(playerid, "HospPosZ", Hospital[hospitalproximo][2]);
SetPVarFloat(playerid, "HospPosA", Hospital[hospitalproximo][3]);
return 1;
}
Re: Hospital -
BuDweiSeR - 15.12.2017
Bom, Sou novato na programaзгo, Queria entender o cуdigo acima:
Код:
stock GetProxHosp(playerid)
{
if(!IsPlayerConnected(playerid)) return 0;
new Float:Hospital[][4] =
{
{-2651.6501, 634.451000, 14.4531, 180.0},
{1173.58420, -1324.5615, 15.1953, 270.0},
{2031.94150, -1404.3578, 17.2614, 165.0},
{1582.56150, 1768.79210, 10.8203, 90.00},
{-318.81500, 1050.88900, 20.3403, 360.0},
{-1514.7959, 2522.85060, 55.8246, 0.000},
{-2200.2214, -2306.5452, 30.6250, 320.0},
{1242.37130, 328.452000, 19.7555, 335.0}
};
new hospitalproximo;
for(new hospid = 0, Float:prevdist, Float:dist; hospid < sizeof(Hospital); hospid++)
{
dist = GetPlayerDistanceToPoint(playerid, Hospital[hospid][0], Hospital[hospid][1], Hospital[hospid][2]);
if(hospid == 0 || dist < prevdist) prevdist = dist, hospitalproximo = hospid;
}
SetPVarFloat(playerid, "HospPosX", Hospital[hospitalproximo][0]);
SetPVarFloat(playerid, "HospPosY", Hospital[hospitalproximo][1]);
SetPVarFloat(playerid, "HospPosZ", Hospital[hospitalproximo][2]);
SetPVarFloat(playerid, "HospPosA", Hospital[hospitalproximo][3]);
return 1;
}
Pois quando vou compilar, hospid e Hospital sгo simbolos indefinidos...
Re: Hospital -
Marllun - 15.12.2017
estude
//Quando o player estive uma distancia determinada do local.
https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint
Re: Hospital -
JeffSantos2 - 15.12.2017
Код:
stock GetProxHosp(playerid)
{
if(!IsPlayerConnected(playerid)) return 0; //caso o player nгo esteja conectado, retorna 0
new Float:Hospital[][4] = //variбvel com as coordenadas de todos os hospitais
{
//X, Y, Z, Angulo
{-2651.6501, 634.451000, 14.4531, 180.0},
{1173.58420, -1324.5615, 15.1953, 270.0},
{2031.94150, -1404.3578, 17.2614, 165.0},
{1582.56150, 1768.79210, 10.8203, 90.00},
{-318.81500, 1050.88900, 20.3403, 360.0},
{-1514.7959, 2522.85060, 55.8246, 0.000},
{-2200.2214, -2306.5452, 30.6250, 320.0},
{1242.37130, 328.452000, 19.7555, 335.0}
};
new hospitalproximo; //variбvel que serб o id do hospital mais prуximo
for(new hospid = 0, Float:prevdist, Float:dist; hospid < sizeof(Hospital); hospid++) //loop por todas as coordenadas dos hospitais. hospid = id hosppital, prevdist й a menor distancia, dist й a distancia para o hospital checado
{
dist = GetPlayerDistanceToPoint(playerid, Hospital[hospid][0], Hospital[hospid][1], Hospital[hospid][2]); //faz com que dist receba essa distancia
if(hospid == 0 || dist < prevdist) prevdist = dist, hospitalproximo = hospid; //se for o primeiro hospital ou se a distancia checada for menor que a menor distancia salva, troca
}
//no fim ele salva em PVAR as coordenadas do hospital mais prуximo
SetPVarFloat(playerid, "HospPosX", Hospital[hospitalproximo][0]);
SetPVarFloat(playerid, "HospPosY", Hospital[hospitalproximo][1]);
SetPVarFloat(playerid, "HospPosZ", Hospital[hospitalproximo][2]);
SetPVarFloat(playerid, "HospPosA", Hospital[hospitalproximo][3]);
return 1;
}
Vocк colocou esse stock no final do seu gamemode?
Re: Hospital -
Marllun - 15.12.2017
Aqui funcionou certinho tente.
PHP код:
stock GetProxHosp(playerid)
{
if(!IsPlayerConnected(playerid)) return 0;
new Float:Hospital[][4] =
{
{-2651.6501, 634.451000, 14.4531, 180.0},
{1173.58420, -1324.5615, 15.1953, 270.0},
{2031.94150, -1404.3578, 17.2614, 165.0},
{1582.56150, 1768.79210, 10.8203, 90.00},
{-318.81500, 1050.88900, 20.3403, 360.0},
{-1514.7959, 2522.85060, 55.8246, 0.000},
{-2200.2214, -2306.5452, 30.6250, 320.0},
{1242.37130, 328.452000, 19.7555, 335.0}
};
new hospitalproximo;
for(new hospid = 0, Float:prevdist, Float:dist; hospid < sizeof(Hospital); hospid++)
{
dist = GetPlayerDistanceFromPoint(playerid, Hospital[hospid][0], Hospital[hospid][1], Hospital[hospid][2]);
if(hospid == 0 || dist < prevdist) prevdist = dist, hospitalproximo = hospid;
}
SetPVarFloat(playerid, "HospPosX", Hospital[hospitalproximo][0]);
SetPVarFloat(playerid, "HospPosY", Hospital[hospitalproximo][1]);
SetPVarFloat(playerid, "HospPosZ", Hospital[hospitalproximo][2]);
SetPVarFloat(playerid, "HospPosA", Hospital[hospitalproximo][3]);
return 1;
}
Re: Hospital -
BuDweiSeR - 15.12.2017
Muito obrigado а todos...
[RESOLVIDO]
+Reputaзгo