SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 23/04/2016, 07:22 AM   #1001
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,667
Reputation: 1210
Default Re: Respuesta: RNPC - Recordfree NPCs | Control NPCs without recording | DEV

Quote:
Originally Posted by EnzoMetlc View Post
#1000! (this is a dream come true...)


I'm having problems with build mode. Look this:

Code:
public FollowMe()
{
	new Float:NPC[3];
	for(new i = 0; i < 20; i++)
	{
	    GetPlayerPos(i, NPC[0], NPC[1], NPC[2]);
	    
		slot = RNPC_CreateBuild_s(i, PLAYER_RECORDING_TYPE_ONFOOT, 95);
		RNPC_AddMovement(NPC[0], NPC[1], NPC[2] + 0.9, 0.0, 0.0, 0.0, RNPC_SPEED_SPRINT);
		RNPC_FinishBuild();
		RNPC_StartBuildPlayback(i, slot);
	}
	return 1;
}


That's just an example. That code take between 150-300 mms to be processed, some way to fix that?
Thanks.
It's probably best to "thread" this with timers. Instead of doing all the work in the loop, set a timer to call a function with the parameters you want where each timer is offset by 100ms (i * 100) then the server can still do stuff in between the timers firing and you won't get a huge 300ms block, you'll get 20 very short blocks instead.
__________________
PSA: I changed my username everywhere to "Southclaws" (including GitHub!)

Contact me on either:
My new favourite social media site: https://mastodon.club/@Southclaws
My discord: dc.southcla.ws

Scavenge and Survive 2017 is coming soon god dammit!
[HLF]Southclaw is offline   Reply With Quote
Old 25/04/2016, 03:06 AM   #1002
Swedky
Banned
 
Join Date: Jun 2013
Location: Argentina.
Posts: 2,110
Reputation: 827
Default Respuesta: RNPC - Recordfree NPCs | Control NPCs without recording | DEV

Ye, I call that function every 500mms, but still is a problem. It eat many process time, so my server becomes slow.
Swedky is offline   Reply With Quote
Old 25/04/2016, 11:43 AM   #1003
Mauzen
Godfather
 
Mauzen's Avatar
 
Join Date: Jun 2007
Location: Western Germany
Posts: 5,066
Reputation: 1501
Default Re: RNPC - Recordfree NPCs | Control NPCs without recording | DEV

A slow or stressed HDD maybe, usually creating 20 short movements shouldnt be that slow.
(Edit 2: just noticed you move the NPCs to 0.0 0.0 0.0 from their current position. This can be a long distance, resulting in a really big recording file, thus explaining why its that slow. Is this really what you want to do? The function name suggests something else.)

Are you running the server on linux, and do you have root ssh access to it? Im experimenting with a way to greatly speed it up for people who have that, you could try it then if you like (its just a series of a few bash commands) The same principle also works on Windows, but its much more complicated there.

Edit: Finally I did some testing (first time I launched a samp server for almost a year, according to logfiles), it all works as expected (except for the need for sudo, I didnt think of that before. So only root users can use this improvement yet. Thats bad, but no catastrophe, maybe there are ways around this that I didnt think of yet)

On my server build-generation worked about 20 times(!) faster, theres even room for more on other servers, as my server's hdd is quite fast.
(Measured the time for creating 500 medium-sized recordings: 1100ms on normal HDD, 55ms with the new method)

For those who didnt get what Im talking about yet: its a short bash script for mounting a ramdisk in place of the recordings folder, so rec files are handled in RAM instead of taking the physical detour. Its a logical step to do that, as the HDD access is by far the slowest part of RNPC.
If someone wants to try it, send me a PM.

Last edited by Mauzen; 25/04/2016 at 10:37 PM.
Mauzen is offline   Reply With Quote
Old 02/05/2016, 02:46 AM   #1004
Swedky
Banned
 
Join Date: Jun 2013
Location: Argentina.
Posts: 2,110
Reputation: 827
Default Respuesta: RNPC - Recordfree NPCs | Control NPCs without recording | DEV

I don't know why, but still I'm having same problem (maybe is my computer?). So I have to move the NPC to a short distance?

Speed test:
Code:
[23:44:24] 390
[23:44:25] 696
[23:44:25] 280
[23:44:26] 402
[23:44:26] 340
[23:44:27] 751
[23:44:28] 249
[23:44:28] 403
[23:44:29] 405
[23:44:29] 324
[23:44:30] 590
[23:44:32] 1450
[23:44:32] 247
[23:44:32] 287
[23:44:33] 286
[23:44:34] 302

