Skip to content

Instantly share code, notes, and snippets.

View DouglasSherk's full-sized avatar

Douglas Sherk DouglasSherk

View GitHub Profile
@DouglasSherk
DouglasSherk / mac_address_randomize.sh
Last active August 29, 2015 13:56
MAC Address Randomizer
#!/usr/bin/bash
# You might want to note your old MAC address here. Use this to get it:
# ifconfig en0 | grep ether
MAC_ADDRESS=`openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'`
echo "Setting MAC address..."
sudo ifconfig en0 ether $MAC_ADDRESS
ifconfig en0 | grep ether
@DouglasSherk
DouglasSherk / bank_account.sma
Created April 13, 2017 19:58
HWRP - Withdrawing from bank account
new authid[32], query[256]
get_user_authid(id,authid,31)
format( query, 255, "SELECT wallet FROM money WHERE steamid='%s'", authid)
result = dbi_query(dbc,query)
if( dbi_nextrow( result ) > 0 )
{
new buffer[32],wallet
dbi_field(result,1,buffer,31)
dbi_free_result(result)
wallet = str_to_num(buffer)
@DouglasSherk
DouglasSherk / bank_account.sma
Created April 13, 2017 20:04
ARP - Withdrawing from a user's bank account
new amount = str_to_num(request)
new bank = ARP_GetUserBank(id)
if (amount < 1) {
client_print(id, print_chat, "[ARP] Invalid amount; please enter a whole number.")
return PLUGIN_HANDLED
}
if (amount > bank) {
client_print(id, print_chat, "[ARP] You do not have enough money in your bank account.")
@DouglasSherk
DouglasSherk / ARP_Core_NPCs.sma
Created April 16, 2017 18:12
ARP NPCs API simplified.
// ARP_Core.sma
// Handler for NPC registration API call
public _ARP_RegisterNpc(plugin, params) {
new ent = create_entity("info_target")
entity_set_string(ent, EV_SZ_classname, NPC_CLASSNAME) // "arp_npc"
entity_set_string(ent, EV_SZ_model, NPC_MODEL) // "711clerk"
// Store the registering plugin on the NPC so we can notify it of events later
entity_set_int(ent, EV_INT_iuser3, plugin)
@DouglasSherk
DouglasSherk / ARP_Core_NPCs.inc
Created April 16, 2017 18:15
ARP NPCs API simplified, header.
/**
* Registers an NPC or zone. Note that this actually creates
* the NPC for you and sets it up as well.
*
* @param name[] name of the NPC, ex. "Edeka Cashier"
* @param Float:origin[3] where to spawn the NPC
* @param Float:angle which direction it should face (0.0-180.0)
* @param model[] the model the NPC should use (if not a zone)
* @param handler[] function to call when a user presses "e" next to it
* @param property[] the internal name of the property that it belongs to
@DouglasSherk
DouglasSherk / ARP_NPCs.sma
Created April 16, 2017 18:20
ARP NPCs base package plugin.
// A callback called for all ARP plugins when the ARP core is loaded.
public ARP_Init() {
new line[256]
new name[32], Float:origin[3], Float:angle, model[128]
while (read_file(NPCS_FILE, line, 255)) {
parse_line_to_npc(line, name, 32, origin, angle, model, 128)
ARP_RegisterNpc(name, origin, angle, model, "handleNpcUsed")
}
}
@DouglasSherk
DouglasSherk / arrayx_fix.inc
Created April 16, 2017 18:48
Temporary fix for ArrayX `clear()` function
/**
* Use this in place of `array_get_int()` as the former mishandles
* parameters and needs to be wrapped safely.
*/
stock array_get_int_safe(array, index) {
// Insert a dummy canary into the stack.
new dummy[32]
// Call a native (VM function) using the dummy variable to get
// rid of "unused symbol" warnings.
@DouglasSherk
DouglasSherk / arrayx_test.sma
Created April 18, 2017 05:39
A test case for the ArrayX API.
testLotsOfData() {
new array = array_create()
for (int i = 0; i < 1000000; i++) {
array_set_int(array, 0, 1)
/**
* What? This was segfaulting after some large i, usually ~:
* 100000 < i < 500000
*/
array_delete(array, 0)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.