dynamic areas issue [solved] -
exclide1 - 29.06.2013
Hello. I've setup a spawn-kill protection, using OnPlayerLeaveDynamicArea(playerid, areaid) function from Incognito's Streamer Plugin. It works, but 1 out of 10 times it happens that it starts the timer, before player actually leaves the area. Here is the code:
pawn Код:
forward OnPlayerLeaveDynamicArea(playerid, areaid);
public OnPlayerLeaveDynamicArea(playerid, areaid)
{
SendClientMessage(playerid, COLOR_RED, "Spawn protection countdown has started. You have 10 seconds.");
spawntimer = SetTimerEx("AntiSpawnkill",10000,0,"i",playerid);
timer1 = true;
DestroyAllDynamicAreas();
return 1;
}
Under OnPlayerSpawn:
pawn Код:
DestroyAllDynamicAreas();
for(new i; i < sizeof(g_CoordSets); i++)
{
CreateDynamicCircle(g_CoordSets[i][xx], g_CoordSets[i][yy], 10, -1, -1, playerid);
}
SetPlayerHealth(playerid, 99999.0);
SendClientMessage(playerid, COLOR_RED, "Spawn protection countdown will start on your movement.");
Any help will be appreciated!
Re: dynamic areas issue -
exclide1 - 29.06.2013
I've set a timer now under OnPlayerSpawn, instead of getting coords instantly:
pawn Код:
DestroyAllDynamicAreas();
areatimer = SetTimerEx("AreaTimer",100,0,"i",playerid);
SetPlayerHealth(playerid, 99999.0);
SendClientMessage(playerid, COLOR_RED, "Spawn protection countdown will start on your movement.");
pawn Код:
forward AreaTimer(playerid);
public AreaTimer(playerid)
{
for(new i; i < sizeof(g_CoordSets); i++)
{
CreateDynamicCircle(g_CoordSets[i][xx], g_CoordSets[i][yy], 10, -1, -1, playerid);
}
return 1;
}
Now it actually works fine always, BUT the first time I connect to the server and spawn. What the hell?
EDIT: I've set the timer to 500 ms and it's ok now. Must be lag-related.
Re: dynamic areas issue -
Pottus - 29.06.2013
This doesn't seem like a good way to do this and is non-logical especially since you have DestroyAllDynamicAreas(); that will mess things up for other players.
The use of timers needs to be avoided as much as possible but used where they are needed.
Here is what I would do....
- Improve how areas are processed
- Create a function to set god mode on a player for x amount of time it will probably be an include since there will be several callbacks hooked
- You should be creating areas after SetPlayerSpawnInfo() function when the next spawn spot is known
Re: dynamic areas issue -
exclide1 - 29.06.2013
Quote:
Originally Posted by [uL]Pottus
This doesn't seem like a good way to do this and is non-logical especially since you have DestroyAllDynamicAreas(); that will mess things up for other players.
|
You're right, damn. I thought for some reason DestroyAllDynamicAreas(); will only destroy them for specified player (lol, it's not specified anywhere). I wish you could give me more tips on how should I do it, as I'm really new to scripting.
Now I'm thinking of setting a timer for checking if !IsPlayerInAnyDynamicArea(playerid); that will then start the countdown timer and kill the DynamicArea checking timer.
Re: dynamic areas issue -
exclide1 - 29.06.2013
TogglePlayerAllDynamicAreas(playerid, 0);
Is using this OK, instead of DestroyAllDynamicAreas();?
Oh, and, I should probably create the areas at OnPlayerConnect, and use the Toggle, right?
Re: dynamic areas issue -
Pottus - 29.06.2013
Try this
https://sampforum.blast.hk/showthread.php?tid=423622
What you want to do is use the same macro reference and call a single macro function.
Basically what that means is you would write the onarea code like this
pawn Код:
ExitArea:SpawnSpot(playerid, areaid, areaindex)
{
SendClientMessage(playerid, "You left your spawn area");
return 1;
}
As long as you specify the playerid for the streamer this will work for you.
You can of course remove the area later when a player disconnects.