14.10.2016, 21:58
(
Последний раз редактировалось CXdur; 14.10.2016 в 22:36.
)
Hey,
I recently thought about reducing the amount of if statement checks per command. I am working on a gamemode with a lot of commands, some of these for different teams and such. As you can imagine there is a lot of different if statements in the different commands, a lot of these are repeated per command. Checking if the player is on foot, in a vehicle, has different pvars etc.
I was thinking of different ways to do it but I don't feel like I've come up with any good ideas yet. I was thinking of making functions to shorten the code, for example creating a function named IsPlayerOnFootAndCanInteract(playerid) which would check if on foot, different pvars for frozen, cuffed, stunned etc. These are just examples.
This doesn't seem like a good approach to me. I also thought about creating a function where I could input various checks in a string and it would run if checks for specified ones, but this would also seem kind of messy to me and probably inefficient. For instance: SetCommandRule(playerid, "allowvehicle=yes&requirespawn=no");. I didn't see this as a good approach to it, just thought I'd put it here so you guys can see my current ideas.
Thanks!
EDIT:
Wanted to add that I am using ZCMD, I have considered switching to YCMD, but would this help for this in any way and how? If so, do you mind providing any sample code as I have just recently looked into it and the functions seem pretty useful. I see that I can enable / disable commands for specific players, but I'm not sure whether or not there's anything in y_commands that will help me reduce the amount of if checks. There's about 500 commands so I think it would take a bit of effort as well, would like to know whether it's worth it or not.
I recently thought about reducing the amount of if statement checks per command. I am working on a gamemode with a lot of commands, some of these for different teams and such. As you can imagine there is a lot of different if statements in the different commands, a lot of these are repeated per command. Checking if the player is on foot, in a vehicle, has different pvars etc.
I was thinking of different ways to do it but I don't feel like I've come up with any good ideas yet. I was thinking of making functions to shorten the code, for example creating a function named IsPlayerOnFootAndCanInteract(playerid) which would check if on foot, different pvars for frozen, cuffed, stunned etc. These are just examples.
This doesn't seem like a good approach to me. I also thought about creating a function where I could input various checks in a string and it would run if checks for specified ones, but this would also seem kind of messy to me and probably inefficient. For instance: SetCommandRule(playerid, "allowvehicle=yes&requirespawn=no");. I didn't see this as a good approach to it, just thought I'd put it here so you guys can see my current ideas.
Thanks!
EDIT:
Wanted to add that I am using ZCMD, I have considered switching to YCMD, but would this help for this in any way and how? If so, do you mind providing any sample code as I have just recently looked into it and the functions seem pretty useful. I see that I can enable / disable commands for specific players, but I'm not sure whether or not there's anything in y_commands that will help me reduce the amount of if checks. There's about 500 commands so I think it would take a bit of effort as well, would like to know whether it's worth it or not.