EDIT: Yes, moving the NPCs at a distance of 2.0mtrs was the way (now I'm a little happy):
Code:
[23:48:32] 60
[23:48:32] 96
[23:48:33] 60
[23:48:33] 91
[23:48:34] 60
[23:48:34] 59
[23:48:35] 104
[23:48:35] 90
[23:48:36] 77
[23:48:36] 57
[23:48:37] 88
[23:48:38] 58
[23:48:38] 58
[23:48:39] 60
[23:48:39] 66
[23:48:40] 58
[23:48:40] 104
[23:48:41] 59
[23:48:41] 59
[23:48:42] 59
Swedky is offline   Reply With Quote
Old 07/05/2016, 04:07 PM   #1005
Xolokos
Little Clucker
 
Xolokos's Avatar
 
Join Date: Dec 2010
Posts: 23
Reputation: 0
Default Re: RNPC - Recordfree NPCs | Control NPCs without recording | DEV

The plugin works for the 0.3.7 R2 ? Or only for the 0.3.7 ?
Moreover if it's not that my server crash when I use RNPC functions : the bot connect perfectly but when I'm in its range he should follow me but instead the server crash.

HTML Code:
forward RFollowPlayer(npcid);
public RFollowPlayer(npcid)
{
	new Float:zx, Float:zy, Float:zz,Float:x, Float:y, Float:z;
	for(new i = 0 ;i<MAX_PLAYERS;i++)
	{
	    if(!IsPlayerNPC(i))
	    {
			if (IsPlayerConnected(i))
			{
				GetPlayerPos(npcid, zx, zy, zz);
				if(IsPlayerInRangeOfPoint(i,RangeZ[i],zx,zy,zz))
				{
					GetPlayerPos(i,x,y,z);
					RNPC_SetUDKeys(KEY_UP);
					MoveRNPC(npcid,x,y,z,RNPC_SPEED_RUN,1);
				}
				else
				{
				    Range[i] = 20;
				}
			}
		}
	}
	return 1;
}
Xolokos is offline   Reply With Quote
Old 28/10/2016, 12:29 AM   #1006
NealPeteros
Huge Clucker
 
NealPeteros's Avatar
 
Join Date: Dec 2015
Location: GetPlayerCountry(playerid);
Posts: 468
Reputation: 32
Default Re: RNPC - Recordfree NPCs | Control NPCs without recording | DEV

Is there any function or callback that removes all the NPCs upon unloading a filterscript or a gamemode?
__________________
Quote:
IRL Description:
  • Neal Andrew Peteros
  • 13 years old
  • Philippines
  • C, C++, Java, Javascript, PAWN, Python Programmer
Currently Working On:

World Wide Web System [PAUSED]

Features
  • Different types of laptop containing different usage
  • World Wide Web added with dozens of websites
Progress: 0/100%

Special thanks to Slavica for the idea
NealPeteros is offline   Reply With Quote
Old 29/10/2016, 01:00 PM   #1007
Mauzen
Godfather
 
Mauzen's Avatar
 
Join Date: Jun 2007
Location: Western Germany
Posts: 5,066
Reputation: 1501
Default Re: RNPC - Recordfree NPCs | Control NPCs without recording | DEV

Quote:
Originally Posted by NealPeteros View Post
Is there any function or callback that removes all the NPCs upon unloading a filterscript or a gamemode?
No, but you can easily do that:
Code:
for (new i = 0; i < MAX_PLAYERS; i++) {
    if (IsPlayerRNPC(i)) Kick(i);
}
Mauzen is offline   Reply With Quote
Old 06/12/2016, 08:46 AM   #1008
PrettyDiamond
Big Clucker
 
PrettyDiamond's Avatar
 
Join Date: Jun 2015
Location: Germany
Posts: 51
Reputation: 0
Question Re: RNPC - Recordfree NPCs | Control NPCs without recording | DEV

I use this script for testing because i want load zombies on my server. I trying a lot of days, but for me nothing works...

Code:
// ------------- NPC zombie test and example script
// RNPC 0.4 (26.6.2014) - Mauzen

// Use ConnectZombieBots(playerid, amount)
// to create <amount> zombie bots that keep following <playerid>
// They wont attack but can be killed for tests and stuff
// Either initialize MapAndreas properly, or go to line 78
// and change the last 1 in MoveRNPC to a 0
#define FILTERSCRIPT

#include <a_samp>
#include <rnpc>//Credits: Mauzen

new rnpcZombie[MAX_PLAYERS];
new rnpcZTimer[MAX_PLAYERS];

stock ConnectZombieBots(playerid, amount)
{
    new name[24];
    new id;
    // spawn the given amount of NPCs
    while(amount-- > 0)
	{
        format(name, 24, "Zombie_%d", 500-amount);
        id = ConnectRNPC(name);
        // Store their target player
        rnpcZombie[id] = playerid;
    }
}

public OnPlayerSpawn(playerid)
{
	if(IsPlayerNPC(playerid))
    {
		if (rnpcZombie[playerid] > 0)
		{
	        // Enable RNPC damage management
	        RNPC_SetShootable(playerid, 1);
	        RNPC_ToggleVehicleCollisionCheck(playerid, 1);

	        // Random skin for datz fun
	        SetPlayerSkin(playerid, random(299));

	        // Change name to avoid name collisions
	        new name[24];
	        format(name, 24, "Zombie_%d", playerid);
	        SetPlayerName(playerid, name);

	        // Spawn zombie somewhere in area around player
	        new Float:x, Float:y, Float:z;
	        GetPlayerPos(rnpcZombie[playerid], x, y, z);
	        x = x - 30.0 + random(60);
	        y = y - 30.0 + random(60);
	        // Set to position on ground
	        MapAndreas_FindZ_For2DCoord(x, y, z);
	        SetPlayerPos(playerid, x, y, z+0.7);

	        // If it was a respawn, kill the old timer
	        if (rnpcZTimer[playerid] > 0) KillTimer(rnpcZTimer[playerid]);
	        // Make him follow the player
	        rnpcZTimer[playerid] = SetTimerEx("RFollowPlayer", 5000, 1, "i", playerid);
	    }
    }
    #if defined RNPC_OnPlayerSpawn
            return RNPC_OnPlayerSpawn(playerid);
    #else
            return 1;
    #endif
}
#if defined _ALS_OnPlayerSpawn
        #undef OnPlayerSpawn
#else
        #define _ALS_OnPlayerSpawn
#endif
#define OnPlayerSpawn RNPCZ_OnPlayerSpawn
forward RNPCZ_OnPlayerSpawn(playerid);

forward RFollowPlayer(npcid);
public RFollowPlayer(npcid)
{
    if (IsPlayerConnected(rnpcZombie[npcid]))
	{
        new Float:x, Float:y, Float:z;
        GetPlayerPos(rnpcZombie[npcid], x, y, z);
        // Move RNPC to random point in area around target player
        MoveRNPC(npcid, x - 3.0 + random(600) / 100.0, y - 3.0 + random(600) / 100.0, z, RNPC_SPEED_RUN, 1);
    }
}
Anyone can help me with this please?

Plugin Loaded:
Quote:
[10:28:40] Loaded.
[10:28:40] Loading plugin: RNPC.so
[10:28:40] RNPC V0.4.1 by Mauzen (03.12.2014)
But then this:

Code:
[10:30:56] [debug] Run time error 3: "Stack/heap collision (insufficient stack size)"
[10:30:56] [debug]  Stack pointer (STK) is 0xB758, heap pointer (HEA) is 0xB71C
[10:30:56] [debug] AMX backtrace:
[10:30:56] [debug] #0 00002ccc in public RNPC_OnPlayerSpawn (0) from zombie.amx
I have 200 NPCs und 300maxplayers in server.cfg

After i searching about:
Code:
Run time error 3: "Stack/heap collision (insufficient stack size)
i remove this from script:

Code:
    #if defined RNPC_OnPlayerSpawn
            return RNPC_OnPlayerSpawn(playerid);
    #else
            return 1;
    #endif
}
#if defined _ALS_OnPlayerSpawn
        #undef OnPlayerSpawn
