AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Limit uses (https://forums.alliedmods.net/showthread.php?t=11186)

v3x 03-11-2005 20:03

Limit uses
 
Alright, I know this is simple but I'm not sure how to do it. Say I'd want to limit the use of a certain command to 3 times per round, how would I do this?

TotalNoobScripter 03-11-2005 20:22

its quite simple actually.
1. Hook the command to a function
2. Make an array that will hold everyones 'command status' like new timesused[32]
3. When the command is ran, use an if statement to see if timesused[id] >= 3. Then return PLUGIN_HANDLED. (optional: write a client_print or do somethign more advanced)
4. then do an else statement
5. timesused[id]++
6. Do what ever the command ussually does; or return PLUGIN_CONTINUE if its a command that is built into HL.
7. You can either use logevent or just event to hook a new round or ResetHud, which will then run a function that does
Code:

for (new i = 0; i<sizeof(timesused);i++){
timesused[i] = 0
}


v3x 03-11-2005 20:32

So.. somethin like this..
Code:
public myFunction(id) {     new timesUsed[32]     if(timesUsed == 3) {     return PLUGIN_HANDLED     }     else {     // do something..     timesUsed[id]++     } }

TotalNoobScripter 03-11-2005 20:38

Code:
new timesUsed[32] //Forgot to mention this was a global varible. public myFunction(id) {         if(timesUsed[id] == 3) {     return PLUGIN_HANDLED     }     else {     // do something..     timesUsed[id]++     } }

also to reset the commadn count every round
Code:
register_event("ResetHUD","event_resethud","b"); // in plugin_init public event_resethud(){ for(new i=0;i<sizeof(timesUsed);i++) { timesUsed[i] = 0 } return PLUGIN_CONTINUE }

however, someoen can reset their command usage by typing fullupdate in console. you might want to block that.

v3x 03-11-2005 20:48

Alright, thanks..

Yea, I'll block that.. =]

XxAvalanchexX 03-11-2005 21:04

Player indexes are from 1 - 32.

An array with a size of 32 has indexes from 0 - 31.

You could possibly get an out-of-bounds error.

Declare your array with a size of 33.

v3x 03-11-2005 21:05

Will do.

TotalNoobScripter 03-11-2005 21:05

well typo, besides i never play with a max 32 server anyway.

XxAvalanchexX 03-11-2005 21:07

But that doesn't mean the people running your plugins don't. :-P

TotalNoobScripter 03-11-2005 21:08

there is a rare amount of servers (well comparted to the total of all servers) that run max 32, and if someone did, whats the chance of them choosing one of my plugins? :D

even though i know i should use [33]..


All times are GMT -4. The time now is 14:06.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.