PDA

View Full Version : How to run EquipPlayerWeapon multiple times, according to a counter's value?


sereky
02-12-2012, 17:54
For example: if the counter's value is 6, run the giveweapon(client, "weapon_..."); command 6 times (in one occasion).

This small source is an example.
#include <sourcemod>
#include <sdktools>

new count[MAXPLAYERS+1];

public Action: ... (an event)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
...
count[client] ++; //add +1 everytime when event hooked
CreateTimer(5.0, give, client);
}

public Action:give(Handle:timer, any:client)
{
giveweapon(client, "weapon_..."); //??? run this multiple times, according to a counter's value
count[client] = 0; //reset the counter
}

giveweapon(client, String:class[40])
{
new ent = CreateEntityByName(class);

if (ent != -1)
{
DispatchSpawn(ent);
EquipPlayerWeapon(client, ent); //or shall I put something here?
}
}

Impact123
02-12-2012, 22:18
Do you mean something like this?

public Action:give(Handle:timer, any:client)
{
// Cache
new count = count[client];

// Runs count-1 times
for(new i; i < count; i++)
{
giveweapon(client, "weapon_..."); //??? run this multiple times, according to a counter's value
}
count[client] = 0; //reset the counter
}


Yours sincerely
Impact

sereky
02-15-2012, 16:51
Do you mean something like this?


Yes, this is what I wanted. Thanks. It works. :)