NPC script timers -
Safun - 06.09.2009
Hy everybody!
Thanks for reading my problem and answering it. NPCs are really new for me as maybe lot of us too and i have a question about them. I'm trying to make and NPC who drives around the freeway at LV. It worked. But than i tried to add a timer on its NPC script to detect if a player is close to it and then stop it moving, becaouse i dont want him to crash all the players. Pawno detected only one warning, but when i start the server the samp-npc.exe crashes. What can be the problem? Here is my code:
#include <a_npc>
#define RECORDING1 "tofreeway" //This is the filename of your recording without the extension.
#define RECORDING2 "round1" //This is the filename of your recording without the extension.
#define RECORDING_TYPE 1 //1 for in vehicle and 2 for on foot.
#define DISTANCE_STOP 5
#define TIME_STOPED 12
PointToPointEx(Float

,Float:y,Float:z,Float

x,Fl oat:yy,Float:zz) {
new Float

d = x-xx;
new Float:yd = y-yy;
new Float:zd = z-zz;
new Float:distance = floatsqroot( floatadd( floatadd(floatmul(xd,xd),floatmul(yd,yd)),floatmul (zd,zd)));
return floatround(distance,floatround_floor);
}
new stat = 0;
new stoped = 0;
new globaltimer;
public OnRecordingPlaybackEnd() {
if(stat == 1) {
StartRecordingPlayback(RECORDING_TYPE, RECORDING2);
}
}
public OnNPCEnterVehicle(vehicleid, seatid) {
if(stat == 0) {
StartRecordingPlayback(RECORDING_TYPE, RECORDING1);
stat = 1;
}
}
public OnNPCSpawn() {
globaltimer = SetTimer("enterFrame",100,true);
}
public OnNPCExitVehicle() {
StopRecordingPlayback();
KillTimer(globaltimer);
stat = 0;
}
public enterFrame() {
if(stoped > 0) {
PauseRecordingPlayback();
}
if(stoped == 0) {
ResumeRecordingPlayback();
}
stoped = stoped-1;
new playerid;
for(playerid=0;playerid<MAX_PLAYERS;playerid++) {
new Float

layerx;
new Float

layery;
new Float

layerz;
GetPlayerPos(playerid,playerx,playery,playerz);
new Float

;
new Float:y;
new Float:z;
GetMyPos(x,y,z);
new distance = PointToPointEx(x,y,z,playerx,playery,playerz);
if(distance < DISTANCE_STOP) {
stoped = TIME_STOPED;
}
}
}
Re: NPC script timers -
_Ben_[Fux-c.co.il RP] - 06.09.2009
Quote:
but when i start the server the samp-npc.exe crashes
|
What you do to start the server?
Open samp-server.exe or samp-npc.exe?
Re: NPC script timers -
Safun - 06.09.2009
Man are you joking?

Of course i start the sa:mp server.exe....
Re: NPC script timers -
Safun - 06.09.2009
I tried to remove some parts of the code to get know what is causing the problem. It seems it isnt the timer it seems its the for(). Is it possible that using for() in an npc-bot's script crashes the npc-server.exe??