#else
        #define _ALS_OnPlayerSpawn
#endif

#define OnPlayerSpawn RNPCZ_OnPlayerSpawn
forward RNPCZ_OnPlayerSpawn(playerid);
and put in:
Code:
public OnPlayerSpawn(playerid)
this:

Code:
public OnPlayerSpawn(playerid)
{
	if(IsPlayerNPC(playerid))
    {
but now npcs doesnt join??
__________________

Last edited by PrettyDiamond; 06/12/2016 at 09:17 AM.
PrettyDiamond is offline   Reply With Quote
Old 20/03/2017, 05:56 PM   #1009
WildWave
Big Clucker
 
WildWave's Avatar
 
Join Date: May 2014
Posts: 73
Reputation: 8
Default Re: RNPC - Recordfree NPCs | Control NPCs without recording | DEV

When im trying to upload my zombies to windows sever they connected successfully but when im trying to upload the zombies on linux server, they wont go up.

http://pastebin.com/Zhpgzd4u
__________________
My Scripts : (2)

Basic Admin System
SavedSkin System
WildWave is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Control NPCs using Paths? Programie Scripting Help 2 16/06/2012 02:49 PM
Help with recording two npcs at once marharth Help Archive 3 13/08/2010 03:14 AM
Recording NPCs animation with new version (0.3b) Hernaner28 Help Archive 0 12/08/2010 01:17 AM
No NPCs regdude Server Support 5 08/07/2010 05:54 PM
[HELP] Npcs armyoftwo Help Archive 3 05/12/2009 08:43 AM


All times are GMT. The time now is 10:46 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.