Last active
April 28, 2019 10:26
-
-
Save CaptainPRICE/0f0d445e437c1499f6a2ae2c8e95c1dd to your computer and use it in GitHub Desktop.
A full E2, used as an example usecase for https://github.com/wiremod/wire/issues/1900
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inputs User:entity | |
@outputs Kick | |
@persist Keyboard:entity Seat:entity | |
if (first()) { | |
Keyboard = entity():isWeldedTo() | |
if (Keyboard:type() != "gmod_wire_keyboard") { error("Not spawned on Wire Keyboard") } | |
propSpawnEffect(1) | |
propSpawnUndo(0) | |
Seat = seatSpawn("models/nova/airboat_seat.mdl", 1) | |
if (!Seat) { error("Failed to spawn Seat entity") } | |
#ifdef entity:linkComponent(entity) | |
# Link Keyboard to the Seat. | |
print((Keyboard:linkComponent(Seat) ? "Successful" : "Failed to") + " link.") | |
#else | |
print("Please link Keyboard to the spawned Seat manually.") | |
#endif | |
#ifdef entity:createWire(entity, string, string) | |
# Wire E2's (in) User to Keyboard's (out) User. | |
entity():createWire(Keyboard, "User", "User") | |
# Wire Keyboard's (in) Kick to E2's (out) Kick. | |
Keyboard:createWire(entity(), "Kick", "Kick") | |
#else | |
print("Please wire E2 and Keyboard entities manually.") | |
#endif | |
function number entity:isAllowed() { | |
# Change this function to fit your needs, return 1 if This player should be allowed to enter the Seat. | |
# Allow owner only. | |
return This == owner() | |
} | |
} | |
if (!(Keyboard & Seat)) { | |
print("Wait what? The Keyboard or Seat is not present any more! Shutting down...") | |
selfDestruct() | |
exit() | |
} | |
if (->User & ~User) { | |
if (User) { | |
if (User:isAllowed()) { | |
Kick = 0 | |
print("A user entered the keyboard: " + User:name()) | |
} else { | |
Kick = 1 | |
print("Denied user " + User:name() + " from entering the keyboard.") | |
} | |
} else { | |
Kick = 0 | |
print("A user left the keyboard.") | |
} | |
} else { | |
Kick = 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment