Would this cause lag issues?
#1

Hi there, I'm not sure if this would be an issue for resources, would you be able to assist me with advice?

pawn Код:
if(GetPlayerAmmo(playerid) == 0)
        {
            ProxDetector(30.0, playerid, "* CLINK *", COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
            SendClientMessage(playerid, COLOUR_GREY, "You are out of ammo for this weapon. You need to load more into it, before you can use it again.");
        }
This is under

pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
Many thanks.
Reply
#2

What did you think that will make this lag? Common sense to be honest. My answer is it won't lag at all, unless there's something wrong with one of the function.
Reply
#3

I don't know why that would cause lag, how-ever it may spam messages if they shoot over, and over with no lag. Maybe add something like this?
pawn Код:
new g_ShotMessage[MAX_PLAYERS];

if(GetPlayerAmmo(playerid) == 0 && g_ShotMessage[playerid] == 0)
{
     
            ProxDetector(30.0, playerid, "* CLINK *", COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
            SendClientMessage(playerid, COLOUR_GREY, "You are out of ammo for this weapon. You need to load more into it, before you can use it again.");
             g_ShotMessage[playerid] = 1;
}
else if(GetPlayerAmmo(playerid) != 0 && g_ShotMessage[playerid] == 1)
{
       g_ShotMessage[playerid] = 0;
}
return 1;
Using this, the message is only sent once per ammo outage. Just make sure the variable is also reset on disconnect /connect.
Reply
#4

Quote:
Originally Posted by Abagail
Посмотреть сообщение
I don't know why that would cause lag, how-ever it may spam messages if they shoot over, and over with no lag. Maybe add something like this?
pawn Код:
new g_ShotMessage[MAX_PLAYERS];

if(GetPlayerAmmo(playerid) == 0 && g_ShotMessage[playerid] == 0)
{
     
            ProxDetector(30.0, playerid, "* CLINK *", COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
            SendClientMessage(playerid, COLOUR_GREY, "You are out of ammo for this weapon. You need to load more into it, before you can use it again.");
             g_ShotMessage[playerid] = 1;
}
else if(GetPlayerAmmo(playerid) != 0 && g_ShotMessage[playerid] == 1)
{
       g_ShotMessage[playerid] = 0;
}
return 1;
Hmm? When the gun is out of ammo, the gun is automatically removed so it won't spam any messages.
Reply
#5

Well everytime someone shoots there will be a check to see if they're out of ammo. Would that not cause lag due to it being called so frequently. Someone shooting consistently. Yeah it wouldn't do that because there's no weapon there to actually check.
Reply
#6

I forgot about that, I don't really script a lot related to weapons now-adays. How-ever, - if they are shooting repeatedly especially if lagging, they still might get spammed a bit.
Reply
#7

Quote:
Originally Posted by Dokins
Посмотреть сообщение
Well everytime someone shoots there will be a check to see if they're out of ammo. Would that not cause lag due to it being called so frequently. Someone shooting consistently. Yeah it wouldn't do that because there's no weapon there to actually check.
Nope, I am sure a lot of people uses OnPlayerWeaponShot I haven't heard any issues about the callback causes lag - The callback won't be made if it will cause disadvantage to the server, Imagine servers like DayZ and Roleplay servers these gamemode uses the callback for a lot of reasons for example for Roleplay when a player shoots an m4 or any assault guns they'll create a 3Dlabel, object so far haven't heard any issues, you're safe if I'm correct.
Reply
#8

That's okay. I don't see how they would get spammed, at most it would be 12 times. That's the max amount of weapons that can fire aha and they'd all have to run about. My concern is checking ammo everytime a weapon fires may cause lag?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)