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


Messages In This Thread
NPC script timers - by Safun - 06.09.2009, 16:01
Re: NPC script timers - by _Ben_[Fux-c.co.il RP] - 06.09.2009, 16:08
Re: NPC script timers - by Safun - 06.09.2009, 16:10
Re: NPC script timers - by Safun - 06.09.2009, 16:45

Forum Jump:


Users browsing this thread: 1 Guest(s)