PDA

View Full Version : Question with entrances


Burning
09/08/2014, 12:28 PM
Hi im creating entrances system and I would like to ask you how should I do that if there's a player in entrance enter or exit that he could enter/exit with [ENTER] key..That's my code:
forward Tunelis(tekstas[],Float:IejimasX,Float:IejimasY,Float:IejimasZ,Floa t:IsejimasX,Float:IsejimasY,Float:IsejimasZ,interj eras);
public Tunelis(tekstas[],Float:IejimasX,Float:IejimasY,Float:IejimasZ,Floa t:IsejimasX,Float:IsejimasY,Float:IsejimasZ,interj eras)
{
new msg[256];
format(msg,sizeof(msg),"[%s]\n[ENTER]",tekstas);
Create3DTextLabel(msg,0x008080FF,IejimasX,IejimasY ,IejimasZ,10.0, 0, 0);
new msg1[256];
format(msg1,sizeof(msg1),"[%s IŠĖJIMAS]\n[ENTER]",tekstas);
Create3DTextLabel(msg1,0x008080FF,IsejimasX,Isejim asY,IsejimasZ,10.0, 0, 0);
print("[TUNELIAI] Užkrauti");
return 1;
}
I know that I have to do something in OnPlayerKeyStateChange but I cant manage to work it out by myself

kamiliuxliuxliux
09/08/2014, 12:39 PM
public OnPlayerKeyStateChange(playerid, newkays, oldkeys)
{
if(newkeys & KEY_SECONDARY_ATTACK) // if pressed ENTER
{
if(IsPlayerInRangeOfPoint(....)) // is player in range of IejimasX IejimasY IejimasZ....
{
SetPlayerPos(playerid, IsejimasX,IsejimasY,IsejimasZ);
}
else if(IsPlayerInRangeOfPoint(.....)) // is player in range of IsejimasXYZ
{
SetPlayerPos(playerid, IejimasX,IejimasY,IejimasZ);
}
}
return 1;
}

Burning
09/08/2014, 12:41 PM
error 017: undefined symbol "IejimasX"

kamiliuxliuxliux
09/08/2014, 12:43 PM
Because those parameters (IejimasXYZ, IsejimasXYZ) aren't global. They're only in Tunelis callback.

Burning
09/08/2014, 12:44 PM
So how should I do with current parameters or I have to create global parametres somehow?

kamiliuxliuxliux
09/08/2014, 12:52 PM
new Float:IsejimasX = your_coords;
new Float:IsejimasY = your_coords;
new Float:IsejimasZ = your_coords;
new Float:IejimasX = your_coords;
new Float:IejimasY = your_coords;
new Float:IejimasZ = your_coords;

Burning
09/08/2014, 02:55 PM
if I will do like u recommended I will have to create so many variables with static coordinates, I need to fetch coordinates from Tunelis

SKAzini
09/08/2014, 03:44 PM
Here you go mate:


new Entrances[MAX_ENTRANCES][entranceEnum], Entrances_Current=-1;

forward Tunelis(tekstas[],Float:IejimasX,Float:IejimasY,Float:IejimasZ,Floa t:IsejimasX,Float:IsejimasY,Float:IsejimasZ,interj eras);
public Tunelis(tekstas[],Float:IejimasX,Float:IejimasY,Float:IejimasZ,Floa t:IsejimasX,Float:IsejimasY,Float:IsejimasZ,interj eras)
{
new msg[256];
format(msg,sizeof(msg),"[%s]\n[ENTER]",tekstas);
Create3DTextLabel(msg,0x008080FF,IejimasX,IejimasY ,IejimasZ,10.0, 0, 0);
new msg1[256];
format(msg1,sizeof(msg1),"[%s IŠĖJIMAS]\n[ENTER]",tekstas);
Create3DTextLabel(msg1,0x008080FF,IsejimasX,Isejim asY,IsejimasZ,10.0, 0, 0);
Entrances[Entrances_Current+1][Iejimas][0] = IejimasX;
Entrances[Entrances_Current+1][Iejimas][1] = IejimasY;
Entrances[Entrances_Current+1][Iejimas][2] = IejimasZ;
Entrances[Entrances_Current+1][Iejimas][0] = IsejimasX;
Entrances[Entrances_Current+1][Iejimas][1] = IsejimasY;
Entrances[Entrances_Current+1][Iejimas][2] = IsejimasZ;
Entrances[Entrances_Current+1][interjeras] = interjeras;
print("[TUNELIAI] Užkrauti");
return 1;
}

public OnPlayerKeyStateChange(playerid, newkays, oldkeys)
{
if(newkeys & KEY_SECONDARY_ATTACK)
{
for(new i; i < MAX_ENTRANCES; i++) //or for(new i; i < Entrances_Current+1; i++)
{
if(IsPlayerInRangeOfPoint(Entrances[i][Iejimas][0], Entrances[i][Iejimas][1], Entrances[i][Iejimas][2])
{
SetPlayerPos(playerid, Entrances[i][Isejimas][0], Entrances[i][Isejimas][1], Entrances[i][Isejimas][2]);
SetPlayerInterior(playerid, interjeras);
break;
}
else if(IsPlayerInRangeOfPoint(Entrances[i][Isejimas][0], Entrances[i][Isejimas][1], Entrances[i][Isejimas][2])
{
SetPlayerPos(playerid, Entrances[i][Iejimas][0], Entrances[i][Iejimas][1], Entrances[i][Iejimas][2]);
SetPlayerInterior(playerid, 0);
break;
}
}
}
return 1;
}