NPC script timers
#1

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,Floatx,Fl oat:yy,Float:zz) {

new Floatd = 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 Floatlayerx;
new Floatlayery;
new Floatlayerz;

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;
}

}

}
Reply
#2

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?
Reply
#3

Man are you joking? Of course i start the sa:mp server.exe....
Reply
#4

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??
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)